-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgraffiti.py
292 lines (249 loc) · 11.8 KB
/
graffiti.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
from audioop import reverse
from signal import SIG_DFL
from this import d
from xml.etree.ElementTree import tostring
import discord, os
import asyncio
from discord import message
from discord.ext import commands
import random
import json
import operator
import firebase_admin
from firebase_admin import credentials
from firebase_admin import db
game = discord.Game("ICISTS-KAIST")
bot = commands.Bot(command_prefix='!', Status=discord.Status.online, activity=game)
client = discord.Client()
cred = credentials.Certificate('investment-game-e04fb-firebase-adminsdk-q4spd-bcff64ea68.json')
firebase_admin.initialize_app(cred,{
'databaseURL' : 'https://investment-game-e04fb-default-rtdb.asia-southeast1.firebasedatabase.app/'
})
global team_number
global startup_list
startup_list = ['QTC','AET','INB','SHZ','RFY','SWT','NUT','NUV']
team_number = 24
@bot.command(aliases=['hi'])
async def hello(ctx):
await ctx.send('ver 3.0.0')
@bot.command()
async def set_round(ctx, set_round_num):
dir = db.reference('status')
dir.update({'currentRound': int(set_round_num)})
await ctx.send(f'ICISTS 투자게임 - 현재 {set_round_num}라운드로 설정되었습니다.')
@bot.command()
async def function1(ctx , input1, input2):
dir_round_num = db.reference('status/currentRound')
round_num = dir_round_num.get()
total_investment = 0
alpha = float(input1)
beta = float(input2)
await ctx.send(f'function1 작동 시작')
dict_invest = db.reference(f'rounds/{round_num}/investAmount').get()
for startup_name in startup_list:
for team_num in range(1,team_number + 1) :
total_investment += dict_invest[team_num][startup_name]
avg_investment = total_investment / 8
await ctx.send(f'전체 스타트업 평균 투자액 : {avg_investment}')
invest_list = [0] * 8 #각 기업별 총 투자액 리스트
index = 0
for startup_name in startup_list: # 각 기업별 각 팀에게 돌려줄 금액 계산
total_invest_eachCompany = 0
for team_num in range(1, team_number + 1) :
total_invest_eachCompany += dict_invest[team_num][startup_name]
invest_list[index] = total_invest_eachCompany
index += 1
await ctx.send('각 스타트업별 받은 총 투자액 정산이 완료되었습니다.')
total_score = 0
dict_score = db.reference(f'rounds/{round_num}/score').get()
for startup_name in startup_list: # 각 기업별 VC에게 받은 평가
total_score += dict_score[startup_name]
avg_score = total_score / 8
await ctx.send(f'각 스타트업에 대한 VC 평가 완료, 평균 점수 : {avg_score}')
dir_result = db.reference(f'rounds/{round_num}/investResult')
dir_valuation = db.reference(f'rounds/{round_num}/valuation')
dict_result = {}
dict_valuation = {}
if(int(round_num) != 3 ):
for team_num in range(1,team_number+1):
dict_startup = {}
index = 0
for startup_name in startup_list:
score = dict_score[startup_name]
invest = dict_invest[team_num][startup_name]
valuation = int((invest_list[index]/avg_investment)**(alpha) * (score / avg_score)**(beta) * avg_investment)
dict_valuation[startup_name] = valuation
formula = int(((invest_list[index]/avg_investment)**(alpha - 1)) * invest * (score / avg_score)**(beta))
dict_startup[startup_name] = formula
index += 1
dict_result[team_num] = dict_startup
dir_result.update(dict_result)
dir_valuation.update(dict_valuation)
await ctx.send(f'ICISTS 투자게임 - {round_num}라운드 각 팀에게 돌려줄 금액 계산이 완료되었습니다. ')
elif int(round_num) == 3 :
for team_num in range(1,team_number+1):
dict_startup = {}
index = 0
for startup_name in startup_list:
invest = dict_invest[team_num][startup_name]
valuation = int((invest_list[index]/avg_investment)**(alpha) * avg_investment)
dict_valuation[startup_name] = valuation
formula = int(((invest_list[index]/avg_investment)**(alpha - 1)) * invest)
dict_startup[startup_name] = formula
index += 1
dict_result[team_num] = dict_startup
dir_result.update(dict_result)
dir_valuation.update(dict_valuation)
await ctx.send(f'ICISTS 투자게임 - {round_num}라운드 각 팀에게 돌려줄 금액 계산이 완료되었습니다. ')
@bot.command()
async def function2(ctx):
dir_round_num = db.reference('status/currentRound')
round_num = dir_round_num.get()
await ctx.send(f'function2 작동 시작')
dir_invest = db.reference(f'rounds/{round_num}/investAmount')
dict_invest = dir_invest.get()
dir_result = db.reference(f'rounds/{round_num}/investResult')
dict_result = dir_result.get()
dir_account = db.reference(f'rounds/{round_num}/account')
dict_account = dir_account.get()
dict_nextAccount = {}
for team_num in range(1,team_number+1):
for startup_name in startup_list:
dict_account[team_num] -= dict_invest[team_num][startup_name]
dict_account[team_num] += dict_result[team_num][startup_name]
dict_nextAccount[team_num] = dict_account[team_num]
dir_nextAccount = db.reference(f'rounds/{round_num+1}/account')
dir_nextAccount.update(dict_nextAccount)
await ctx.send(f'ICISTS 투자게임 - {round_num}라운드 각 팀의 투자 결과 정산이 완료되었습니다')
@bot.command()
async def base_setting(ctx, round_num):
await ctx.send(f'ICISTS 투자게임 - {round_num} 라운드 기본 설정을 시작합니다.\n')
for startup_name in startup_list:
dir = db.reference(f'rounds/{round_num}/valuation')
dir.update({
f'{startup_name}' : 0
})
for team_num in range(1,team_number+1):
dir = db.reference(f'rounds/{round_num}/investAmount')
dir.update({
f'{team_num}' : 0
})
for team_num in range(1,team_number+1):
dir = db.reference(f'rounds/{round_num}/investResult')
dir.update({
f'{team_num}' : 0
})
await ctx.send(f'ICISTS 투자게임 - {round_num} 라운드 기본 설정을 완료했습니다.\n')
@bot.command()
async def able(ctx):
dir = db.reference('status')
dir.update({
'investable' : True
})
await ctx.send('ICISTS 투자게임 - 현재 투자가 가능하게 되었습니다.')
@bot.command()
async def unable(ctx):
dir = db.reference('status')
dir.update({
'investable' : False
})
await ctx.send('ICISTS 투자게임 - 현재 투자가 불가능하게 되었습니다.')
@bot.command()
async def setting_defaultmoney(ctx, round):
defaultmoney = 0
for team_num in range(1,team_number+1):
dir = db.reference(f'rounds/{round}/account')
dir.update({
f'{team_num}' : defaultmoney
})
await ctx.send('ICISTS 투자게임 - 기본금 지급이 완료되었습니다.')
@bot.command()
async def setting(ctx, round_num):
await ctx.send(f'ICISTS 투자게임 - {round_num} 라운드 Firebase 데이터베이스 설정을 시작합니다.\n')
for team_num in range(1, team_number + 1):
dir_investAmount= db.reference(f'rounds/{round_num}/investAmount/{team_num}/')
dir_investAmount.set({
f'{startup_list[0]}' : 0,
f'{startup_list[1]}' : 0,
f'{startup_list[2]}' : 0,
f'{startup_list[3]}' : 0,
f'{startup_list[4]}' : 0,
f'{startup_list[5]}' : 0,
f'{startup_list[6]}' : 0,
f'{startup_list[7]}' : 0
})
for team_num in range(1, team_number + 1):
dir_investResult= db.reference(f'rounds/{round_num}/investResult/{team_num}')
dir_investResult.set({
f'{startup_list[0]}' : 0,
f'{startup_list[1]}' : 0,
f'{startup_list[2]}' : 0,
f'{startup_list[3]}' : 0,
f'{startup_list[4]}' : 0,
f'{startup_list[5]}' : 0,
f'{startup_list[6]}' : 0,
f'{startup_list[7]}' : 0
})
dir_score = db.reference(f'rounds/{round_num}/score')
dir_score.set({
f'{startup_list[0]}' : 0,
f'{startup_list[1]}' : 0,
f'{startup_list[2]}' : 0,
f'{startup_list[3]}' : 0,
f'{startup_list[4]}' : 0,
f'{startup_list[5]}' : 0,
f'{startup_list[6]}' : 0,
f'{startup_list[7]}' : 0
})
for startup_name in startup_list :
dir_valuation = db.reference(f'rounds/{round_num}/valuation')
dir_valuation.update({
f'{startup_name}' : 0
})
await ctx.send(f'ICISTS 투자게임 - Firebase 데이터 기본 설정이 완료되었습니다.\n')
@bot.command()
async def pitching(ctx, startup_name):
dir = db.reference("status")
if startup_name in startup_list:
dir.update({
'currentPitching' : startup_name
})
else:
dir.update({
'currentPitching' : ''
})
await ctx.send('ICISTS 투자 게임 - 피칭 기업 설정 완료')
@bot.command()
async def ranking_startup(ctx):
dict_rank = {}
for startup_name in startup_list :
dict_rank[startup_name] = 0
for round_num in range(4):
dir = db.reference(f'rounds/{round_num}/valuation')
dict = dir.get()
for startup_name in startup_list:
dict_rank[startup_name] += dict[startup_name]
dict_rank = sorted(dict_rank.items(), key = lambda x : x[1])
await ctx.send(dict_rank)
@bot.command()
async def ranking_team(ctx):
dir = db.reference('rounds/4/account')
dict_account = dir.get()
dict_rank = {}
for team_num in range(1,team_number+1):
dict_rank[team_num] = dict_account[team_num]
dict_rank = sorted(dict_rank.items(), key = lambda x : x[1], reverse= True)
await ctx.send(dict_rank)
list = [ 1, 4, 9 , 16]
for rank in list:
await ctx.send(f'{rank}등 팀 : {dict_rank[rank - 1]}')
@bot.command()
async def setseat(ctx):
dict = {1: {1: None, 2: 'NUV', 3: 'AET', 4: 'INB', 5: 'RFY', 6: None}, 2: {1: 'NUV', 2: 'AET', 3: 'INB', 4: 'RFY', 5: None, 6: None}, 3: {1: 'SHZ', 2: 'QTC', 3: None, 4: None, 5: 'SWT', 6: 'NUT'}, 4: {1: None, 2: None, 3: 'NUV', 4: 'AET', 5: 'INB', 6: 'RFY'}, 5: {1: 'RFY', 2: None, 3: None, 4: 'NUV', 5: 'AET', 6: 'INB'}, 6: {1: 'QTC', 2: None, 3: None, 4: 'SWT', 5: 'NUT', 6: 'SHZ'}, 7: {1: 'NUT', 2: 'SHZ', 3: 'QTC', 4: None, 5: None, 6: 'SWT'}, 8: {1: None, 2: None, 3: 'SWT', 4: 'NUT', 5: 'SHZ', 6: 'QTC'}, 9: {1: 'QTC', 2: None, 3: None, 4: 'SWT', 5: 'NUT', 6: 'SHZ'}, 10: {1: 'SHZ', 2: 'QTC', 3: None, 4: None, 5: 'SWT', 6: 'NUT'}, 11: {1: 'SWT', 2: 'NUT', 3: 'SHZ', 4: 'QTC', 5: None, 6: None}, 12: {1: None, 2: 'SWT', 3: 'NUT', 4: 'SHZ', 5: 'QTC', 6: None}, 13: {1: 'AET', 2: 'INB', 3: 'RFY', 4: None, 5: None, 6: 'NUV'}, 14: {1: 'NUV', 2: 'AET', 3: 'INB', 4: 'RFY', 5: None, 6: None}, 15: {1: None, 2: None, 3: 'SWT', 4: 'NUT', 5: 'SHZ', 6: 'QTC'}, 16: {1: 'RFY', 2: None, 3: None, 4: 'NUV', 5: 'AET', 6: 'INB'}, 17: {1: 'INB', 2: 'RFY', 3: None, 4: None, 5: 'NUV', 6: 'AET'}, 18: {1: 'NUT', 2: 'SHZ', 3: 'QTC', 4: None, 5: None, 6: 'SWT'}, 19: {1: None, 2: None, 3: 'NUV', 4: 'AET', 5: 'INB', 6: 'RFY'}, 20: {1: 'SWT', 2: 'NUT', 3: 'SHZ', 4: 'QTC', 5: None, 6: None}, 21: {1: None, 2: 'SWT', 3: 'NUT', 4: 'SHZ', 5: 'QTC', 6: None}, 22: {1: 'AET', 2: 'INB', 3: 'RFY', 4: None, 5: None, 6: 'NUV'}, 23: {1: 'INB', 2: 'RFY', 3: None, 4: None, 5: 'NUV', 6: 'AET'}, 24: {1: None, 2: 'NUV', 3: 'AET', 4: 'INB', 5: 'RFY', 6: None}}
for team_num in range(1,team_number+1):
dir = db.reference(f'teams/{team_num}')
dir.update({'track' : dict[team_num]})
@bot.command()
async def team_matching(ctx):
await ctx.send('미구현')
bot.run(os.environ['token'])