feat: gui layout + basic func

This commit is contained in:
AGawde05 2021-04-01 02:21:01 -05:00
parent b214e2f797
commit 29d4002dc0
4 changed files with 199 additions and 92 deletions

View File

@ -1,46 +1,101 @@
{ {
"max-threads": 0.5, "max-threads": 0.5,
"team": "", "team": "",
"competition": "", "competition": "2020ilch",
"key":{ "key": {
"database":"", "database": "mongodb+srv://analysis:MU2gPeEjEurRt2n@2022-scouting-4vfuu.mongodb.net/<dbname>?retryWrites=true&w=majority",
"tba":"" "tba": "UDvKmPjPRfwwUdDX1JxbmkyecYBJhCtXeyVk9vmO2i7K0Zn4wqQPMfzuEINXJ7e5"
}, },
"statistics":{ "statistics": {
"match":{ "match": {
"balls-blocked":["basic_stats","historical_analysis","regression_linear","regression_logarithmic","regression_exponential","regression_polynomial","regression_sigmoidal"], "balls-blocked": [
"balls-collected":["basic_stats","historical_analysis","regression_linear","regression_logarithmic","regression_exponential","regression_polynomial","regression_sigmoidal"], "basic_stats",
"balls-lower-teleop":["basic_stats","historical_analysis","regression_linear","regression_logarithmic","regression_exponential","regression_polynomial","regression_sigmoidal"], "historical_analysis",
"balls-lower-auto":["basic_stats","historical_analysis","regression_linear","regression_logarithmic","regression_exponential","regression_polynomial","regression_sigmoidal"], "regression_linear",
"balls-started":["basic_stats","historical_analyss","regression_linear","regression_logarithmic","regression_exponential","regression_polynomial","regression_sigmoidal"], "regression_logarithmic",
"balls-upper-teleop":["basic_stats","historical_analysis","regression_linear","regression_logarithmic","regression_exponential","regression_polynomial","regression_sigmoidal"], "regression_exponential",
"balls-upper-auto":["basic_stats","historical_analysis","regression_linear","regression_logarithmic","regression_exponential","regression_polynomial","regression_sigmoidal"] "regression_polynomial",
"regression_sigmoidal"
],
"balls-collected": [
"basic_stats",
"historical_analysis",
"regression_linear",
"regression_logarithmic",
"regression_exponential",
"regression_polynomial",
"regression_sigmoidal"
],
"balls-lower-teleop": [
"basic_stats",
"historical_analysis",
"regression_linear",
"regression_logarithmic",
"regression_exponential",
"regression_polynomial",
"regression_sigmoidal"
],
"balls-lower-auto": [
"basic_stats",
"historical_analysis",
"regression_linear",
"regression_logarithmic",
"regression_exponential",
"regression_polynomial",
"regression_sigmoidal"
],
"balls-started": [
"basic_stats",
"historical_analyss",
"regression_linear",
"regression_logarithmic",
"regression_exponential",
"regression_polynomial",
"regression_sigmoidal"
],
"balls-upper-teleop": [
"basic_stats",
"historical_analysis",
"regression_linear",
"regression_logarithmic",
"regression_exponential",
"regression_polynomial",
"regression_sigmoidal"
],
"balls-upper-auto": [
"basic_stats",
"historical_analysis",
"regression_linear",
"regression_logarithmic",
"regression_exponential",
"regression_polynomial",
"regression_sigmoidal"
]
}, },
"metric":{ "metric": {
"elo":{ "elo": {
"score":1500, "score": 1500,
"N":400, "N": 400,
"K":24 "K": 24
}, },
"gl2":{ "gl2": {
"score":1500, "score": 1500,
"rd":250, "rd": 250,
"vol":0.06 "vol": 0.06
}, },
"ts":{ "ts": {
"mu":25, "mu": 25,
"sigma":8.33 "sigma": 8.33
} }
}, },
"pit":{ "pit": {
"wheel-mechanism":true, "wheel-mechanism": true,
"low-balls":true, "low-balls": true,
"high-balls":true, "high-balls": true,
"wheel-success":true, "wheel-success": true,
"strategic-focus":true, "strategic-focus": true,
"climb-mechanism":true, "climb-mechanism": true,
"attitude":true "attitude": true
} }
} }
} }

