Commit eb98d613 authored by Kruyff,D.L.W. (Dylan)'s avatar Kruyff,D.L.W. (Dylan)
Browse files

Replaced http server with angular app + naive labeling

parent 34732969
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/app",
"types": []
},
"files": [
"src/main.ts",
"src/polyfills.ts"
],
"include": [
"src/**/*.d.ts"
]
}
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es5",
"lib": [
"es2018",
"dom"
]
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
}
}
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/spec",
"types": [
"jasmine",
"node"
]
},
"files": [
"src/test.ts",
"src/polyfills.ts"
],
"include": [
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}
{
"extends": "tslint:recommended",
"rules": {
"align": {
"options": [
"parameters",
"statements"
]
},
"array-type": false,
"arrow-return-shorthand": true,
"curly": true,
"deprecation": {
"severity": "warning"
},
"component-class-suffix": true,
"contextual-lifecycle": true,
"directive-class-suffix": true,
"directive-selector": [
true,
"attribute",
"app",
"camelCase"
],
"component-selector": [
true,
"element",
"app",
"kebab-case"
],
"eofline": true,
"import-blacklist": [
true,
"rxjs/Rx"
],
"import-spacing": true,
"indent": {
"options": [
"spaces"
]
},
"max-classes-per-file": false,
"max-line-length": [
true,
140
],
"member-ordering": [
true,
{
"order": [
"static-field",
"instance-field",
"static-method",
"instance-method"
]
}
],
"no-console": [
true,
"debug",
"info",
"time",
"timeEnd",
"trace"
],
"no-empty": false,
"no-inferrable-types": [
true,
"ignore-params"
],
"no-non-null-assertion": true,
"no-redundant-jsdoc": true,
"no-switch-case-fall-through": true,
"no-var-requires": false,
"object-literal-key-quotes": [
true,
"as-needed"
],
"quotemark": [
true,
"single"
],
"semicolon": {
"options": [
"always"
]
},
"space-before-function-paren": {
"options": {
"anonymous": "never",
"asyncArrow": "always",
"constructor": "never",
"method": "never",
"named": "never"
}
},
"typedef-whitespace": {
"options": [
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
},
{
"call-signature": "onespace",
"index-signature": "onespace",
"parameter": "onespace",
"property-declaration": "onespace",
"variable-declaration": "onespace"
}
]
},
"variable-name": {
"options": [
"ban-keywords",
"check-format",
"allow-pascal-case"
]
},
"whitespace": {
"options": [
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type",
"check-typecast"
]
},
"no-conflicting-lifecycle": true,
"no-host-metadata-property": true,
"no-input-rename": true,
"no-inputs-metadata-property": true,
"no-output-native": true,
"no-output-on-prefix": true,
"no-output-rename": true,
"no-outputs-metadata-property": true,
"template-banana-in-box": true,
"template-no-negated-async": true,
"use-lifecycle-interface": true,
"use-pipe-transform-interface": true
},
"rulesDirectory": [
"codelyzer"
]
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="Flask">
<option name="enabled" value="true" />
</component>
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TemplatesService">
<option name="TEMPLATE_CONFIGURATION" value="Jinja2" />
<option name="TEMPLATE_FOLDERS">
<list>
<option value="$MODULE_DIR$/venv/Lib/site-packages/pandas/io/formats/templates" />
</list>
</option>
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (Flaskserver)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Flaskserver.iml" filepath="$PROJECT_DIR$/.idea/Flaskserver.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="556080ba-825c-4b55-a92a-867a4df4fb32" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../Webserver/index.html" beforeDir="false" afterPath="$PROJECT_DIR$/../Webserver/index.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../Webserver/index.js" beforeDir="false" afterPath="$PROJECT_DIR$/../Webserver/index.js" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/main.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-1300">
<caret line="53" column="25" lean-forward="true" selection-start-line="53" selection-start-column="25" selection-end-line="53" selection-end-column="25" />
<folding>
<element signature="e#0#41#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/main.py" />
</list>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="12" />
<option name="y" value="-36" />
<option name="width" value="1890" />
<option name="height" value="960" />
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="Flaskserver" type="b2602c69:ProjectViewProjectNode" />
<item name="Flaskserver" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="Scope" />
</panes>
</component>
<component name="PropertiesComponent">
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="RunManager">
<configuration name="Flaskserver" type="Python.FlaskServer">
<module name="Flaskserver" />
<option name="target" value="$PROJECT_DIR$/main.py" />
<option name="targetType" value="PATH" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="launchJavascriptDebuger" value="false" />
<method v="2" />
</configuration>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="556080ba-825c-4b55-a92a-867a4df4fb32" name="Default Changelist" comment="" />
<created>1594051522057</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1594051522057</updated>
<workItem from="1594051526942" duration="608000" />
<workItem from="1594152452853" duration="1968000" />
<workItem from="1594223646564" duration="1330000" />
<workItem from="1594494759659" duration="1411000" />
<workItem from="1594589515579" duration="1044000" />
<workItem from="1594719112139" duration="9023000" />
</task>
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="15384000" />
</component>
<component name="ToolWindowManager">
<frame x="-7" y="-7" width="1295" height="695" extended-state="7" />
<editor active="true" />
<layout>
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.26273242" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="bottom" id="Docker" order="7" show_stripe_button="false" />
<window_info anchor="bottom" id="Version Control" order="8" />
<window_info anchor="bottom" id="Database Changes" order="9" />
<window_info anchor="bottom" id="Event Log" order="10" side_tool="true" />
<window_info anchor="bottom" id="Terminal" order="11" />
<window_info anchor="bottom" id="Python Console" order="12" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
<window_info anchor="right" id="SciView" order="3" />
<window_info anchor="right" id="Database" order="4" />
</layout>
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/main.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-1300">
<caret line="53" column="25" lean-forward="true" selection-start-line="53" selection-start-column="25" selection-end-line="53" selection-end-column="25" />
<folding>
<element signature="e#0#41#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</component>
</project>
\ No newline at end of file
...@@ -3,7 +3,7 @@ import matplotlib.pyplot as plt ...@@ -3,7 +3,7 @@ import matplotlib.pyplot as plt
import pandas as pd import pandas as pd
import numpy as np import numpy as np
from flask_cors import CORS from flask_cors import CORS
from collections import defaultdict from collections import defaultdict, Counter
from time import time from time import time
app = Flask(__name__) app = Flask(__name__)
...@@ -31,7 +31,7 @@ def read_data(): ...@@ -31,7 +31,7 @@ def read_data():
def create_windows(): def create_windows():
raw_data = request.json raw_data = request.json
values = raw_data["values"] values = raw_data["values"]
window_size = int(raw_data["windowsize"]) window_size = int(raw_data['parameters']["windowsize"])
data = [] data = []
for index in range(len(values) - window_size): for index in range(len(values) - window_size):
window = values[index:index + window_size] window = values[index:index + window_size]
...@@ -48,9 +48,9 @@ def create_tables(): ...@@ -48,9 +48,9 @@ def create_tables():
t0 = time() t0 = time()
raw_data = request.json raw_data = request.json
data = raw_data["windows"] data = raw_data["windows"]
window_size = int(raw_data["windowsize"]) window_size = int(raw_data['parameters']["windowsize"])
hash_size = int(raw_data["hashsize"]) hash_size = int(raw_data['parameters']["hashsize"])
table_size = int(raw_data["tablesize"]) table_size = int(raw_data['parameters']["tablesize"])
data = np.array(data) data = np.array(data)
tables = [defaultdict(list) for _ in range(table_size)] tables = [defaultdict(list) for _ in range(table_size)]
tables_hash_function = [np.random.randn(window_size, hash_size) for _ in range(table_size)] tables_hash_function = [np.random.randn(window_size, hash_size) for _ in range(table_size)]
...@@ -62,11 +62,14 @@ def create_tables(): ...@@ -62,11 +62,14 @@ def create_tables():
signature = (np.dot(data[window_index], hash_function) > 0).astype('int') signature = (np.dot(data[window_index], hash_function) > 0).astype('int')
table[str(signature)].append(window_index) table[str(signature)].append(window_index)
print(time() - t0) print('Creation time: ' + str(time() - t0))
response = { hash_functions = np.array(tables_hash_function).tolist()
"hash_functions": np.array(tables_hash_function).tolist(), response = {}
"tables": tables for table_index in range(table_size):
} response[table_index] = {
"hash": hash_functions[table_index],
"entries": tables[table_index]
}
response = jsonify(response) response = jsonify(response)
return response return response
...@@ -75,16 +78,77 @@ def query(): ...@@ -75,16 +78,77 @@ def query():
raw_data = request.json raw_data = request.json
window = raw_data["window"] window = raw_data["window"]
tables = raw_data["tables"] tables = raw_data["tables"]
hash_functions = raw_data["hash_functions"]
neighbours = [] neighbours = []
for t in range(len(tables)): output = {}
table = tables[t]
hash_function = hash_functions[t] for t in tables.values():
row = window signature = (np.dot(window, t["hash"]) > 0).astype('int')
signature = (np.dot(row, hash_function) > 0).astype('int') neighbours.extend(t["entries"][str(signature)])
neighbours.append(table[str(signature)]) neighbours_with_frequency = dict(Counter(neighbours))
neighbours = list(set.intersection(*map(set, neighbours))) for index, frequency in neighbours_with_frequency.items():
if not frequency in output:
output[frequency] = []
output[frequency].append(index)
response = jsonify(output)
return response
@app.route('/update', methods=['POST'])
def update():
t0 = time()
raw_data = request.json
response = jsonify(neighbours) data = raw_data["windows"]
data = np.array(data)
label_data = raw_data["labelData"]
tables = raw_data["tables"]
window_size = int(raw_data['parameters']["windowsize"])
hash_size = int(raw_data['parameters']["hashsize"])
table_size = int(raw_data['parameters']["tablesize"])
new_tables = []
correct_indices = [index for index, value in enumerate(label_data) if value is True]
incorrect_indices = [index for index, value in enumerate(label_data) if value is False]
window = data[correct_indices[0]]
for t in tables.values():
valid = True
signature = (np.dot(window, t["hash"]) > 0).astype('int')
neighbours = t["entries"][str(signature)]
for index in correct_indices:
if index not in neighbours:
valid = False
break
for index in incorrect_indices:
if index in neighbours:
valid = False
break
if valid:
new_tables.append(t)
for i in range(table_size - len(new_tables)):
entries = defaultdict(list)
while True:
hash_function = np.random.randn(window_size, hash_size)
correct_signatures = [str((np.dot(data[index], hash_function) > 0).astype('int')) for index in correct_indices]
incorrect_signatures = [str((np.dot(data[index], hash_function) > 0).astype('int')) for index in incorrect_indices]
if correct_signatures.count(correct_signatures[0]) == len(correct_signatures) and incorrect_signatures.count(correct_signatures[0]) == 0:
break
for window_index in range(data.shape[0]):
signature = (np.dot(data[window_index], hash_function) > 0).astype('int')
entries[str(signature)].append(window_index)
new_tables.append({
"hash": hash_function.tolist(),
"entries": entries
})
print('Update time: ' + str(time() - t0))
response = {}
for table_index in range(len(new_tables)):
response[table_index] = {
"hash": new_tables[table_index]["hash"],
"entries": new_tables[table_index]["entries"]
}
response = jsonify(response)
return response return response
\ No newline at end of file
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
<label for="windowsize">Window Size:</label><br> <label for="windowsize">Window Size:</label><br>
<input type="text" id="windowsize" name="windowsize" value="20"><br> <input type="text" id="windowsize" name="windowsize" value="20"><br>
<label for="tablesize">Table Size:</label><br> <label for="tablesize">Table Size:</label><br>
<input type="text" id="tablesize" name="tablesize" value="10"><br> <input type="text" id="tablesize" name="tablesize" value="20"><br>
<label for="hashsize">Hash Size:</label><br> <label for="hashsize">Hash Size:</label><br>
<input type="text" id="hashsize" name="hashsize" value="10"><br> <input type="text" id="hashsize" name="hashsize" value="10"><br>
</form> </form>
......
...@@ -4,6 +4,7 @@ const FORM = document.getElementById('parameters'); ...@@ -4,6 +4,7 @@ const FORM = document.getElementById('parameters');
var default_colors = []; var default_colors = [];
var default_sizes = []; var default_sizes = [];