def __init__(self): self._pdb = Base('centric.partition') self._sdb = Base('centric.scanner') self._pdb.create('pid', 'maxSeq', 'minSeq', 'tableName', 'assigned', 'splitNum', 'phase', 'creator', 'createTime', 'lastUpdateTime', mode="override") self._sdb.create('startSeq', 'endSeq', 'intervalSecs', 'scannerId', 'pid', 'creator', 'createTime', 'lastUpdateTime', 'url', 'port', mode="override")
def generateWeights(graph, weightFile, param): pdb = Base(weightFile) pdb.create('pair', 'node1', 'node2', 'FI') pdb.create_index('pair') sortedNodes = sorted(graph.nodes()) for node in sortedNodes: others = sorted(set(n for n in sortedNodes if n > node)) for other in others: if graph.has_edge(node, other): informations = list( edge for n1, n2, edge in graph.edges([node, other], data=True) if ((n1 == node and n2 == other) or ( n1 == other and n2 == node))) total_publications = len(informations) bagNode1 = list( eval(edge['keywords']) for n1, n2, edge in graph.edges([node], data=True) if (n1 != other and n2 != other)) bagNode2 = list( eval(edge['keywords']) for n1, n2, edge in graph.edges([other], data=True) if (n1 != node and n2 != node)) jc = get_jacard_domain(bagNode1, bagNode2) pdb.insert( str(node) + ';' + str(other), node, other, (total_publications * (jc + 1))) pdb.commit() return pdb
def endGame(bot, currentMessage, chat_id): # /quit behavior ends the game for everyone gameRecords = Base("chatStorage/records.pdl") gameRecords.open() rec = gameRecords._groupChatID[str(chat_id)] # select all the records with chat_id (only 1) if not rec: botSendFunctions.sendText(bot, chat_id, "Invalid command format") return rec = rec[-1] # Strip the last record from the list pointsBoard = "Here are the scores\n" # Send the final scores to the group for name, points in zip(rec['memberUsernames'].split(), rec['memberPoints'].split()): pointsBoard += str(name) + ": " + str(points) + " point(s)\n" botSendFunctions.sendText(bot, chat_id, pointsBoard) for player in rec['memberChatIDs'].split(): # Clean out the playerCards global try: del globalVars.playerCards[player] except Exception: # If a player isn't there ignore it pass try: del globalVars.resp[rec['gameID']] # Delete the game's responses key del globalVars.currBlackCard[rec['gameID']] # Delete the game's current black card key del globalVars.whiteCards[rec['gameID']] except Exception: pass gameRecords.delete(rec) # Remove the database record gameRecords.commit() # Save the changes botSendFunctions.sendText(bot, chat_id, "Goodbye!")
def write_graph(channel): db = Base(os.path.join(SCRIPT_DIR, f'{channel}_members.db')) db.open() member_data = ((int(l['members'].split()[0]), l['time'].date()) for l in sorted(db, key=lambda x: x['time'])) variant = db[0]['members'].split()[1] # Split the list of combinations in two lists, one for the y values and one for the x values y, x = list(zip(*member_data)) fig = plt.figure() fig.autofmt_xdate() ax = fig.add_subplot(111) p = ax.plot(x, y, 'b') ax.yaxis.set_major_locator(MaxNLocator(integer=True)) date_range = (max(x) - min(x)).days # Change X axis locators for large date ranges if date_range > 365: ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y')) ax.xaxis.set_major_locator(mdates.YearLocator()) ax.xaxis.set_minor_locator(mdates.MonthLocator()) ax.set_xlabel('Date') ax.set_ylabel(f'{variant.capitalize()}') fig.suptitle(f'Number of {variant} for {channel} over time', fontsize=15) ax.set_title(f'Maximum: {max(y)}. Currently: {y[-1]}') ax.set_ylim(bottom=0) print(y[-1]) # Print latest value to stdout plt.xticks(rotation=45) fig.savefig(os.path.join(SCRIPT_DIR, f'{channel}.png'))
def _create_db(): try: app.db = Base('pets.pdl') app.db.create('name', 'type', 'age', 'sex', 'description', 'owner_email', 'image_url') except IOError: app.db.open() print('Base db already exists')
def playGame(bot, gameID): # Called by /startgame gameRecords = Base("chatStorage/records.pdl") gameRecords.open() rec = gameRecords._gameID[gameID] if not rec: # Error check return rec = rec[-1] globalVars.resp = dict() globalVars.resp[gameID] = dict() globalVars.currBlackCard = dict() def dealCards(): # Add random cards for every player players = rec['memberChatIDs'].split() globalVars.playerCards = dict() for player in players: l = [[] for _ in range(5)] globalVars.playerCards[player] = list() for i in range(5): card = globalVars.whiteCards[rec['gameID']].pop()['Value'] l[i].append(str("/ans " + rec['gameID'] + " " + card)) globalVars.playerCards[player] = l botSendFunctions.sendText(bot, player, "Here are your cards", 0, l) dealCards() globalVars.currBlackCard[gameID] = str(globalVars.blackCards[gameID].pop()['Value']) botSendFunctions.sendText(bot, rec['groupChatID'], globalVars.currBlackCard[gameID], 0, []) # Send a random black card to the group
def getAnswers(bot, currentMessage, chat_id): # Process the players responses here gameRecords = Base("chatStorage/records.pdl") gameRecords.open() rec = gameRecords._gameID[currentMessage.text[5:10]] if not rec: botSendFunctions.sendText(bot, chat_id, "Invalid command format") return rec = rec[-1] answer = currentMessage.text[11:] if currentMessage.text in [j for i in globalVars.playerCards[str(currentMessage.from_user.id)] for j in i] and not str(currentMessage.from_user.id) in globalVars.resp[rec['gameID']]: globalVars.resp[rec['gameID']][str(currentMessage.from_user.id)] = currentMessage.text[11:] emptyList = [] # List magic due to the way custom keyboards must be sent [[], [], []] try: emptyList.append("/ans " + str(rec['gameID']) + " " + globalVars.whiteCards[rec['gameID']].pop()['Value']) except IndexError: botSendFunctions.sendText(bot, rec['groupChatID'], "Sorry. Out of cards, game over.") endGame(bot, currentMessage, chat_id) return for i in range(len(globalVars.playerCards[str(chat_id)])): if currentMessage.text in globalVars.playerCards[str(chat_id)][i]: globalVars.playerCards[str(chat_id)].pop(i) break globalVars.playerCards[str(chat_id)].append(emptyList) newStr = globalVars.currBlackCard[rec['gameID']].replace("_____", str(answer)) # Send all the responses to the group chat if newStr == globalVars.currBlackCard[rec['gameID']]: # Handling for cards with no 'blank' botSendFunctions.sendText(bot, rec['groupChatID'], str(answer)) else: botSendFunctions.sendText(bot, rec['groupChatID'], newStr) botSendFunctions.sendText(bot, chat_id, "Answer recieved.") if set(globalVars.resp[rec['gameID']].keys()) == set(rec['memberUserIDs'].split()): # If everyone has responded call judge judge(bot, currentMessage.text[5:10], chat_id) else: botSendFunctions.sendText(bot, chat_id, "Invaild card sent.", keyboardLayout=globalVars.playerCards[str(chat_id)])
def lambda_handler(event, session): import boto3 from pydblite import Base db = Base('/tmp/TechHub.pld') if db.exists(): db.open() else: db.create('name', 'quantity') db.open() dynamodb = boto3.client('dynamodb') print("[INTENT_HANDLER]") print("event.session.application.applicationId=" + event['session']['application']['applicationId']) logger.info('got event{}'.format(event)) if event['session']['new']: on_session_started({'requestId': event['request']['requestId']}, event['session']) if event['request']['type'] == "LaunchRequest": output = on_launch(event['request'], event['session']) elif event['request']['type'] == "IntentRequest": output = on_intent(event['request'], event['session'], db, dynamodb) elif event['request']['type'] == "SessionEndedRequest": output = on_session_ended(event['request'], event['session']) db.commit() return output
def generateWeights(graph, weightFile, param): pdb = Base(weightFile) pdb.create('pair', 'node1', 'node2', 'TS02', 'TS05', 'TS08') pdb.create_index('pair') sortedNodes = sorted(graph.nodes()) for node in sortedNodes: others = sorted(set(n for n in sortedNodes if n > node)) for other in others: if graph.has_edge(node, other): informations = list( edge for n1, n2, edge in graph.edges([node, other], data=True) if ((n1 == node and n2 == other) or ( n1 == other and n2 == node))) timesofLinks = [] for info in informations: timesofLinks.append(int(info['time'])) total_publications = len(informations) k = int(param.t0_) - max(timesofLinks) decayfunction02 = (1 - 0.2)**k decayfunction05 = (1 - 0.5)**k decayfunction08 = (1 - 0.8)**k pdb.insert( str(node) + ';' + str(other), node, other, (total_publications * decayfunction02), (total_publications * decayfunction05), (total_publications * decayfunction08)) pdb.commit() return pdb
def calculatingWeights(graph, nodesnotLinked, database, calculatingFile): pdb = Base(calculatingFile) pdb.create('node1', 'node2', 'WCNFI','WAAFI') pdb.create_index('node1', 'node2') element = 0 qtyofNodesToProcess = len(nodesnotLinked) for pair in nodesnotLinked: element = element+1 FormatingDataSets.printProgressofEvents(element, qtyofNodesToProcess, "Calculating features for nodes not liked: ") neighbors_node1 = all_neighbors(graph, pair[0]) neighbors_node2 = all_neighbors(graph, pair[1]) len_neihbors_node1 = len(neighbors_node1) len_neihbors_node2 = len(neighbors_node2) CommonNeigbors = neighbors_node1.intersection(neighbors_node2) WCNFI = 0; WAAFI = 0; for cn in CommonNeigbors: item = get_partOfWeightCalculating(graph, database, pair, cn) WCNFI = WCNFI + item['WCN']; WAAFI = WAAFI + item['WAA']; pdb.insert(str(pair[0]), str(pair[1]), WCNFI, WAAFI ) pdb.commit() return pdb;
def run_class_configuration(request): if request.method == 'POST': db = Base('backendDB.pdl') if db.exists(): db.open() else: db.create('Type','Log', 'Run', 'Prefix','Rule','Threshold', 'TimeStamp', 'Status') configuration_json = json.loads(request.body) print configuration_json log = configuration_json["log"] prefix = configuration_json['prefix'] rule = configuration_json['rule'] threshold = configuration_json['threshold'] # Encode the file. encoding.encode(log, prefix) for encodingMethod in configuration_json['encoding']: for clustering in configuration_json['clustering']: for classification in configuration_json['classification']: django_rq.enqueue(tasks.classifierTask, log, prefix, encodingMethod, clustering, classification, rule, threshold) run = classification + '_' + encodingMethod + '_' + clustering records = [r for r in db if r['Run'] == run and r['Prefix'] == str(prefix) and r['Log'] == log and r['Rule'] == rule and r['Threshold'] == str(threshold)] print records if not records: db.insert("Classification", log, run, str(prefix), rule, str(threshold), time.strftime("%b %d %Y %H:%M:%S", time.localtime()), 'queued') else: db.update(records[0], TimeStamp=time.strftime("%b %d %Y %H:%M:%S", time.localtime()), Status= 'queued') db.commit() return HttpResponse("YOLO")
class Owner(Model): name = 'owner' base = Base('database/' + name + '.pdl') def create_db(cls): cls.base.create('login', 'password', 'name', 'email', 'phone', 'address') def insert_db(cls, request): return cls.db().insert( login=request.form['login'], name=request.form['name'], email=request.form['email'], phone=request.form['phone'], address=request.form['address'], password=sha256( request.json['password'].encode('UTF-8')).hexdigest()) def update_db(cls, item, request): return cls.db().update(item, name=request.form['name'], email=request.form['email'], phone=request.form['phone'], address=request.form['address']) def __init__(self, id): super().__init__(id) self.data.pop('password')
def winner(bot, currentMessage, chat_id): # Decide who wins here. Only the judge is able to use this gameRecords = Base("chatStorage/records.pdl") gameRecords.open() rec = gameRecords._gameID[currentMessage.text[5:10]] if not rec: botSendFunctions.sendText(bot, chat_id, "Invalid command format") return rec = rec[-1] if currentMessage.from_user.id == rec['creator']: revD = {value: key for key, value in globalVars.resp[rec['gameID']].items()} winningResp = currentMessage.text[11:] if winningResp in revD.keys(): winningPerson = revD[winningResp] pointsList = rec['memberPoints'].split() # List stuff for the database memberList = rec['memberUserIDs'].split() nameList = rec['memberUsernames'].split() pointsList[memberList.index(winningPerson)] = int(pointsList[memberList.index(winningPerson)]) + 1 gameRecords.update(rec, memberPoints=" ".join([str(i) for i in pointsList])) # Points backend for Assign 3 gameRecords.commit() botSendFunctions.sendText(bot, rec['groupChatID'], "The winner was " + nameList[memberList.index(winningPerson)] + " with " + winningResp + " They now have " + str(pointsList[memberList.index(winningPerson)]) + " point(s).") # Send who won to the group chat try: globalVars.currBlackCard[currentMessage.text[5:10]] = str(globalVars.blackCards[rec['gameID']].pop()['Value']) # Get the next black card except IndexError: # If there are no more cards end the game botSendFunctions.sendText(bot, rec['groupChatID'], "Sorry, out of cards. Thanks for playing") endGame(bot, currentMessage, chat_id) return botSendFunctions.sendText(bot, rec['groupChatID'], globalVars.currBlackCard[currentMessage.text[5:10]]) # Send the next black card for player in rec['memberChatIDs'].split(): # Send all the players a new card to replace the one they used del globalVars.resp[rec['gameID']][player] botSendFunctions.sendText(bot, player, "Here are your new cards", 0, globalVars.playerCards[player]) else: botSendFunctions.sendText(bot, chat_id, "Invalid answer") else: botSendFunctions.sendText(bot, chat_id, "You are not the judge")
def open_db(): db = Base(DB_FILE) db.create('abbr', 'name', 'available', 'volume', 'buy', 'sell', 'date', mode="open") if not db.exists(): raise Exception('Database error') db.create_index('abbr') return db
def get_cursor(db_name): if db_name == 'weather_data': db = Base('storage/weather_data.pdl') if not db.exists(): db.create('low', 'tmw', 'high', 'temp', 'date', 'text', 'code', 'history', 'uniq_id', 'location', 'astronomy', 'atmosphere', 'country_name', 'created_date', 'location_name') elif db_name == 'locations': db = Base('storage/locations.pdl') if not db.exists(): db.create('uniq_id', 'location', 'created_date') else: raise Exception('Please Enter Valid Name!') cursor = db.open() return cursor
def save_in_db(comic_url): db = Base(os.path.join(SCRIPT_DIR, 'comics.db')) db.create('comic', 'time', mode="open") db.insert(comic=comic_url, time=datetime.datetime.now()) db.commit() return len(db(comic=comic_url)) == 1
def save_in_db(channel, count): db = Base(os.path.join(SCRIPT_DIR, f'{channel}_members.db')) db.create('members', 'time', mode="open") len_db = len(db) count_previous = db[len_db - 1]['members'] if len_db else 0 if count != count_previous: db.insert(members=count, time=datetime.datetime.now()) db.commit() return True
def getConfStatus(request): db = Base('backendDB.pdl') if db.exists(): db.open() records = []; for r in db: print r records.append(r) return HttpResponse(json.dumps(records), content_type="application/json")
def save_in_db(channel, count, date): db = Base(os.path.join(SCRIPT_DIR, f'{channel}_members.db')) db.create('members', 'time', mode="open") variant = db[0]['members'].split()[1] value = f"{count} {variant}" already_present = [r for r in db if r['members'] == value] if not already_present: db.insert(members=value, time=date) db.commit() return True
def __init__(self, mode): self.db = Base("./mlfv_hosts.pdl") self.db.create('ip', 'port', 'libs', 'cpu', 'mem', 'net', 'runs', mode=mode)
class Data: """Stores global data Gives access to a series of global variables for use throughout the file """ books = {} authors = {} bookDB = Base(EBOOK_FOLDER + 'books.pdl') authorDB = Base(EBOOK_FOLDER + 'authors.pdl') @staticmethod def debug_log(msg_str): """Log helper Prefixes a debug message with the plugin title to allow for easy search in the log Arguments: msg_str {string} -- Message to log """ Log.Debug(TITLE + ": " + msg_str)
def setUp(self): self.app = app.test_client() self.app.testing = True test_db = 'test_pets.pdl' if os.path.exists(test_db): os.remove(test_db) self.app.application.db = Base(test_db) self.app.application.db.create('name', 'type', 'age', 'sex', 'description', 'owner_email', 'image_url') self.test_create_pets()
def __init__(self): requests.packages.urllib3.disable_warnings(InsecureRequestWarning) self.config = json.loads( open("/opt/prometheus/vrops_exporter/vrops.json").read()) journal.send("Connecting to vROPs host: ", FIELD2=self.config["server"]["hostname"]) self.vcops = nagini.Nagini(host=self.config["server"]["hostname"], user_pass=(self.config["server"]["user"], self.config["server"]["pwd"])) #print vcops.get_resources(resourceKind="VirtualMachine", pageSize=1) self.db = Base('/tmp/vrops.pd1')
def generateWeights(graph, weightFile, param): pdb = Base(weightFile) pdb.create('pair', 'node1', 'node2', 'FTI01', 'FTI02', 'FTI03', 'FTI04', 'FTI05', 'FTI06', 'FTI07', 'FTI08', 'FTI09') pdb.create_index('pair') sortedNodes = sorted(graph.nodes()) for node in sortedNodes: others = sorted(set(n for n in sortedNodes if n > node)) for other in others: if graph.has_edge(node, other): informations = list( edge for n1, n2, edge in graph.edges([node, other], data=True) if ((n1 == node and n2 == other) or ( n1 == other and n2 == node))) timesofLinks = [] for info in informations: timesofLinks.append(int(info['time'])) total_publications = len(informations) k = int(param.t0_) - max(timesofLinks) decayfunction = (0.8)**k bagNode1 = list( eval(edge['keywords']) for n1, n2, edge in graph.edges([node], data=True) if (n1 != other and n2 != other)) bagNode2 = list( eval(edge['keywords']) for n1, n2, edge in graph.edges([other], data=True) if (n1 != node and n2 != node)) jc = get_jacard_domain(bagNode1, bagNode2) FTI01 = total_publications * (decayfunction * (1 / (0.1**jc))) FTI02 = total_publications * (decayfunction * (1 / (0.2**jc))) FTI03 = total_publications * (decayfunction * (1 / (0.3**jc))) FTI04 = total_publications * (decayfunction * (1 / (0.4**jc))) FTI05 = total_publications * (decayfunction * (1 / (0.5**jc))) FTI06 = total_publications * (decayfunction * (1 / (0.6**jc))) FTI07 = total_publications * (decayfunction * (1 / (0.7**jc))) FTI08 = total_publications * (decayfunction * (1 / (0.8**jc))) FTI09 = total_publications * (decayfunction * (1 / (0.9**jc))) pdb.insert( str(node) + ';' + str(other), node, other, FTI01, FTI02, FTI03, FTI04, FTI05, FTI06, FTI07, FTI08, FTI09) pdb.commit() return pdb
def generateWeights(graph, weightFile, param): pdb = Base(weightFile) pdb.create('pair', 'node1', 'node2', 'CTS02', 'CTS05', 'CTS08') pdb.create_index('pair') sortedNodes = sorted(graph.nodes()) for node in sortedNodes: others = sorted(set(n for n in sortedNodes if n > node)) for other in others: if graph.has_edge(node, other): informations = list( edge for n1, n2, edge in graph.edges([node, other], data=True) if ((n1 == node and n2 == other) or ( n1 == other and n2 == node))) timesofLinks = [] for info in informations: timesofLinks.append(int(info['time'])) bagNode1 = list( eval(edge['keywords']) for n1, n2, edge in graph.edges([node], data=True) if (n1 != other and n2 != other)) bagNode2 = list( eval(edge['keywords']) for n1, n2, edge in graph.edges([other], data=True) if (n1 != node and n2 != node)) total_publications = len(informations) k = int(param.t0_) - max(timesofLinks) jc = get_jacard_domain(bagNode1, bagNode2) decayfunction = (0.6)**k decayfunction02 = (1 - 0.7)**jc decayfunction05 = (1 - 0.8)**jc decayfunction08 = (1 - 0.9)**jc CTS02 = total_publications * (decayfunction * (1 / decayfunction02)) CTS05 = total_publications * (decayfunction * (1 / decayfunction05)) CTS08 = total_publications * (decayfunction * (1 / decayfunction08)) pdb.insert( str(node) + ';' + str(other), node, other, CTS02, CTS05, CTS08) pdb.commit() return pdb
def judge(bot, gameID, chat_id): # Send all the responses to the judge gameRecords = Base("chatStorage/records.pdl") gameRecords.open() rec = gameRecords._gameID[gameID] if not rec: botSendFunctions.sendText(bot, chat_id, "Invalid command format") return rec = rec[-1] l = [[] for _ in range(len(globalVars.resp[rec['gameID']]))] i = 0 for ans in globalVars.resp[rec['gameID']].values(): l[i].append("/win " + gameID + " " + str(ans)) i += 1 botSendFunctions.sendText(bot, rec['creatorChatID'], "Here are the responses", keyboardLayout=l)
def generateDataForCalculate(self): if self.trainnigGraph == None: self.generating_Training_Graph() _nodes = sorted(self.trainnigGraph.nodes()) adb = Base(self.filePathTrainingGraph + ".calc.pdl") adb.create('pairNodes', 'common', 'time', 'domain') for node in sorted(_nodes): othernodes = set(n for n in _nodes if n > node) for other in othernodes: common = set( networkx.common_neighbors(self.trainnigGraph, node, other)) arestas = self.trainnigGraph.edges([node, other], True)
def new_repo(db_path): all_items = list_queue() pbs_id = [] for line in all_items: pbs_id.append(str(re.search(r'\d+', line).group())) job_db = Base(os.path.join(db_path, 'PBS_job_database.pdl')) job_db.create('PBS_id', 'uniq_id', 'work_dir') for ele in pbs_id: ele_dir = init_work_dir(ele) ele_id = re.findall(r'\d+', ele_dir)[-1] job_db.insert(PBS_id=ele, work_dir=ele_dir, uniq_id=ele_id) job_db.commit() return job_db
def __init__(self, name, path='./', mode="open"): '''mode can be 'override' ''' name_sig = name + '_sig.pdl' name_sig = join(path, name_sig) self.db_sig = Base(name_sig) self.db_sig.create('signal_bundle', 'signals', 'timestamps', 'name', 'labels', 'md5', 'sublabel', mode=mode) self.db_sig.open()
def __init__(self, database_name=None): print ("Opening " + database_name) db_r = Base(database_name) # Choose the DB of the Question Thread URL db_r.create('url', 'date', mode="open") # Check if the DB is empty or new if len(db_r)==0: print ("ERROR: Database not found or empty") sys.exit() else: print ("Database elements: " + str(len(db_r))) for r in db_r: self.url_to_scrape.append(UrlDate(r["url"], r["date"])) # Making a SET of the Database in order to delete duplicate URLS self.url_to_scrape = {x.url: x for x in self.url_to_scrape}.values() print ("Database elements after set operation: " + str(len(db_r)))