View File

@ -1,4 +1,4 @@
BoxLayout: <Launch>:
orientation: "vertical" orientation: "vertical"
NavigationLayout: NavigationLayout:
@ -51,6 +51,7 @@ BoxLayout:
MDTextField: MDTextField:
hint_text: "placeholder" hint_text: "placeholder"
pos_hint: {"center_y": .5} pos_hint: {"center_y": .5}
BoxLayout: BoxLayout:
orientation: "horizontal" orientation: "horizontal"
MDLabel: MDLabel:
@ -84,9 +85,15 @@ BoxLayout:
MDProgressBar: MDProgressBar:
id: progress id: progress
value: 50 value: 50
StatsScreen:
name: "Stats"
MDCheckbox:
size_hint: None, None
size: "48dp", "48dp"
pos_hint: {'center_x': .5, 'center_y': .5}
on_active: Screen.test()
#Navigation Drawer -------------------------
MDNavigationDrawer: MDNavigationDrawer:
id: nav_drawer id: nav_drawer
BoxLayout: BoxLayout:
@ -133,3 +140,12 @@ BoxLayout:
screen_manager.current = "Info" screen_manager.current = "Info"
IconLeftWidget: IconLeftWidget:
icon: "cog" icon: "cog"
OneLineAvatarListItem:
text: "Stats"
on_press:
# nav_drawer.set_state("close")
# screen_manager.transition.direction = "right"
# screen_manager.fade
screen_manager.current = "Stats"
IconLeftWidget:
icon: "cog"

38
main.py
View File

