Skip to content

Commit

Permalink
General refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
matejak committed Jun 4, 2024
1 parent 3246752 commit f6c97f9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
4 changes: 0 additions & 4 deletions estimage/persistence/event/ini.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ def _event_to_string_dict(self, event):
task_name=event.task_name
)
if (val := event.value_before) is not None:
if event.quantity == "state":
val = val
to_save["value_before"] = str(val)
if (val := event.value_after) is not None:
if event.quantity == "state":
val = val
to_save["value_after"] = str(val)

return to_save
Expand Down
29 changes: 13 additions & 16 deletions estimage/statops/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,8 @@ def get_time_to_completion(velocity_mean, velocity_stdev, distance, confidence=0


def get_prob_of_completion(velocity_mean, velocity_stdev, distance, time):
if distance == 0:
return 1
if velocity_stdev == 0:
return 0 if velocity_mean * time < distance else 1
if time == 0:
return 0
dist = sp.stats.norm(loc=velocity_mean * time, scale=np.sqrt(velocity_stdev ** 2 * time))
return 1 - dist.cdf(distance)
times = np.ones(1) * time
return get_prob_of_completion_vector(velocity_mean, velocity_stdev, distance, times)[0]


def get_prob_of_completion_vector(velocity_mean, velocity_stdev, distance, times):
Expand Down Expand Up @@ -212,17 +206,20 @@ def estimate_lognorm(grids, samples):
return result


def autoestimate_lognorm(samples):
grids = get_1d_lognorm_grid(0.01, 5.0, samples.mean(), 10)
res = estimate_lognorm(grids, samples)

grids = get_1d_lognorm_grid(res[1] - 0.5, res[1] + 0.5, samples.mean(), 10)
res2 = estimate_lognorm(grids, samples)
def autoestimage_lognorm_general(samples, first_grid, radii, counts):
mean = samples.mean()
res = estimate_lognorm(first_grid, samples)
for (radius, count) in zip(radii, counts):
grid = get_1d_lognorm_grid(res[1] - radius, res[1] + radius, mean, count)
res = estimate_lognorm(grid, samples)
return res

grids = get_1d_lognorm_grid(res2[1] - 0.2, res2[1] + 0.2, samples.mean(), 20)
res3 = estimate_lognorm(grids, samples)

return res3
def autoestimate_lognorm(samples):
grids = get_1d_lognorm_grid(0.01, 5.0, samples.mean(), 10)
res = autoestimage_lognorm_general(samples, grids, (0.5, 0.2), (10, 20))
return res


def get_nonzero_velocity(velocity):
Expand Down
18 changes: 11 additions & 7 deletions estimage/webapp/main/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ def move_consensus_estimate_to_authoritative(task_name):
return view_projective_task(task_name, dict(authoritative=form))


def _attempt_record_of_estimate(task_name, form, pollster):
if form.submit.data:
tell_pollster_about_obtained_data(pollster, task_name, form)
elif form.delete.data:
if pollster.knows_points(task_name):
pollster.forget_points(task_name)
else:
flask.flash("Told to forget something that we don't know")


@bp.route('/estimate/<task_name>', methods=['POST'])
@flask_login.login_required
def estimate(task_name):
Expand All @@ -109,13 +119,7 @@ def estimate(task_name):
form = forms.NumberEstimationForm()

if form.validate_on_submit():
if form.submit.data:
tell_pollster_about_obtained_data(pollster, task_name, form)
elif form.delete.data:
if pollster.knows_points(task_name):
pollster.forget_points(task_name)
else:
flask.flash("Told to forget something that we don't know")
_attempt_record_of_estimate(task_name, form, pollster)
else:
msg = "There were following errors: "
msg += ", ".join(form.get_all_errors())
Expand Down

0 comments on commit f6c97f9

Please sign in to comment.