Skip to content

Commit

Permalink
* this is a large purge of old code
Browse files Browse the repository at this point in the history
* tests of core formpack functionality (exports) are passing
* any aspects of KPI which might be broken by this change should 
probably
  be tested independently

#220
  • Loading branch information
dorey committed Jul 15, 2020
1 parent 9750c55 commit 3a2e473
Show file tree
Hide file tree
Showing 13 changed files with 4 additions and 1,466 deletions.
9 changes: 1 addition & 8 deletions src/formpack/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,18 @@
import begin

from formpack import FormPack
from .utils.expand_content import expand_content
from .utils.flatten_content import flatten_content
from .utils.xls_to_ss_structure import xls_to_dicts


def print_xls(filename, expand=False, flatten=False, xml=False):
def print_xls(filename, flatten=False, xml=False):
"""
converts and XLS file with many sheets to a JSON object with lists
of key-value pairs for each row in the sheet.
"""
try:
with open(filename, 'r') as ff:
content = xls_to_dicts(ff)
if expand:
expand_content(content)
settings = content.get('settings', {})
settings['title'] = settings.get('title', 'title')
settings['id_string'] = settings.get('id_string', 'id_string')
content['settings'] = [settings]
if flatten:
flatten_content(content)
settings = content.pop('settings', [{}])[0]
Expand Down
5 changes: 0 additions & 5 deletions src/formpack/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
from .version import FormVersion
from .utils import str_types
from .reporting import Export, AutoReport
from .utils.expand_content import expand_content
from .utils.future import OrderedDict
from .utils.replace_aliases import replace_aliases
from .constants import UNSPECIFIED_TRANSLATION
from formpack.schema.fields import CopyField

Expand Down Expand Up @@ -109,9 +107,6 @@ def load_version(self, schema):
"""
cschema = deepcopy(schema)

replace_aliases(schema['content'], in_place=True)
expand_content(schema['content'], in_place=True)

_content = cschema.pop('content')
content = {**_content, 'schema': '1+formpack'}

Expand Down
7 changes: 1 addition & 6 deletions src/formpack/reporting/autoreport.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from collections import defaultdict

from ..constants import UNSPECIFIED_TRANSLATION
from ..submission import FormSubmission
from ..utils.ordered_collection import OrderedCounter


Expand Down Expand Up @@ -70,8 +69,6 @@ def _calculate_stats(self, submissions, fields, versions, lang):
submissions_count += 1
submission_counts_by_version[version_id] += 1

# TODO: do we really need FormSubmission ?
entry = FormSubmission(entry).data
for field in fields:
if field.has_stats:
counter = metrics[field.name]
Expand Down Expand Up @@ -140,11 +137,9 @@ def _disaggregate_stats(self, submissions, fields, versions, lang, split_by_fiel
submissions_count += 1
submission_counts_by_version.update([version_id])

# TODO: do we really need FormSubmission ?

# since we are going to pop one entry, we make a copy
# of it to avoid side effect
entry = dict(FormSubmission(sbmssn).data)
entry = dict(sbmssn)
splitter = entry.pop(split_by_field.path, None)

for field in fields:
Expand Down
4 changes: 1 addition & 3 deletions src/formpack/reporting/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

from ..constants import UNSPECIFIED_TRANSLATION, TAG_COLUMNS_AND_SEPARATORS
from ..schema import CopyField
from ..submission import FormSubmission
from ..utils.exceptions import FormPackGeoJsonError
from ..utils.flatten_content import flatten_tag_list
from ..utils.future import iteritems, itervalues, OrderedDict
Expand Down Expand Up @@ -126,8 +125,7 @@ def parse_one_submission(self, submission, version=None):
# `format_one_submission()` will recurse through all the sections; get
# the first one to start
section = get_first_occurrence(version.sections.values())
submission = FormSubmission(submission)
return self.format_one_submission([submission.data], section)
return self.format_one_submission([submission], section)

def parse_submissions(self, submissions):
"""
Expand Down
18 changes: 1 addition & 17 deletions src/formpack/schema/datadef.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from ..utils.future import OrderedDict



class FormDataDef(object):
""" Any object composing a form. It's only used with a subclass. """

Expand All @@ -26,17 +25,6 @@ def __repr__(self):
def get_value_names(self):
return [self.name]

@classmethod
def _extract_json_labels(cls, definition, translations):
""" Extract translation labels from the JSON data definition """
label = definition.get('label')
if label:
labels = OrderedDict(zip(translations, label))
else:
labels = {}
return labels


@property
def path(self):
return '/'.join(item.name for item in self.hierarchy[1:])
Expand Down Expand Up @@ -69,11 +57,7 @@ def parent_section(self):

@property
def section(self):
if self._section:
assert self._section is self.parent_section
return self._section
else:
return self.parent_section
return self.parent_section

def _add_to_parent_section_fields(self):
_parent_section = self.parent_section
Expand Down
113 changes: 0 additions & 113 deletions src/formpack/submission.py

This file was deleted.

Loading

0 comments on commit 3a2e473

Please sign in to comment.