Skip to content

Commit

Permalink
feat: Input files parsed in browser of user (#141)
Browse files Browse the repository at this point in the history
* removed file import, parsing in browser now. Not working yet

* fixed parsing comment

* default uncertainty

* added handling of file separators and improved form responsiveness

* disallow form submission if no data is loaded

* parsing old session data in browser now

* updated readme

* adjusted tests for new file import

* small clarifications
  • Loading branch information
tobiasmllr authored May 16, 2024
1 parent dc53c08 commit f95e1ca
Show file tree
Hide file tree
Showing 8 changed files with 624 additions and 334 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The HydRA app is hosted in the BC Gov GitHub organization and is available at PL

## Managing the app packages

After cloning the repository, use the `poetry` python package manager to install the dependencies by running `poetry install` from the `frontend` directory. To update the dependencies, run `poetry update` or editate the `pyproject.toml` file.
After cloning the repository, use the `poetry` python package manager to install the dependencies by running `poetry install` from the `frontend` directory. To update the dependencies, run `poetry update` or edit the `pyproject.toml` file. To export the dependencies to a `requirements.txt` file for the docker image, run `poetry export -f requirements.txt --output requirements.txt`.

## Running the app locally

Expand Down
2 changes: 1 addition & 1 deletion frontend/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ events {
}
http {
include mime.types;
# allow csv files and pdf files to be served
# allow csv files. Seems to also allow .dat files
types {
text/csv csv;
}
Expand Down
181 changes: 157 additions & 24 deletions frontend/rctool/forms.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,173 @@
from django import forms
from django.core import validators


class DatePickerInput(forms.DateInput):
input_type = 'date'
input_type = "date"


class import_rc_data(forms.Form):
# csv_upload = forms.FileField(label="csv file", widget=forms.FileInput(attrs={'class': 'form-control form-control-sm'}))
csv_upload = forms.FileField(label="csv file", widget=forms.FileInput(attrs={'class': 'form-control form-control-sm', 'style': 'font-size: 11.5px;'}))
header_row = forms.IntegerField(label="header row number", widget=forms.NumberInput(attrs={'class': 'form-control form-control-sm', 'min':1, 'value':1, 'id':'form-header-row', 'style': 'font-size: 11.5px;'}))
csv_upload.required = False
header_row.required = False
input_session_type = forms.ChoiceField(
label="import type",
widget=forms.Select(
attrs={
"class": "form-control form-control-sm",
"style": "font-size: 11.5px;",
}
),
choices=[
("new", "new session"),
("load", "load previous session"),
],
)

csv_content = forms.CharField(
label="csv content",
widget=forms.Textarea(
attrs={
"class": "form-control form-control-sm",
"style": "font-size: 11.5px; height: 200px;",
}
),
required=False,
)

session_content = forms.CharField(
label="session content",
widget=forms.Textarea(
attrs={
"class": "form-control form-control-sm",
"style": "font-size: 11.5px; height: 200px;",
}
),
required=False,
)

csv_separator = forms.ChoiceField(
label="separator",
widget=forms.Select(
attrs={
"class": "form-control form-control-sm",
"style": "font-size: 11.5px;",
}
),
choices=[
(",", "comma"),
(";", "semicolon"),
("\t", "tab"),
],
)

header_row = forms.IntegerField(
label="header row number",
widget=forms.NumberInput(
attrs={
"class": "form-control form-control-sm",
"min": 1,
"value": 1,
"id": "form-header-row",
"style": "font-size: 11.5px;",
}
),
)


class develop_rc(forms.Form):
set_offset1 = forms.FloatField(label="offset 1", widget=forms.NumberInput(attrs={'class': 'form-control form-control-sm', 'id':'offset1', 'style': 'font-size: 11.5px;'}))
set_offset2 = forms.FloatField(label="offset 2", widget=forms.NumberInput(attrs={'class': 'form-control form-control-sm', 'id':'offset2', 'style': 'font-size: 11.5px;'}))
set_breakpoint1 = forms.IntegerField(label="number of breakpoints", widget=forms.NumberInput(attrs={'class form-control-sm': 'form-control','id':'breakpoint1', 'value':1, 'style': 'font-size: 11.5px;'}))
set_breakpoint2 = forms.IntegerField(label="number of breakpoints", widget=forms.NumberInput(attrs={'class form-control-sm': 'form-control', 'id':'breakpoint2', 'value':1, 'style': 'font-size: 11.5px;'}))
set_offset1 = forms.FloatField(
label="offset 1",
widget=forms.NumberInput(
attrs={
"class": "form-control form-control-sm",
"id": "offset1",
"style": "font-size: 11.5px;",
}
),
)
set_offset2 = forms.FloatField(
label="offset 2",
widget=forms.NumberInput(
attrs={
"class": "form-control form-control-sm",
"id": "offset2",
"style": "font-size: 11.5px;",
}
),
)
set_breakpoint1 = forms.IntegerField(
label="number of breakpoints",
widget=forms.NumberInput(
attrs={
"class form-control-sm": "form-control",
"id": "breakpoint1",
"value": 1,
"style": "font-size: 11.5px;",
}
),
)
set_breakpoint2 = forms.IntegerField(
label="number of breakpoints",
widget=forms.NumberInput(
attrs={
"class form-control-sm": "form-control",
"id": "breakpoint2",
"value": 1,
"style": "font-size: 11.5px;",
}
),
)


class export_rc_data(forms.Form):
export_filetype = forms.ChoiceField(label='export type', widget=forms.Select(attrs={'class': 'form-control form-control-sm', 'style': 'font-size: 11.5px;'}), choices=[('session settings', 'session settings'), ('session results (pdf)', 'session results (pdf)'), ('session results (csv)', 'session results (csv)')])
export_filetype.widget.attrs['onchange'] = 'toggleExportForm(this.value)'
export_filename = forms.CharField(label="file name", widget=forms.TextInput(attrs={'class': 'form-control form-control-sm', 'style': 'font-size: 11.5px;' }), max_length=200)
export_station_name = forms.CharField(label="station name", widget=forms.TextInput(attrs={'class': 'form-control form-control-sm', 'style': 'font-size: 11.5px;'}), max_length=200)
export_filetype = forms.ChoiceField(
label="export type",
widget=forms.Select(
attrs={
"class": "form-control form-control-sm",
"style": "font-size: 11.5px;",
}
),
choices=[
("session settings", "session settings"),
("session results (pdf)", "session results (pdf)"),
("session results (csv)", "session results (csv)"),
],
)
export_filetype.widget.attrs["onchange"] = "toggleExportForm(this.value)"
export_filename = forms.CharField(
label="file name",
widget=forms.TextInput(
attrs={
"class": "form-control form-control-sm",
"style": "font-size: 11.5px;",
}
),
max_length=200,
)
export_station_name = forms.CharField(
label="station name",
widget=forms.TextInput(
attrs={
"class": "form-control form-control-sm",
"style": "font-size: 11.5px;",
}
),
max_length=200,
)
export_station_name.required = False
export_comments = forms.CharField(label="comments", widget=forms.Textarea(attrs={'class': 'form-control form-control-sm', 'style': 'font-size: 11.5px; height:60px;'}), max_length=1000)
export_comments = forms.CharField(
label="comments",
widget=forms.Textarea(
attrs={
"class": "form-control form-control-sm",
"style": "font-size: 11.5px; height:60px;",
}
),
max_length=1000,
)
export_comments.required = False
export_date_applic_init = forms.DateField(widget=DatePickerInput)
export_date_applic_init.widget.attrs['class'] = 'form-control form-control-sm'
export_date_applic_init.widget.attrs["class"] = "form-control form-control-sm"
export_date_applic_init.required = False
export_date_applic_final = forms.DateField(widget=DatePickerInput)
export_date_applic_final.widget.attrs['class'] = 'form-control form-control-sm'
export_date_applic_final.widget.attrs["class"] = "form-control form-control-sm"
export_date_applic_final.required = False







1 change: 1 addition & 0 deletions frontend/rctool/functions/fit_linear_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def fit_linear_model(df, offset, label, weighted=None, intersect_points=None, *a
df_data["U"] = df_data["U"].apply(lambda x: x / 100.0)
# set weights as 1 - % unc
df_data["W"] = df_data["U"].apply(lambda x: 1 - x)

# try weighting
result = plm.fit(df_data["Q"], params, x=df_data["H0"], weights=df_data["W"])
wgt_const = result.best_values["amplitude"]
Expand Down
Loading

0 comments on commit f95e1ca

Please sign in to comment.