Skip to content

Commit

Permalink
Merge pull request #19 from NoFoolLikeOne/Codex-Entries
Browse files Browse the repository at this point in the history
NHSS and HDREPORT
  • Loading branch information
NoFoolLikeOne authored Jan 20, 2019
2 parents 3b6bfc0 + 73e3393 commit 3533679
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 75 deletions.
8 changes: 5 additions & 3 deletions canonn/codex.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Codex(threading.Thread):
'''
Should probably make this a heritable class as this is a repeating pattern
'''
def __init__(self,cmdr, is_beta, system, x,y,z, entry, body,lat,lon):
def __init__(self,cmdr, is_beta, system, x,y,z, entry, body,lat,lon,client):
threading.Thread.__init__(self)
self.cmdr = cmdr
self.system = system
Expand All @@ -22,6 +22,7 @@ def __init__(self,cmdr, is_beta, system, x,y,z, entry, body,lat,lon):
self.lon = lon
self.is_beta = is_beta
self.entry = entry.copy()
seles.client = client



Expand Down Expand Up @@ -52,6 +53,7 @@ def run(self):
payload["voucherAmount"]=self.entry.get("VoucherAmount")
payload["rawJson"]=self.entry
payload["isBeta"]=self.is_beta
payload["clientVersion"]=self.client

try:
r=requests.post("https://api.canonn.tech:2053/codexreports",data=json.dumps(payload),headers={"content-type":"application/json"})
Expand All @@ -67,8 +69,8 @@ def matches(d, field, value):
journaldata.submit(cmdr, system, station, entry)
'''
def submit(cmdr, is_beta, system, x,y,z, entry, body,lat,lon):
def submit(cmdr, is_beta, system, x,y,z, entry, body,lat,lon,client):
if entry["event"] == "CodexEntry":
Codex(cmdr, is_beta, system, x,y,z,entry, body,lat,lon).start()
Codex(cmdr, is_beta, system, x,y,z,entry, body,lat,lon,client).start()


8 changes: 5 additions & 3 deletions canonn/factionkill.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ class FactionKill(threading.Thread):
'''
Should probably make this a heritable class as this is a repeating pattern
'''
def __init__(self,cmdr, is_beta, system, station, entry):
def __init__(self,cmdr, is_beta, system, station, entry,client):
threading.Thread.__init__(self)
self.system = system
self.cmdr = cmdr
self.station = station
self.is_beta = is_beta
self.entry = entry.copy()
self.client = client


def run(self):
Expand All @@ -36,6 +37,7 @@ def run(self):
payload["rewardingFaction"]=self.entry["AwardingFaction"]
payload["victimFaction"]=self.entry["VictimFaction"]
payload["isbeta"]= self.is_beta
payload["clientVersion"]= self.client

try:
r=requests.post("https://api.canonn.tech:2053/killreports",data=json.dumps(payload),headers={"content-type":"application/json"})
Expand All @@ -51,11 +53,11 @@ def matches(d, field, value):
journaldata.submit(cmdr, system, station, entry)
'''
def submit(cmdr, is_beta, system, station, entry):
def submit(cmdr, is_beta, system, station, entry,client):
if entry["event"] == "FactionKillBond" and (
matches(entry, 'VictimFaction', '$faction_Thargoid;') or
matches(entry, 'VictimFaction', '$faction_Guardian;')
):
FactionKill(cmdr, is_beta, system, station, entry).start()
FactionKill(cmdr, is_beta, system, station, entry,client).start()


74 changes: 74 additions & 0 deletions canonn/hdreport.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import threading
import requests
import sys
import json

'''
{ "timestamp":"2018-10-07T13:03:02Z",
"event":"USSDrop",
"USSType":"$USS_Type_NonHuman;",
"USSType_Localised":"Non-Human signal source",
"USSThreat":4 }
'''

class HDReport(threading.Thread):

hdsystem=""

'''
Should probably make this a heritable class as this is a repeating pattern
'''
def __init__(self,cmdr, is_beta, system, station, entry,client):
threading.Thread.__init__(self)
self.system = system
self.cmdr = cmdr
self.station = station
self.is_beta = is_beta
self.entry = entry.copy()
self.client=client


def run(self):
payload={}

payload["fromSystemName"]=self.entry.get("TG_ENCOUNTERS").get("TG_ENCOUNTER_TOTAL_LAST_SYSTEM")
payload["cmdrName"]=self.cmdr
payload["isbeta"]= self.is_beta
payload["clientVersion"]= self.client
payload["reportStatus"]="accepted"
payload["reportComment"]="Hyperdiction from TG_ENCOUNTERS"
payload["hdRawJson"]=self.entry.get("TG_ENCOUNTERS")


try:
r=requests.post("https://api.canonn.tech:2053/hdreports",data=json.dumps(payload),headers={"content-type":"application/json"})
#print payload
#print r
except:
print("[EDMC-Canonn] Issue posting ussReport " + str(sys.exc_info()[0]))
print r

