Skip to content

Commit

Permalink
vector code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
efultz committed Oct 18, 2023
1 parent 1974472 commit 4dc9ff3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 36 deletions.
64 changes: 40 additions & 24 deletions vector/equipment_outage_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from model import RiskVector, Test

from sqlalchemy.orm.session import Session
from sqlalchemy.orm.query import Query
from model import Test
from vector import InternetVector

Expand Down Expand Up @@ -36,42 +37,57 @@ def execute(self, expected_timedelta: timedelta):
self.session.commit()
# print(result)

tests = self.session.query(Test).filter(
q: Query[Test] = self.session.query(Test).filter(
Test.datetime >= datetime_from,
Test.datetime <= datetime_to,
Test.vector_id.in_(self.observed_riskvector_ids),
).order_by(Test.datetime)

expweighted = 0.0
outage = 0.0

# find all sequential outages.
# Determine a score based on how many and how long the outages are.
# longer sequences have a much higher weight by cubing its length
# divide by a constant scaling factor, then equalize to 0<x<1 with 1-1/(x+1)
for test in tests.all():
tests: list[Test] = list(q.all())


groups : dict[int, list[Test]] = {}
group_scores : dict[int, int] = {}
for test in tests:
if test.vector_id not in groups.keys():
groups[test.vector_id] = []
groups[test.vector_id].append(test)


for vector_id in groups.keys():
group: list[Test] = groups[vector_id]
expweighted = 0.0
outage = 0.0
# find all sequential outages.
# Determine a score based on how many and how long the outages are.
# longer sequences have a much higher weight by cubing its length
# divide by a constant scaling factor, then equalize to 0<x<1 with 1-1/(x+1)
# scaling factor of 25 feels ok. solo outages add 3%. 3 outages in a row adds 50%.
for test in group:
print("expweighted: %s outage: %d "%(expweighted,outage))
if test.score > 0.0:
outage += 1
else:
if outage > 0:
# this is the end of a sequence, cube its length
expweighted += outage * outage * outage / 200.0
outage = 0

if outage > 0:
expweighted += outage * outage * outage / 200.0

print("expweighted: %s outage: %d "%(expweighted,outage))
if test.score > 0.0:
outage += 1
else:
if outage > 0:
# this is the end of a sequence, cube its length
expweighted += outage * outage * outage / 200.0
outage = 0

if outage > 0:
expweighted += outage * outage * outage / 200.0

print("expweighted: %s outage: %d "%(expweighted,outage))

result.score = 1.0 - 1.0/(expweighted+1.0)
group_scores[vector_id] = 1.0 - 1.0/(expweighted+1.0)

result.detail = "vector_id=score: " + ", ".join([ "{}={}".format(k, i) for (k,i) in group_scores.items()])
result.score = max(group_scores.values())

self.session.commit()

return result



if __name__ == '__main__':

pass

12 changes: 1 addition & 11 deletions vector/internet.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,7 @@ def execute(self, expected_timedelta: timedelta):
.order_by(Test.datetime_to.desc())\
.limit(1).all()

if len(list(last)) :
last_datetime = last[0].datetime_to
if datetime_to - last_datetime < expected_timedelta * 2:
datetime_from = last_datetime
print("found previous run, referencing datetime_to")
else:
print("found previous run, datetime_to is too old")
else:
print("no previous run found, using expected_timedelta")

result = Test(name="internet test from %s to %s"%(datetime_from,datetime_to), vector=self.rv)
result = Test(name="internet test at %s"%(datetime_to.strftime('%Y-%m-%d %H:%M:%SZ')), vector=self.rv)
self.session.add(result)
self.session.commit()
# print(result)
Expand Down
2 changes: 1 addition & 1 deletion vector/thalos_mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def execute(self, expected_timedelta: timedelta):
datedirs = [ datedir.name for datedir in camdirs.iterdir() ]
if len(datedirs) > 0:
result.score -= 0.125
if now.astimezone(timezone.utc).strftime('%Y-%m-%d') in datedirs:
if now.astimezone(timezone.utc).strftime('%d-%m-%Y') in datedirs:
result.score -= 0.125
if result.score < 1.0:
result.score -= 0.5
Expand Down

0 comments on commit 4dc9ff3

Please sign in to comment.