Skip to content

Instantly share code, notes, and snippets.

(Date.parse('2015-10-01').to_date..Date.parse('2015-11-16').to_date).each do |date|
1.upto(24).each do |i|
hour = format("%02d", i)
d = "#{date.to_s(:number)}#{hour}"
result = c.message_history_delete(d)
puts "#{date} #{result}"
end
end
@yangxing-star
yangxing-star / achievement_data.rb
Last active August 29, 2015 14:11
每月绩效
def generate_achievement_records(start_at=1.months.ago.beginning_of_month, end_at=1.months.ago.end_of_month)
CSV.open("#{Rails.root}/#{start_at.to_s}", 'w' ) do |writer|
writer << %w( 姓名 手机 新增 新增有效 维护 维护有效(录入) 维护有效(沟通记录) 录入 企业主 )
User.all.each do |user|
count = AchievementCount.between_date(start_at, end_at).where(user_id: user.id).analysis
chat_count = AchievementRecord.where('created_at >= ? and created_at <= ?', start_at, end_at).where(maintain_type: 1, is_next_login: true, user_id: user.id).count
owner_count = Customer.where('import_at >= ? and import_at <= ?', start_at, end_at).where(user_id: user.id, career: 1).count
import_count = AchievementRecord.where('created_at >= ? and created_at <= ?', start_at, end_at).where(maintain_type: 3, is_next_login: true, user_id: user.id).count
writer << [ user.name, user.mobile, count.try(:newly_count).to_i, count.try(:newly_valid_count).to_i, count.try(:maintain_count).to_i, import_count.to_i, chat_count.to_i, count.try(:info_c
require 'csv'
error = []
CSV.open("#{Padrino.root}/users.csv", 'w' ) do |writer|
writer << %w( ID 昵称 密码 Email 手机 位置(城市) 头像 身份证号 姓名 身份证照片地址 weibo_openid weibo_token weibo_uid tqq2_openid tqq2_token tqq2_uid douban_openid douban_token douban_uid tudou_openid tudou_token tudou_uid 性别 生日 注册时间 注册IP 喜欢的城市 个人描述 积分 学历 职业 语言 会员类别 价格 好友 )
User.all.each do |u|
begin
tqq2_openid = tqq2_token = tqq2_uid = ''
weibo_openid = weibo_token = weibo_uid = ''
tudou_openid = tudou_token = tudou_uid = ''
douban_openid = douban_token = douban_uid = ''
@yangxing-star
yangxing-star / achievement_record.rb
Created November 28, 2014 03:34
修复绩效计算错误
Customer.where('import_at >= "2014-09-01 00:00:00"').each do |c|
ActiveRecord::Base.transaction do
create_date = c.created_at.strftime('%Y-%m-%d')
if (c.created_at..(c.created_at+1.day)).cover?(c.import_at)
AchievementRecord.create( user: c.user,
mobile: c.mobile,
status: c.status,
category: :newly,
created_at: c.import_at,
updated_at: c.import_at )
@yangxing-star
yangxing-star / customer.rb
Created November 18, 2014 03:04
绩效计算
def gene_achievement_records
CSV.generate({col_sep: "\t"}) do |csv|
csv << %w( 姓名 手机 新增 新增有效 维护 维护有效(录入) 维护有效(沟通记录) 录入 企业主 )
User.all.each do |user|
co = AchievementCount.between_date('2014-09-01', '2014-09-30').where(user_id: user.id).analysis
import_count = AchievementRecord.where('created_at >= ? and created_at <= ?', '2014-09-01', '2014-09-30').where(maintain_type: 3, is_next_login: true, user_id: user.id).count
chat_count = AchievementRecord.where('created_at >= ? and created_at <= ?', '2014-09-01', '2014-09-30').where(maintain_type: 1, is_next_login: true, user_id: user.id).count
owner_count = Customer.where('import_at >= ? and import_at <= ?', '2014-09-01', '2014-09-30').where(user_id: user.id, career: '企业主').count
csv << [ user.name, user.mobile, co.try(:newly_count), co.try(:newly_valid_count), co.try(:maintain_count), import_count, chat_count, co.try(:info_count), owner_count ]
end
def total
data = []
a = ["2014-10-17", "2014-10-18", "2014-10-19", "2014-10-20", "2014-10-21", "2014-10-22", "2014-10-23", "2014-10-24", "2014-10-25", "2014-10-26", "2014-10-27", "2014-10-28", "2014-10-29", "2014-10-30", "2014-10-31", "2014-11-01", "2014-11-02", "2014-11-03", "2014-11-04", "2014-11-05", "2014-11-06", "2014-11-07", "2014-11-08", "2014-11-09", "2014-11-10"]
a.each do |d|
date = Date.parse(d)
begin_at = date.beginning_of_day
end_at = date.end_of_day
newly_customers_count = Customer.newly_added(begin_at, end_at).count
newly_merchants_count = Customer.newly_added(begin_at, end_at).where('career = ?', 1).count
require 'csv'
CSV.open('/home/ubuntu/simple_crm/data.csv', 'w' ) do |writer|
Customer.where('import_at > ?', '2014-10-19 00:00:00').each do |c|
writer << [ c.name, c.mobile, c.company, Customer::CAREERS.invert[c.career], c.province.try(:name), c.city.try(:name), c.market_name, c.address, c.scale ]
end
puts '完成'
end
class Logger
private_class_method :new
@@instance = nil
def info(msg)
puts msg
end
def self.instance
@@instance = new unless @@instance
User.all.each do |u|
date = [ '2014-09-01','2014-09-02','2014-09-03','2014-09-04','2014-09-05',
'2014-09-06','2014-09-07','2014-09-08','2014-09-09','2014-09-10',
'2014-09-11','2014-09-12','2014-09-13','2014-09-14','2014-09-15',
'2014-09-16','2014-09-17','2014-09-18','2014-09-19','2014-09-20',
'2014-09-21','2014-09-22','2014-09-23','2014-09-24','2014-09-25',
'2014-09-26','2014-09-27','2014-09-28','2014-09-29','2014-09-30',
'2014-10-01','2014-10-02','2014-10-03','2014-10-04','2014-10-05',
'2014-10-06','2014-10-07','2014-10-08' ]
date.each do |d|
@yangxing-star
yangxing-star / uploader.js
Created August 5, 2014 05:20
图片转成base64
var img = new Image();
img.crossOrigin = "*";
img.src = "http://s3.steedos.com/users/5194c74a8e296a6cfe000019/admin/angel_galaxy-wallpaper-1440x900.jpg";
var canvas = document.createElement("canvas");
canvas.width = img.width;
canvas.height = img.width;
var ctx = canvas.getContext("2d");
ctx.fillRect(50,50,50,50);