Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add image columns to tables #897

Merged
merged 15 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: transform string data for integral fields (#892)
* feat: transform string data for integral fields

* chore: clear refs to participant completion rating
  • Loading branch information
dodumosu authored and takinbo committed Sep 14, 2022
commit 8b749d6b9b5289a159b5d853af3199e8bf1c9a13
4 changes: 0 additions & 4 deletions apollo/formsframework/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,6 @@ def save(self, commit=True):
submission.update_related(data)
update_submission_version(submission)

# update completion rating for participant
# if submission.form.form_type == 'CHECKLIST':
# update_participant_completion_rating(participant)

return submission


Expand Down
11 changes: 9 additions & 2 deletions apollo/submissions/qa/query_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from arpeggio import PTNodeVisitor, visit_parse_tree
from arpeggio.cleanpeg import ParserPEG
from sqlalchemy import (
BigInteger, Integer, String, and_, case, false, func, null, or_)
BigInteger, Integer, String, and_, case, cast, false, func, null, or_)
from sqlalchemy.dialects.postgresql import array
from sqlalchemy.sql.operators import concat_op

Expand Down Expand Up @@ -263,7 +263,14 @@ def visit_variable(self, node, children):
return null()
else:
self.prev_cast_type = cast_type
if cast_type is not None:
if cast_type in (BigInteger, Integer):
return cast(
func.coalesce(
func.nullif(Submission.data[var_name].astext, ''),
'0'
), cast_type
)
elif cast_type is not None:
return Submission.data[var_name].astext.cast(cast_type)
return Submission.data[var_name]

Expand Down
57 changes: 20 additions & 37 deletions apollo/submissions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np
import pandas as pd
from pandas.io.json import json_normalize
from sqlalchemy import String, cast, func
from sqlalchemy import BigInteger, String, cast, func
from sqlalchemy.dialects.postgresql import array_agg
from sqlalchemy.orm import aliased

Expand All @@ -24,10 +24,24 @@ def make_submission_dataframe(query, form, selected_tags=None,
fields = fields.difference(excluded_tags)

# the 'updated' field is required for results analysis
integral_fields = [
tag for tag in fields
if form.get_field_by_tag(tag)['type'] == 'integer'
or form.get_field_by_tag(tag)['type'] == 'select'
]

columns = [
Submission.data[tag].label(tag) for tag in fields] + [
cast(
func.coalesce(
func.nullif(Submission.data[tag].astext, ''),
'0'),
BigInteger).label(tag) for tag in integral_fields]
other_fields = fields.difference(integral_fields)

columns.extend([
Submission.data[tag].label(tag) for tag in other_fields] + [
Submission.updated
]
])

# alias just in case the query is already joined to the tables below
ancestor_loc = aliased(Location, name='ancestor')
Expand Down Expand Up @@ -71,7 +85,9 @@ def make_submission_dataframe(query, form, selected_tags=None,
type_coercions = {
tag: np.float64
for tag in form.tags
if form.get_field_by_tag(tag)['type'] == 'integer'}
if form.get_field_by_tag(tag)['type'] == 'integer'
or form.get_field_by_tag(tag)['type'] == 'select'
}

dataframe_query = query.filter(
Submission.location_id == own_loc.id
Expand Down Expand Up @@ -99,36 +115,3 @@ def make_submission_dataframe(query, form, selected_tags=None,
], axis=1, join_axes=[df.index])

return df_summary


def update_participant_completion_rating(submission):
participant = submission.participant
submissions = participant.submissions

numerator = 0
denominator = 0
completion_map = {
'Missing': 0,
'Partial': 1,
'Complete': 2,
'Conflict': 2 # TODO: find a better way to compute the ratings
}

# TODO: fix this
# if len(submissions) == 0:
# participant.completion_rating = 1
# else:
# for submission in submissions:
# completion_values = [
# completion_map[i] for i in
# list(submission.completion.values())
# ]
# denominator += len(submission.form.groups) * 2.0
# numerator += sum(completion_values)

# try:
# participant.completion_rating = (numerator / denominator)
# except ZeroDivisionError:
# # this should never happen
# participant.completion_rating = 1
# participant.save()
4 changes: 0 additions & 4 deletions apollo/submissions/views_submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1124,10 +1124,6 @@ def submission_edit(submission_id):

db.session.commit()
update_submission_version(submission)
# submission is for a checklist form, update
# contributor completion rating
# update_participant_completion_rating(
# submission.participant)
else:
no_error = False

Expand Down