Skip to content

Commit

Permalink
extra revampings and organization
Browse files Browse the repository at this point in the history
  • Loading branch information
kauevestena committed Oct 17, 2024
1 parent 299c622 commit 557e239
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 40 deletions.
52 changes: 45 additions & 7 deletions dashboard/statistics_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
now = datetime.now()
dt_string = now.strftime("%d/%m/%Y %H:%M:%S")

default_color = alt.value("lightseagreen")


def get_count_df(
input_df,
Expand Down Expand Up @@ -156,7 +158,7 @@ def get_year_surveydate(featuredate):
return featuredate.split("-")[0]


def create_double_scatter_bar(
def create_double_mat_and_bar(
input_df,
title,
xs="surface",
Expand Down Expand Up @@ -209,8 +211,6 @@ def create_double_scatter_bar(

interval = alt.selection_interval()

default_color = alt.value("lightseagreen")

if not hcolor:
hcolor = default_color

Expand All @@ -220,6 +220,7 @@ def create_double_scatter_bar(
scatter = (
alt.Chart(input_df, title=title)
.mark_point()
# .mark_rect() # MAYBE? TODO: how to make it have a different color than the histogram
.encode(
x=xs,
y=ys,
Expand All @@ -228,7 +229,7 @@ def create_double_scatter_bar(
)
.properties(
width=600,
height=350,
# height=350,
)
.add_params(interval)
)
Expand All @@ -237,7 +238,7 @@ def create_double_scatter_bar(
alt.Chart(input_df)
.mark_bar()
.encode(
x=xh,
x=alt.X(xh, title=xh.replace("()", "").title() + " (selection)"),
color=hcolor,
tooltip=alt.Tooltip(["count()"], title="count:"),
)
Expand Down Expand Up @@ -266,9 +267,15 @@ def create_double_scatter_bar(
encoding_h2["y"] = yh2

# define the histograms
hist = hist_base.encode(**encoding_h1) | hist_base.encode(**encoding_h2)
# hist = hist_base.encode(**encoding_h1) | hist_base.encode(**encoding_h2)
hist = alt.hconcat(
hist_base.encode(**encoding_h1),
hist_base.encode(**encoding_h2),
# title="selection",
)

return (scatter & hist).configure_title(fontSize=fontsize, align="center")
# return (scatter & hist).configure_title(fontSize=fontsize, align="center")
return alt.vconcat(scatter, hist).configure_title(fontSize=fontsize, align="center")


def create_linked_boxplot_histogram(
Expand Down Expand Up @@ -381,3 +388,34 @@ def create_rev_date(row):
return datetime(
default_missing_year, default_missing_month, default_missing_day
)


global_insertions = {
"<head>": """
<head>
<link rel="stylesheet" href="https://kauevestena.github.io/oswm_codebase/assets/styles/stats_styles.css">
<script src="https://kauevestena.github.io/oswm_codebase/assets/webscripts/stats_funcs.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<title>OSWM Dashboard</title>
<link rel="icon" type="image/x-icon" href="https://kauevestena.github.io/oswm_codebase/assets/homepage/favicon_homepage.png">
""",
}

global_exclusions = [{"points": ["<style>", "</style>"], "multiline": True}]


# it needs to be here rather than in the main script:
gdfs_dict = get_gdfs_dict()
updating_dicts = {}
for category in paths_dict["data"]:

if os.path.exists(paths_dict["versioning"].get(category)):
updating_dicts[category] = pd.read_json(versioning_dict[category])
else:
updating_dicts[category] = pd.DataFrame()
37 changes: 4 additions & 33 deletions dashboard/statistics_specs.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
from statistics_funcs import *

gdfs_dict = get_gdfs_dict()
updating_dicts = {}


for category in paths_dict["data"]:

if os.path.exists(paths_dict["versioning"].get(category)):
updating_dicts[category] = pd.read_json(versioning_dict[category])
else:
updating_dicts[category] = pd.DataFrame()


charts_specs = {
"sidewalks": {
"sidewalks_smoothness_x_surface": {
"function": create_double_scatter_bar,
"function": create_double_mat_and_bar,
"params": {
"input_df": gdfs_dict["sidewalks"],
"title": "Surface x Smoothness (sidewalks)",
Expand Down Expand Up @@ -170,7 +158,7 @@
"title": "Surface Type",
},
"crossings_smoothness_x_surface": {
"function": create_double_scatter_bar,
"function": create_double_mat_and_bar,
"params": {
"input_df": gdfs_dict["crossings"],
"title": "Surface x Smoothness (crossings)",
Expand Down Expand Up @@ -224,7 +212,7 @@
},
"kerbs": {
"kerbs_x_paving_x_wheelchair": {
"function": create_double_scatter_bar,
"function": create_double_mat_and_bar,
"params": {
"input_df": gdfs_dict["kerbs"],
"title": "Kerb x Tactile Paving x Wheelchair Acess.",
Expand Down Expand Up @@ -341,7 +329,7 @@
# "title": "Other Footways Surface",
# },
"other_footways_smoothness_x_surface": {
"function": create_double_scatter_bar,
"function": create_double_mat_and_bar,
"params": {
"input_df": gdfs_dict["other_footways"],
"title": "Surface x Smoothness (other_footways)",
Expand Down Expand Up @@ -434,20 +422,3 @@
},
},
}

global_insertions = {
"<head>": """
<head>
<link rel="stylesheet" href="https://kauevestena.github.io/oswm_codebase/assets/styles/stats_styles.css">
<script src="https://kauevestena.github.io/oswm_codebase/assets/webscripts/stats_funcs.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<title>OSWM Dashboard</title>
""",
}

global_exclusions = [{"points": ["<style>", "</style>"], "multiline": True}]

0 comments on commit 557e239

Please sign in to comment.