Browse Source

initial commit

master
Chris Mahoney 2 years ago
commit
10909cf818
  1. 3
      .gitignore
  2. 1
      README.md
  3. 99
      commit.py
  4. 19
      run.sh

3
.gitignore

@ -0,0 +1,3 @@
apgmera/
logs/
processed/

1
README.md

@ -0,0 +1 @@
initail commit

99
commit.py

@ -0,0 +1,99 @@
from os import listdir, system
import mysql.connector
mydb = mysql.connector.connect(
host="trilogy",
user="soup",
password="ecosystem-pusher-riveter-nifty",
database="soups"
)
home = "/home/mahonec/soup/"
# Get logs
logs = [home + "logs/" + f for f in listdir(home + "logs/")]
logs.sort()
for log in logs:
print("processing " + log)
# Load log file into dictionary
res = {}
# Get log unix timestamp
res["time"] = int(log.split(".")[1])
with open(log, "r") as fp:
fp.readline() # payosha256 key
fp.readline() # Blank
res["version"] = fp.readline().split(" ")[1][:-1]
res["md5"] = fp.readline().split(" ")[1][:-1]
res["root"] = fp.readline().split(" ")[1][:-1]
res["rule"] = fp.readline().split(" ")[1][:-1]
res["symmetry"] = fp.readline().split(" ")[1][:-1]
res["num_soups"] = int(fp.readline().split(" ")[1])
res["num_objects"] = int(fp.readline().split(" ")[1])
fp.readline() # Blank
fp.readline() # CENSUS TABLE
l = fp.readline() # First census (probably xs4_33)
res["census"] = {}
while l != "\n":
split = l.split(" ")
res["census"][split[0]] = int(split[1])
l = fp.readline()
fp.readline() # SAMPLE_SOUPIDS
l = fp.readline() # First sample (probably xs4_33)
res["samples"] = {}
while l != "":
split = l.split(" ")
split[-1] = split[-1][:-1] # Removes \n from end of last value
res["samples"][split[0]] = [res["root"] + c for c in split[1:]] # Combine id with root for further reference
l = fp.readline()
# Complete census
for life in res["census"]:
cursor = mydb.cursor()
sql = "SELECT * FROM census WHERE apgcode=%s"
code = (life, )
cursor.execute(sql, code)
result = cursor.fetchall()
# Check if no element exists
if result == []:
sql = "INSERT INTO census VALUES ('%s', %d, %d, %d)" % (life, res["census"][life], res["time"], res["time"])
cursor.execute(sql)
else:
# Update element with new total and new time
apgcode, population, firstFound, lastFound = result[0]
population += res["census"][life]
if lastFound < res["time"]:
sql = "UPDATE census SET population=%d, lastFound=%d WHERE apgcode='%s'" % (population, res["time"], life)
else:
sql = "UPDATE census SET population=%d WHERE apgcode='%s'" % (population, life)
cursor.execute(sql)
# Add samples
for life in res["samples"]:
cursorn = mydb.cursor()
sql = "SELECT * FROM samples WHERE apgcode='%s'" % life
cursorn.execute(sql)
result = cursorn.fetchall()
n = len(result)
for sample in res["samples"][life]:
sql = "INSERT INTO samples VALUES ('%s', %d, '%s')" % (life, n ,sample)
if n < 25 or sample[:1] == "me": # "me" is the prefix to "megasized" "messless" and "methuselah"
cursorn.execute(sql)
n += 1
elif n == 25:
cursorn.execute(sql)
break
else:
break
system("mv " + log + " " + home + "processed")
mydb.commit()
system("gzip " + home + "processed/*.txt")

19
run.sh

@ -0,0 +1,19 @@
# Init directoriesa
if [ ! -d "logs" ]; then
mkdir logs
fi
if [ ! -d "processed" ]; then
mkdir processed
fi
# Pull requirements
if [ ! -d "apgmera" ]; then
git clone https://gitlab.com/apgoucher/apgmera.git
fi
# cd into logs so that the logs files will be saved to there
cd logs
# run apgmera you can change the key.
nohup ./../apgmera/apgluxe -n 10000000 -L 1 -k FM23ToPikEy6Dfh3</dev/null >/dev/null 2>&1 &
Loading…
Cancel
Save