def matches(d, field, value):
return field in d and value == d[field]

'''
from canonn import journaldata
journaldata.submit(cmdr, system, station, entry)
'''
def submit(cmdr, is_beta, system, station, entry,client):

# The last system isnt always set so we can ignore
if entry["event"] == "Statistics" and entry.get("TG_ENCOUNTERS").get("TG_ENCOUNTER_TOTAL_LAST_SYSTEM"):

lastsystem=entry.get("TG_ENCOUNTERS").get("TG_ENCOUNTER_TOTAL_LAST_SYSTEM")
if HDReport.hdsystem == lastsystem:
print("Hyperdiction already recorded here ")
else:
HDReport.hdsystem = lastsystem
HDReport(cmdr, is_beta, lastsystem, station, entry,client).start()




8 changes: 5 additions & 3 deletions canonn/journaldata.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,14 @@ class CanonnJournal(threading.Thread):
'''
Should probably make this a heritable class as this is a repeating pattern
'''
def __init__(self,cmdr, is_beta, system, station, entry):
def __init__(self,cmdr, is_beta, system, station, entry,client):
threading.Thread.__init__(self)
self.system = system
self.cmdr = cmdr
self.station = station
self.is_beta = is_beta
self.entry = entry.copy()
self.client = client


def run(self):
Expand All @@ -90,6 +91,7 @@ def run(self):
payload["cmdrName"]=self.cmdr
payload["jsonData"]=self.entry
payload["EventName"]=self.entry["event"]
payload["clientVersion"]= self.client


included_event=(self.entry["event"] not in excluded_events)
Expand All @@ -112,5 +114,5 @@ def run(self):
journaldata.submit(cmdr, system, station, entry)
'''
def submit(cmdr, is_beta, system, station, entry):
CanonnJournal(cmdr, is_beta, system, station, entry).start()
def submit(cmdr, is_beta, system, station, entry,client):
CanonnJournal(cmdr, is_beta, system, station, entry,client).start()
105 changes: 105 additions & 0 deletions canonn/nhss.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import threading
import requests
import sys
import json

'''
{ "timestamp":"2018-10-07T13:03:02Z",
"event":"USSDrop",
"USSType":"$USS_Type_NonHuman;",
"USSType_Localised":"Non-Human signal source",
"USSThreat":4 }
'''

class NHSS(threading.Thread):

fss= {}

'''
Should probably make this a heritable class as this is a repeating pattern
'''
def __init__(self,cmdr, is_beta, system, station, entry,client):
threading.Thread.__init__(self)
self.system = system
self.cmdr = cmdr
self.station = station
self.is_beta = is_beta
self.entry = entry.copy()
self.client=client


def run(self):
payload={}

if self.entry["event"] == 'FSSSignalDiscovered':
threatLevel=self.entry.get("ThreatLevel")
type="FSS"
else:
threatLevel=self.entry.get("USSThreat")
type="Drop"

payload["systemName"]=self.system
payload["cmdrName"]=self.cmdr
payload["nhssRawJson"]=self.entry
payload["threatLevel"]=threatLevel
payload["isbeta"]= self.is_beta
payload["clientVersion"]= self.client
payload["reportStatus"]="accepted"
payload["reportComment"]=type


try:
r=requests.post("https://api.canonn.tech:2053/nhssreports",data=json.dumps(payload),headers={"content-type":"application/json"})
#print payload
#print r
except:
print("[EDMC-Canonn] Issue posting ussReport " + str(sys.exc_info()[0]))
print r

def matches(d, field, value):
return field in d and value == d[field]

'''
from canonn import journaldata
journaldata.submit(cmdr, system, station, entry)
'''
def submit(cmdr, is_beta, system, station, entry,client):

#USS and FFS
if entry["event"] in ("USSDrop",'FSSSignalDiscovered') and entry.get("USSType") == "$USS_Type_NonHuman;" :

# The have different names for teh same thing so normalise
if entry["event"] == 'FSSSignalDiscovered':
threatLevel=entry.get("ThreatLevel")
else:
threatLevel=entry.get("USSThreat")

# see if you have system and threat levels store
# Thsi will fail if it a new threat level in the current system
try:
globalfss=NHSS.fss.get(system)
oldthreat=globalfss.get(threatLevel)
#print(globalfss)
except:
oldthreat=False


if oldthreat:
print("Threat level already recorded here "+str(threatLevel))

else:
#print("Threat {}".format(threatLevel))
try:
#set the threatlevel for the system
NHSS.fss[system][threatLevel] = True
except:
#we couldnt find teh system so lets define it
NHSS.fss[system]={ threatLevel: True}

NHSS(cmdr, is_beta, system, station, entry,client).start()




57 changes: 0 additions & 57 deletions canonn/ussdrop.py

This file was deleted.

Loading

0 comments on commit 3533679

Please sign in to comment.