MarioWeb/IDManager.py

76 lines
2.2 KiB
Python
Raw Normal View History

2022-11-03 14:07:08 +00:00
import random
import csv
2022-11-03 12:03:04 +00:00
class idManager():
2022-11-03 14:07:08 +00:00
levelNum = 200
2022-11-10 14:13:32 +00:00
timeMin = 2
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-03 14:07:08 +00:00
def __int__(self):
self.levelNum = 200
2022-11-03 12:03:04 +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] = []
levels = [random.randint(1,self.levelNum), random.randint(1,self.levelNum)]
while levels[0] in self.ip_dic[ip]:
levels[0] = random.randint(1,self.levelNum)
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-03 14:52:38 +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-03 14:52:38 +00:00
def getRecent(self,ip):
return self.ip_recent[ip]
2022-11-09 14:09:00 +00:00
def setControl(self,ip,content):
if content == "A":
self.ip_control[ip] = 0
else:
self.ip_control[ip] = 1
2022-11-10 12:12:06 +00:00
def getTimes(self,ip):
print(self.ip_time[ip])
if ip not in self.ip_time.keys():
return 0
else:
if self.ip_time[ip]>=self.timeMin:
return 1
else:
return 0
def addTimes(self,ip):
if ip not in self.ip_time.keys():
self.ip_time[ip] = 0
self.ip_time[ip] = self.ip_time[ip]+1
return self.ip_time[ip]
2022-11-09 14:09:00 +00:00
2022-11-10 13:54:44 +00:00
def addTutorial(self,ip):
if ip not in self.ip_tutorial.keys():
self.ip_tutorial[ip] = 1
return 1
else:
if self.ip_tutorial[ip]>self.tutorialMax:
return 1
else:
self.ip_tutorial[ip] = self.ip_tutorial[ip] + 1
return self.ip_tutorial[ip]
def hasNextTutorial(self,ip):
if self.ip_tutorial[ip] == self.tutorialMax:
return 0
else:
return 1
2022-11-09 14:09:00 +00:00
def getControl(self,ip):
return self.ip_control[ip]
2022-11-03 14:07:08 +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-15 05:46:21 +00:00
csv_write.writerow([*data, ''])