新增:初始化区块链脚本
This commit is contained in:
parent
4952373655
commit
200b954f41
|
@ -449,13 +449,16 @@ class Project < ApplicationRecord
|
|||
email = itemArray[0]
|
||||
username = itemArray[1]
|
||||
commits = itemArray[2].to_i
|
||||
if username =~ CustomRegexp::LOGIN && email =~ CustomRegexp::EMAIL
|
||||
user = User.find_by(login: username, mail: email)
|
||||
user = User.find_by(login: username, mail: email)
|
||||
user = User.find_by(login: username) if user.nil?
|
||||
user = User.find_by(mail: email) if user.nil?
|
||||
# next if user.nil?
|
||||
search_contributor = contributors.select{|con| con["id"]==user.id}[0]
|
||||
if search_contributor.present?
|
||||
search_contributor["contributions"] += commits
|
||||
else
|
||||
user = User.find_by(mail: email) unless username =~ CustomRegexp::LOGIN
|
||||
user = User.find_by(login: username) unless email =~ CustomRegexp::EMAIL
|
||||
contributors << {contributions: commits, name: username, login: username, email: email, id: user&.id}.stringify_keys
|
||||
end
|
||||
contributors << {contributions: commits, name: username, login: username, email: email, id: user&.id}.stringify_keys
|
||||
end
|
||||
file.close
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# 执行示例 bundle exec rake "sync_mindspore:contributor_to_user"
|
||||
# RAILS_ENV=production bundle exec rake "sync_mindspore:contributor_to_user"
|
||||
desc "mindspore项目贡献者数据"
|
||||
|
||||
# 同步mindspre贡献者数据至用户表
|
||||
|
@ -46,9 +48,32 @@ namespace :sync_mindspore do
|
|||
|
||||
file.close
|
||||
end
|
||||
|
||||
# 执行示例 bundle exec rake "sync_mindspore:init_project_blockchain[1,2]"
|
||||
# RAILS_ENV=production bundle exec rake "sync_mindspore:init_project_blockchain[1,2]"
|
||||
desc "初始化区块链项目"
|
||||
task init_project_blockchain: :environment do
|
||||
task :init_project_blockchain, [:id, :init_id] => :environment do |t, args|
|
||||
puts "=====Init Project Blockchain: #{args.id}====="
|
||||
project = Project.find_by_id(args.id)
|
||||
project.update_column(:use_blockchain, true)
|
||||
|
||||
username = project.user_id.to_s
|
||||
token_name = project.id.to_s
|
||||
total_supply = 10000
|
||||
token_balance = [[init_id.to_s, 100]]
|
||||
|
||||
contributions = Project.mindspore_contributors
|
||||
total_contributions = contributions.sum{|i| i["contributions"]}
|
||||
contributions.each do |con|
|
||||
cont_balance = Float(con["contributions"]*9900/total_contributions).round(0)
|
||||
token_balance << [con["id"], cont_balance] if cont_balance > 0
|
||||
end
|
||||
params = {
|
||||
"request-type": "create repo",
|
||||
"username": username,
|
||||
"token_name": token_name,
|
||||
"total_supply": total_supply,
|
||||
"token_balance": token_balance
|
||||
}.to_json
|
||||
resp_body = Blockchain::InvokeBlockchainApi.call(params)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -66,7 +66,7 @@ liyong126@huawei.com|:|liyong|:|133
|
|||
xiaotianci1@huawei.com|:|Xiao_Tianci|:|129
|
||||
hezhenhao1@huawei.com|:|hezhenhao1|:|128
|
||||
lilinjie11@huawei.com|:|lilinjie|:|127
|
||||
wangnan39@huawei.com|:|wangnan39@huawei.com|:|126
|
||||
wangnan39@huawei.com|:|wangnan39|:|126
|
||||
fanjibin@huawei.com|:|fan-ji-bin|:|124
|
||||
xuhui78@huawei.com|:|looop5|:|122
|
||||
yangzhenzhang@huawei.com|:|yangzhenzhang|:|121
|
||||
|
@ -124,7 +124,7 @@ hanhuifeng1@huawei.com|:|hanhuifeng2020|:|76
|
|||
yanpanhui@huawei.com|:|ms_yan|:|76
|
||||
eric.zhang1@huawei.com|:|eric|:|76
|
||||
liuyongqi5@huawei.com|:|liu-yongqi-63|:|74
|
||||
albert.liyan@huawei.com|:|albert.liyan@huawei.com|:|74
|
||||
albert.liyan@huawei.com|:|albert.liyan|:|74
|
||||
liqiliang1@huawei.com|:|liqiliang|:|74
|
||||
xiongkun5@huawei.com|:|xiongkun|:|73
|
||||
liuluobin@huawei.com|:|liuluobin|:|73
|
||||
|
@ -336,14 +336,14 @@ daisurong@mail.nankai.edu.cn|:|Dai_Surong|:|22
|
|||
zhengbin25@huawei.com|:|zhengbin|:|22
|
||||
harshvardhan.gupta@huawei.com|:|Harshvardhan_Gupta|:|22
|
||||
yue.yu1@huawei.com|:|alex-yuyue|:|22
|
||||
6517937+tronzhang@user.noreply.gitee.com|:|tronzhang|:|22
|
||||
tronzhang@huawei.com|:|tronzhang|:|22
|
||||
pengyanjun1@huawei.com|:|Yanjun_Peng|:|22
|
||||
gukecai@huawei.com|:|gukecai|:|22
|
||||
qianlong3@huawei.com|:|qianlong|:|22
|
||||
meixiaowei1@huawei.com|:|meixiaowei|:|22
|
||||
wenkai8@huawei.com|:|wenkai|:|21
|
||||
harshvardhan.gupta1@huawei.com|:|Harshvardhan_Gupta|:|21
|
||||
zhanghaibo5@huawei.com|:|zhanghaibo5@huawei.com|:|21
|
||||
zhanghaibo5@huawei.com|:|zhanghaibo5|:|21
|
||||
xulei83@huawei.com|:|xulei2020|:|21
|
||||
liuxiao78@huawei.com|:|_liuxiao_|:|21
|
||||
liujunzhu@huawei.com|:|liujunzhu|:|20
|
||||
|
@ -853,7 +853,7 @@ huenrui1@huawei.com|:|huenrui|:|2
|
|||
doyushui@163.com|:|dong-li|:|2
|
||||
yiannis.lamprou@gmail.com|:|Ioannis_Lamprou|:|2
|
||||
thuxuxs@163.com|:|xuxs|:|2
|
||||
5719707+jonyguo@user.noreply.gitee.com|:|guozhijian|:|2
|
||||
guozhijian@huawei.com|:|guozhijian|:|2
|
||||
summyflyer@163.com|:|13465716071|:|2
|
||||
chentanjie@huawei.com|:|Daniel|:|2
|
||||
rmdyh@hotmail.com|:|rmdyh|:|2
|
||||
|
@ -1097,7 +1097,7 @@ chenxinghaothu@gmail.com|:|Xinghao_Chen|:|1
|
|||
fuyu_wang@126.com|:|Fuyu_Wang|:|1
|
||||
zhanghui_china2020@163.com|:|ZhangHui|:|1
|
||||
liyiming1998@qq.com|:|neoming|:|1
|
||||
8315094+panpanrui@user.noreply.gitee.com|:|panpanrui|:|1
|
||||
panpanrui@huawei.com|:|panpanrui|:|1
|
||||
chuckchy0819@126.com|:|chuck|:|1
|
||||
dff@pku.edu.cn|:|dff|:|1
|
||||
chengjunjie@126.com|:|Junjie_Cheng|:|1
|
||||
|
@ -1142,7 +1142,7 @@ xun.xue@huawei.com|:|xunxue|:|1
|
|||
yangjie1305@163.com|:|yangjie|:|1
|
||||
lilei123@huawei.com|:|lilei|:|1
|
||||
lihongkang1@huawei.com|:|lihongkang|:|1
|
||||
6517995+hanyuanai@user.noreply.gitee.com|:|hanyuanai|:|1
|
||||
hanyuanai@huawei.com|:|hanyuanai|:|1
|
||||
linyifan@huawei.com|:|lyfne|:|1
|
||||
lupengcheng4@huawei.com|:|lupengcheng|:|1
|
||||
jzw@desktop-2orpq19.localdomain|:|jzw|:|1
|
||||
|
|
Loading…
Reference in New Issue