Skip to content

Commit 63535fa

Browse files
tilt-engine and analysis-engine bug fix
1 parent 196f095 commit 63535fa

File tree

3 files changed

+76
-5
lines changed

3 files changed

+76
-5
lines changed

analysis/app/routers/analysis.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
# API-Analysis
1717
# <------------------------>
1818

19-
@router.on_event("startup")
20-
@repeat_every( seconds= 60 * 60 * 24 )
2119
@router.get("/update", responses=default_responses)
2220
async def analysis(user: User = Depends(authenticate)):
2321
if user["access_lvl"] != 0 and user["access_lvl"] != 1:
@@ -28,3 +26,10 @@ async def analysis(user: User = Depends(authenticate)):
2826
print("updated!")
2927

3028
return JSONResponse(status_code=200, content={"acknowledged": True})
29+
30+
@router.on_event("startup")
31+
@repeat_every( seconds= 60 * 60 * 24 )
32+
async def __analysis():
33+
print("updating...")
34+
update()
35+
print("updated!")

tests/risks_analysis.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import json
2+
3+
f = open('./dbseed/risks.json')
4+
5+
data = json.load(f)
6+
7+
hasSimilarNodes = 0
8+
numberSimilarNodes = 0
9+
10+
hasRisk = 0
11+
totalRisk = 0
12+
maxRisk = 0
13+
14+
totalBreached = []
15+
totalBreaches = 0
16+
17+
seenCluster = []
18+
validArticleRank = 0
19+
validBetweenness = 0
20+
validDegree = 0
21+
validHarmonicCloseness = 0
22+
23+
for d in data:
24+
if "similarNodes" in d and len(d["similarNodes"]) > 0:
25+
hasSimilarNodes += 1
26+
numberSimilarNodes += len(d["similarNodes"])
27+
else:
28+
print(d)
29+
if "riskScore" in d:
30+
hasRisk += 1
31+
totalRisk += d["riskScore"]
32+
if d["riskScore"] > maxRisk:
33+
maxRisk = d["riskScore"]
34+
if "similarBreachedDomains" in d:
35+
for breached in d["similarBreachedDomains"]:
36+
if breached["domain"] not in totalBreached:
37+
totalBreached.append(breached["domain"])
38+
totalBreaches += breached["breaches"]
39+
if "validMeasuresInCluster" in d:
40+
for c in d["validMeasuresInCluster"]:
41+
if c["cluster"] not in seenCluster:
42+
seenCluster.append(c["cluster"])
43+
if c["articleRank"]:
44+
validArticleRank += 1
45+
if c["betweenness"]:
46+
validBetweenness += 1
47+
if c["degree"]:
48+
validDegree += 1
49+
if c["harmonicCloseness"]:
50+
validHarmonicCloseness += 1
51+
52+
print(len(data))
53+
54+
print("Has similar nodes: ", hasSimilarNodes)
55+
print("Average amount of similar nodes: ", numberSimilarNodes/hasSimilarNodes)
56+
57+
print("Has risk: ", hasRisk)
58+
print("Average risk: ", totalRisk/hasRisk)
59+
print("maxRisk: ", maxRisk)
60+
61+
print("Total breached: ", len(totalBreached))
62+
print("Total breaches: ", totalBreaches)
63+
64+
print("Number of cluster: ", len(seenCluster))
65+
print("Number of valid ArticleRanks: ", validArticleRank)
66+
print("Number of valid Betweenness: ", validBetweenness)
67+
print("Number of valid Degree: ", validDegree)
68+
print("Number of valid Harmonic Closeness: ", validHarmonicCloseness)

tilt/app/routers/data.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
from fastapi import APIRouter, HTTPException, Depends, Request
22
from fastapi.responses import JSONResponse
3-
from pydantic import BaseModel
4-
from datetime import datetime
53

64
from .authentication import User, authenticate
7-
from ..database.data import insert_tilt, insert_tilts, delete_tilt, delete_tilts
5+
from ..database.data import insert_tilt, insert_tilts, delete_tilt
86
from ..database.models.http_responses import *
97

108

0 commit comments

Comments
 (0)