MarioWeb/IDManager.py

97 lines
2.6 KiB
Python
Raw Normal View History

2022-11-03 14:07:08 +00:00
import random
import csv
2022-11-24 06:49:02 +00:00
2022-11-03 12:03:04 +00:00
class idManager():
2022-11-03 14:07:08 +00:00
levelNum = 200
2022-11-24 07:44:32 +00:00
timeMin = 1
2022-11-10 13:54:44 +00:00
tutorialMax = 3
2022-11-03 14:07:08 +00:00
ip_dic = {}
2022-11-03 14:52:38 +00:00
ip_recent = {}
2022-11-09 14:09:00 +00:00
ip_control = {}
2022-11-10 12:12:06 +00:00
ip_time = {}
2022-11-10 13:54:44 +00:00
ip_tutorial = {}
2022-11-24 06:49:02 +00:00
2022-11-03 14:07:08 +00:00
def __int__(self):
self.levelNum = 200
2022-11-24 06:49:02 +00:00
def getLevels(self, ip):
2022-11-03 14:07:08 +00:00
if ip not in self.ip_dic.keys():
self.ip_dic[ip] = []
2022-11-24 06:49:02 +00:00
levels = [random.randint(1, self.levelNum), random.randint(1, self.levelNum)]
2022-11-03 14:07:08 +00:00
while levels[0] in self.ip_dic[ip]:
2022-11-24 06:49:02 +00:00
levels[0] = random.randint(1, self.levelNum)
2022-11-03 14:07:08 +00:00
self.ip_dic[ip].append(levels[0])
while levels[1] in self.ip_dic[ip]:
levels[1] = random.randint(1, self.levelNum)
self.ip_dic[ip].append(levels[1])
2022-11-24 06:49:02 +00:00
self.ip_recent[ip] = [levels[0], levels[1]]
return ["lvl" + str(levels[0]), "lvl" + str(levels[1])]
# return ["test1","test2"]
2022-11-03 14:07:08 +00:00
2022-11-24 06:49:02 +00:00
def getRecent(self, ip):
2022-11-03 14:52:38 +00:00
return self.ip_recent[ip]
2022-11-24 06:49:02 +00:00
def getLevel(self, ip):
2022-11-24 07:44:32 +00:00
if ip not in self.ip_dic.keys():
self.ip_dic[ip] = []
2022-11-24 06:49:02 +00:00
level = random.randint(1, self.levelNum)
while level in self.ip_dic[ip]:
level = random.randint(1, self.levelNum)
self.ip_dic[ip].append(level)
self.ip_recent[ip] = level
return "lvl" + str(level)
def setControl(self, ip, content):
2022-11-09 14:09:00 +00:00
if content == "A":
self.ip_control[ip] = 0
else:
self.ip_control[ip] = 1
2022-11-24 06:49:02 +00:00
def setTimes(self, ip):
self.ip_time[ip] = 0
def getTimes(self, ip):
2022-11-10 12:12:06 +00:00
print(self.ip_time[ip])
if ip not in self.ip_time.keys():
return 0
else:
2022-11-24 06:49:02 +00:00
if self.ip_time[ip] >= self.timeMin:
2022-11-10 12:12:06 +00:00
return 1
else:
return 0
2022-11-24 06:49:02 +00:00
def addTimes(self, ip):
2022-11-10 12:12:06 +00:00
if ip not in self.ip_time.keys():
self.ip_time[ip] = 0
2022-11-24 06:49:02 +00:00
self.ip_time[ip] = self.ip_time[ip] + 1
2022-11-10 12:12:06 +00:00
return self.ip_time[ip]
2022-11-09 14:09:00 +00:00
2022-11-24 06:49:02 +00:00
def addTutorial(self, ip):
2022-11-10 13:54:44 +00:00
if ip not in self.ip_tutorial.keys():
self.ip_tutorial[ip] = 1
return 1
else:
2022-11-24 06:49:02 +00:00
if self.ip_tutorial[ip] > self.tutorialMax:
2022-11-10 13:54:44 +00:00
return 1
else:
self.ip_tutorial[ip] = self.ip_tutorial[ip] + 1
return self.ip_tutorial[ip]
2022-11-24 06:49:02 +00:00
def hasNextTutorial(self, ip):
2022-11-10 13:54:44 +00:00
if self.ip_tutorial[ip] == self.tutorialMax:
return 0
else:
return 1
2022-11-24 06:49:02 +00:00
def getControl(self, ip):
2022-11-09 14:09:00 +00:00
return self.ip_control[ip]
2022-11-24 06:49:02 +00:00
def write_csv(self, path, data):
2022-11-15 05:46:21 +00:00
with open(path, 'a+', newline='') as f:
2022-11-03 14:07:08 +00:00
csv_write = csv.writer(f)
2022-11-24 06:49:02 +00:00
csv_write.writerow([*data, ''])