@ -1,9 +1,40 @@
from kivy.lang import Builder from kivy.lang import Builder
from kivymd.uix.screen import Screen
from kivymd.uix.list import OneLineListItem, MDList, TwoLineListItem, ThreeLineListItem
from kivymd.uix.list import OneLineIconListItem, IconLeftWidget
from kivy.uix.scrollview import ScrollView
from kivy.uix.boxlayout import BoxLayout from kivy.uix.boxlayout import BoxLayout
from kivy.uix.screenmanager import ScreenManager, Screen from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.dropdown import DropDown
from kivy.uix.button import Button
from kivy.base import runTouchApp
from kivymd.uix.menu import MDDropdownMenu, MDMenuItem
from kivymd.app import MDApp from kivymd.app import MDApp
# import superscript as ss # import superscript as ss
# from tra_analysis import analysis as an
import data as d
from collections import defaultdict
import json
import math
import numpy as np
import os
from os import system, name
from pathlib import Path
from multiprocessing import Pool
import matplotlib.pyplot as plt
from concurrent.futures import ThreadPoolExecutor
import time
import warnings
# global exec_threads
# Screens
class HomeScreen(Screen): class HomeScreen(Screen):
pass pass
class SettingsScreen(Screen): class SettingsScreen(Screen):
@ -11,11 +42,16 @@ class SettingsScreen(Screen):
class InfoScreen(Screen): class InfoScreen(Screen):
pass pass
class StatsScreen(Screen):
pass
class MyApp(MDApp): class MyApp(MDApp):
def build(self): def build(self):
self.theme_cls.primary_palette = "Red" self.theme_cls.primary_palette = "Red"
return Builder.load_file("design.kv") return Builder.load_file("design.kv")
def test():
print("test")
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -135,75 +135,75 @@ from concurrent.futures import ThreadPoolExecutor
import time import time
import warnings import warnings
global exec_threads # global exec_threads
def main(): def main():
global exec_threads # global exec_threads
warnings.filterwarnings("ignore") warnings.filterwarnings("ignore")
while (True): # while (True):
current_time = time.time() current_time = time.time()
print("[OK] time: " + str(current_time)) print("[OK] time: " + str(current_time))
config = load_config("data-analysis/config.json") config = load_config("red-alliance-analysis\data-analysis\config.json")
competition = config["competition"] competition = config["competition"]
match_tests = config["statistics"]["match"] match_tests = config["statistics"]["match"]
pit_tests = config["statistics"]["pit"] pit_tests = config["statistics"]["pit"]
metrics_tests = config["statistics"]["metric"] metrics_tests = config["statistics"]["metric"]
print("[OK] configs loaded") print("[OK] configs loaded")
print("[OK] starting threads") print("[OK] starting threads")
cfg_max_threads = config["max-threads"] cfg_max_threads = config["max-threads"]
sys_max_threads = os.cpu_count() sys_max_threads = os.cpu_count()
if cfg_max_threads > -sys_max_threads and cfg_max_threads < 0 : if cfg_max_threads > -sys_max_threads and cfg_max_threads < 0 :
alloc_processes = sys_max_threads + cfg_max_threads alloc_processes = sys_max_threads + cfg_max_threads
elif cfg_max_threads > 0 and cfg_max_threads < 1: elif cfg_max_threads > 0 and cfg_max_threads < 1:
alloc_processes = math.floor(cfg_max_threads * sys_max_threads) alloc_processes = math.floor(cfg_max_threads * sys_max_threads)
elif cfg_max_threads > 1 and cfg_max_threads <= sys_max_threads: elif cfg_max_threads > 1 and cfg_max_threads <= sys_max_threads:
alloc_processes = cfg_max_threads alloc_processes = cfg_max_threads
elif cfg_max_threads == 0: elif cfg_max_threads == 0:
alloc_processes = sys_max_threads alloc_processes = sys_max_threads
else: else:
print("[Err] Invalid number of processes, must be between -" + str(sys_max_threads) + " and " + str(sys_max_threads)) print("[Err] Invalid number of processes, must be between -" + str(sys_max_threads) + " and " + str(sys_max_threads))
exit() exit()
exec_threads = Pool(processes = alloc_processes) # exec_threads = Pool(processes = alloc_processes)
print("[OK] " + str(alloc_processes) + " threads started") # print("[OK] " + str(alloc_processes) + " threads started")
apikey = config["key"]["database"] apikey = config["key"]["database"]
tbakey = config["key"]["tba"] tbakey = config["key"]["tba"]
print("[OK] loaded keys") print("[OK] loaded keys")
previous_time = get_previous_time(apikey) previous_time = get_previous_time(apikey)
print("[OK] analysis backtimed to: " + str(previous_time)) print("[OK] analysis backtimed to: " + str(previous_time))
print("[OK] loading data") print("[OK] loading data")
start = time.time() start = time.time()
match_data = load_match(apikey, competition) match_data = load_match(apikey, competition)
pit_data = load_pit(apikey, competition) pit_data = load_pit(apikey, competition)
print("[OK] loaded data in " + str(time.time() - start) + " seconds") print("[OK] loaded data in " + str(time.time() - start) + " seconds")
print("[OK] running match stats") print("[OK] running match stats")
start = time.time() start = time.time()
matchloop(apikey, competition, match_data, match_tests) matchloop(apikey, competition, match_data, match_tests)
print("[OK] finished match stats in " + str(time.time() - start) + " seconds") print("[OK] finished match stats in " + str(time.time() - start) + " seconds")
print("[OK] running team metrics") print("[OK] running team metrics")
start = time.time() start = time.time()
metricloop(tbakey, apikey, competition, previous_time, metrics_tests) metricloop(tbakey, apikey, competition, previous_time, metrics_tests)
print("[OK] finished team metrics in " + str(time.time() - start) + " seconds") print("[OK] finished team metrics in " + str(time.time() - start) + " seconds")
print("[OK] running pit analysis") print("[OK] running pit analysis")
start = time.time() start = time.time()
pitloop(apikey, competition, pit_data, pit_tests) pitloop(apikey, competition, pit_data, pit_tests)
print("[OK] finished pit analysis in " + str(time.time() - start) + " seconds") print("[OK] finished pit analysis in " + str(time.time() - start) + " seconds")
set_current_time(apikey, current_time) set_current_time(apikey, current_time)
print("[OK] finished all tests, looping") print("[OK] finished all tests, looping")
clear() # clear()
def clear(): def clear():
@ -314,7 +314,7 @@ def matchloop(apikey, competition, data, tests): # expects 3D array with [Team][
variable_data.append((data[team][variable], test)) variable_data.append((data[team][variable], test))
test_filtered.append(test) test_filtered.append(test)
result_filtered = exec_threads.map(simplestats, variable_data) result_filtered = map(simplestats, variable_data)
i = 0 i = 0
result_filtered = list(result_filtered) result_filtered = list(result_filtered)