def insertUpdateCurrentMaxMinRecords(auths, dailyCurrencies): maxMinRecordTables = [] sourceHelper = source(auths) maxMinRecordTableNames = ["dailyMaxMinRecords", "weeklyMaxMinRecords", "monthlyMaxMinRecords"] for maxMinRecordTableName in maxMinRecordTableNames: maxMinRecordTable = sourceHelper.getTable(maxMinRecordTableName) maxMinRecordNewCode = sourceHelper.getNewCode(maxMinRecordTable) currentRecord = sourceHelper.getRows(maxMinRecordTable["rows"], ["code"], [maxMinRecordNewCode]) if len(currentRecord) == 0: currentRecord = {"code": maxMinRecordNewCode, "min": dailyCurrencies, "max": dailyCurrencies } maxMinRecordTable["rows"].append(currentRecord) sourceHelper.saveTable(maxMinRecordTable) else: currentRecord = currentRecord[0] for key, value in dailyCurrencies.items(): if key not in ("code", "currencySource"): if value >= currentRecord["max"][key]: currentRecord["max"][key] = value if value <= currentRecord["min"][key]: currentRecord["min"][key] = value sourceHelper.updateTable(maxMinRecordTable, currentRecord) maxMinRecordTables.append(maxMinRecordTable) return maxMinRecordTables
def add(self, source, **params): s = source( name = "%s.union._%i" % (self.name, len(self.__members)), t_update = None, t_keep = 0, **params ) self.__members.append(s) return self
def getCurrentMaxMinRecords(auths): maxMinRecordTables = [] sourceHelper = source(auths) maxMinRecordTableNames = ["dailyMaxMinRecords", "weeklyMaxMinRecords", "monthlyMaxMinRecords"] for maxMinRecordTableName in maxMinRecordTableNames: maxMinRecordTables.append(sourceHelper.getTable(maxMinRecordTableName)) return maxMinRecordTables
def getCurrentMaxMinRecords(auths): maxMinRecordTables = [] sourceHelper = source(auths) maxMinRecordTableNames = [ "dailyMaxMinRecords", "weeklyMaxMinRecords", "monthlyMaxMinRecords" ] for maxMinRecordTableName in maxMinRecordTableNames: maxMinRecordTables.append(sourceHelper.getTable(maxMinRecordTableName)) return maxMinRecordTables
def insertUpdateCurrentMaxMinRecords(auths, dailyCurrencies): maxMinRecordTables = [] sourceHelper = source(auths) maxMinRecordTableNames = [ "dailyMaxMinRecords", "weeklyMaxMinRecords", "monthlyMaxMinRecords" ] for maxMinRecordTableName in maxMinRecordTableNames: maxMinRecordTable = sourceHelper.getTable(maxMinRecordTableName) maxMinRecordNewCode = sourceHelper.getNewCode(maxMinRecordTable) currentRecord = sourceHelper.getRows(maxMinRecordTable["rows"], ["code"], [maxMinRecordNewCode]) if len(currentRecord) == 0: currentRecord = { "code": maxMinRecordNewCode, "min": dailyCurrencies, "max": dailyCurrencies } maxMinRecordTable["rows"].append(currentRecord) sourceHelper.saveTable(maxMinRecordTable) else: currentRecord = currentRecord[0] for key, value in dailyCurrencies.items(): if key not in ("code", "currencySource"): if value >= currentRecord["max"][key]: currentRecord["max"][key] = value if value <= currentRecord["min"][key]: currentRecord["min"][key] = value sourceHelper.updateTable(maxMinRecordTable, currentRecord) maxMinRecordTables.append(maxMinRecordTable) return maxMinRecordTables
total = 0.0 if ((i1 <= 1) or (i1 > 2)): #GO TO(10, 160), I1 if ((ifun != 2)): #GO TO (30, 20, 30, 30), IFUN #10 ifun2 = ifun ifun = 1 #20 ###GO TO 40#################working on this!!!!!!#################################################### #if ncal =1 go to 40, if ncal = 2 go to 80 #30 if (ncal == 1): i = 2 while (i < 250): #DO 50 I=2, 250 #40 t1 = i * dt #ORIGINAL FORTRAN HAD T * DT... I think it was supposed to be I * DT??? t2 = (i-1) * dt s1 = source(t1) s2 = source(t2) i += 1 #end while loop #50 #if (s1 - s2) 60, 50, 50 #go to 60 if neg, go to 50 if 0 or positive if ((s1 - s2) >= 0): #(print 410, ifun) #example: PRINT f, list (f is a format reference, list is what is being printed) sys.exit("Error occured. ifun is: {0}.".format(ifun)) #stop peak = s2 #60 cay = gcal/peak if ((ifun2 - 2) == 0):
def getAvailableUserAlarms(auths, dailyRecordsTable, userAlarmsTable, userId): sourceHelper = source(auths) now = datetime.now(tz) currencies = dailyRecordsTable["rows"][len(dailyRecordsTable["rows"]) - 1] availableUserAlarms = [] alarmsTable = sourceHelper.getTable("alarms") userAlarmWavePointsTable = sourceHelper.getTable("userAlarmWavePoints") userAlarms = sourceHelper.getRowsByClause( userAlarmsTable["rows"], ["userId", "startDate", "finishDate", "status"], [userId, now, now, "1"], ["equal", "biggerorequal", "smallerorequal", "equal"]) for userAlarm in userAlarms: alarm = sourceHelper.getRows(alarmsTable["rows"], ["id"], userAlarm["alarmId"])[0] if alarm["type"] == "1": # Belli saatlerde calisan alarm hourItem = alarm["hour"].split(":") if now.hour == int(hourItem[0]) + WebConfig["HourFixer"] and int( hourItem[1]) - 2 <= now.minute <= int(hourItem[1]) + 2: availableUserAlarms.append(alarm) elif alarm[ "type"] == "2": # Belli degeri gecince veya altinda kalinca calisan alarm for currencyCode in alarm["currencies"].split(","): if isThisRow(alarm["when"], alarm["value"], currencies[currencyCode]): availableUserAlarms.append(alarm) userAlarm["status"] = "0" sourceHelper.updateTable(userAlarmsTable, userAlarm) elif alarm[ "type"] == "3": # Belli miktarda dalgalanma oldugunda calisan alarm for currencyCode in alarm["currencies"].split(","): wavePoint = { "userAlarmId": userAlarm["id"], "date": str(now), "value": "", "currency": currencyCode, "isReferencePoint": "1" } userAlarmWavePoints = sourceHelper.getRows( userAlarmWavePointsTable["rows"], ["userAlarmId", "date", "currency"], [userAlarm["id"], now, currencyCode]) if len(userAlarmWavePoints) == 0: lastDayLastWavePoint = sourceHelper.getRows( userAlarmWavePointsTable["rows"], ["userAlarmId", "date", "currency"], [ userAlarm["id"], now + timedelta(days=-1), currencyCode ]) if len(lastDayLastWavePoint) > 0: wavePoint["value"] = lastDayLastWavePoint[0]["value"] else: wavePoint["value"] = currencies[currencyCode] wavePoint["id"] = sourceHelper.getNewCode( userAlarmWavePointsTable) wavePoint["isReferencePoint"] = "0" userAlarmWavePointsTable["rows"].append(wavePoint) sourceHelper.saveTable(userAlarmWavePointsTable) else: wavePoint = userAlarmWavePoints[0] currentWave = float(currencies[currencyCode]) - float( wavePoint["value"]) if alarm["when"] == "increase": isWaving = isThisRow("biggerorequal", alarm["value"], currentWave) elif alarm["when"] == "decrease": isWaving = isThisRow( "smaller", 0, currentWave) and isThisRow( "biggerorequal", alarm["value"], currentWave * -1) if isWaving: availableUserAlarms.append(alarm) if wavePoint["isReferencePoint"] == "0": wavePoint["value"] = currencies[currencyCode] wavePoint["date"] = str(now) sourceHelper.updateTable(userAlarmWavePointsTable, wavePoint) if "conjuagateUserAlarmId" in userAlarm: userConjugateAlarmWavePoints = sourceHelper.getRows( userAlarmWavePointsTable["rows"], ["userAlarmId", "date", "currency"], [ userAlarm["conjuagateUserAlarmId"], now, currencyCode ]) if len(userConjugateAlarmWavePoints) > 0: conjuagateWavePoint = userConjugateAlarmWavePoints[ 0] conjuagateWavePoint["value"] = currencies[ currencyCode] conjuagateWavePoint["date"] = str(now) sourceHelper.updateTable(userAlarmWavePointsTable, conjuagateWavePoint) return availableUserAlarms
def getAvailableUserAlarms(auths, dailyRecordsTable, userAlarmsTable, userId): sourceHelper = source(auths) now = datetime.now(tz) currencies = dailyRecordsTable["rows"][len(dailyRecordsTable["rows"]) - 1] availableUserAlarms = [] alarmsTable = sourceHelper.getTable("alarms") userAlarmWavePointsTable = sourceHelper.getTable("userAlarmWavePoints") userAlarms = sourceHelper.getRowsByClause(userAlarmsTable["rows"], ["userId", "startDate", "finishDate", "status"], [userId, now, now, "1"], ["equal", "biggerorequal", "smallerorequal", "equal"]) for userAlarm in userAlarms: alarm = sourceHelper.getRows(alarmsTable["rows"], ["id"], userAlarm["alarmId"])[0] if alarm["type"] == "1": # Belli saatlerde calisan alarm hourItem = alarm["hour"].split(":") if now.hour == int(hourItem[0]) + WebConfig["HourFixer"] and int(hourItem[1]) - 2 <= now.minute <= int(hourItem[1]) + 2: availableUserAlarms.append(alarm) elif alarm["type"] == "2": # Belli degeri gecince veya altinda kalinca calisan alarm for currencyCode in alarm["currencies"].split(","): if isThisRow(alarm["when"], alarm["value"], currencies[currencyCode]): availableUserAlarms.append(alarm) userAlarm["status"] = "0" sourceHelper.updateTable(userAlarmsTable, userAlarm) elif alarm["type"] == "3": # Belli miktarda dalgalanma oldugunda calisan alarm for currencyCode in alarm["currencies"].split(","): wavePoint = { "userAlarmId": userAlarm["id"], "date": str(now), "value": "", "currency": currencyCode, "isReferencePoint": "1" } userAlarmWavePoints = sourceHelper.getRows(userAlarmWavePointsTable["rows"], ["userAlarmId", "date", "currency"], [userAlarm["id"], now, currencyCode]) if len(userAlarmWavePoints) == 0: lastDayLastWavePoint = sourceHelper.getRows(userAlarmWavePointsTable["rows"], ["userAlarmId", "date", "currency"], [userAlarm["id"], now + timedelta(days = -1), currencyCode]) if len(lastDayLastWavePoint) > 0: wavePoint["value"] = lastDayLastWavePoint[0]["value"] else: wavePoint["value"] = currencies[currencyCode] wavePoint["id"] = sourceHelper.getNewCode(userAlarmWavePointsTable) wavePoint["isReferencePoint"] = "0" userAlarmWavePointsTable["rows"].append(wavePoint) sourceHelper.saveTable(userAlarmWavePointsTable) else: wavePoint = userAlarmWavePoints[0] currentWave = float(currencies[currencyCode]) - float(wavePoint["value"]) if alarm["when"] == "increase": isWaving = isThisRow("biggerorequal", alarm["value"], currentWave) elif alarm["when"] == "decrease": isWaving = isThisRow("smaller", 0, currentWave) and isThisRow("biggerorequal", alarm["value"], currentWave * -1) if isWaving: availableUserAlarms.append(alarm) if wavePoint["isReferencePoint"] == "0": wavePoint["value"] = currencies[currencyCode] wavePoint["date"] = str(now) sourceHelper.updateTable(userAlarmWavePointsTable, wavePoint) if "conjuagateUserAlarmId" in userAlarm: userConjugateAlarmWavePoints = sourceHelper.getRows(userAlarmWavePointsTable["rows"], ["userAlarmId", "date", "currency"], [userAlarm["conjuagateUserAlarmId"], now, currencyCode]) if len(userConjugateAlarmWavePoints) > 0: conjuagateWavePoint = userConjugateAlarmWavePoints[0] conjuagateWavePoint["value"] = currencies[currencyCode] conjuagateWavePoint["date"] = str(now) sourceHelper.updateTable(userAlarmWavePointsTable, conjuagateWavePoint) return availableUserAlarms
from source import * from knn import * import numpy as np import queue as Q from getNC_point import * que = Q.PriorityQueue() k = Knn() X,S_min = source() T_h = 60 # T_h 是阈值,C_p作为恒定参数控制类簇规模 k.fit(X) def Euclidean_Distance(a,b): d1=np.sqrt(np.sum(np.square(a-b))) return d1 def Ncpoint(cluster,X): index = getNcpoint(cluster,X) return index def clus_dis(A, B,X,K): if len(A) == 1 and len(B) == 1: NC_pointA = A[0] NC_pointB = B[0] # print(NC_pointA) # print(NC_pointB) distance = K.get_dis(NC_pointA, NC_pointB) else: NC_pointA = Ncpoint(A,X) NC_pointB = Ncpoint(B,X) # print(NC_pointA)
import sys from scapy.all import * from datetime import datetime, timedelta from source import * message_source = source() def add(message): message_source.add(message) if (message_source.count % 5000) == 0: print "Reached " + str( message_source.count) + " packets processed at: " + str( datetime.now().time()) def extract_arp_packet(packet): if packet.type == int(0x806): op_code = packet[ARP].op source = packet[ARP].psrc add((op_code, source)) def extract_for_graph_arp_packet(packet): if packet.type == int(0x806): op_code = packet[ARP].op source = packet[ARP].psrc destination = packet[ARP].pdst add((op_code, source, destination))
import sys from scapy.all import * from datetime import datetime, timedelta from source import * message_source = source() def add(message): message_source.add(message) if (message_source.count % 5000) == 0: print "Reached " + str(message_source.count) + " packets processed at: " + str(datetime.now().time()) def extract_arp_packet(packet): if packet.type == int(0x806): op_code = packet[ARP].op source = packet[ARP].psrc add((op_code, source)) def extract_for_graph_arp_packet(packet): if packet.type == int(0x806): op_code = packet[ARP].op source = packet[ARP].psrc destination = packet[ARP].pdst add((op_code, source, destination)) def extract_type_from_packet(packet): add(packet.type) def type_key_parser(type): return hex(type)