Example #1
0
def create(filename):
    raw = io.read_csv_as_dictionary(path.raw(filename))
    d = []
    # camelcase company name for consistency
    for x in raw:
        company = name.camel_case(x['Company'])

        # true/false whether telco
        is_telco = 'false'
        if 'telco' in x['Type'].lower():
            is_telco = 'true'

        d.append({
            'name': company,
            'id': name.filename(company),
            'display': x['Company'],
            'total': x['Total'],
            'commitment': x['Commitment'],
            'freedom': x['Freedom of Expression'],
            'privacy': x['Privacy'],
            'telco': is_telco
        })

    # io.write_json(path.assets('overview.json'), d)
    io.write_json_pretty(path.assets('overview.json'), d)
Example #2
0
def create(filename):
    raw = io.read_csv(path.raw(filename))

    # input file uses empty rows to separate questions.
    groups = array.slice_arr(raw, array.is_empty_row)

    # find where each indicator is based on row length
    survey = []
    for grouping in groups:

        # strip empty cells
        stripped = []
        for row in grouping:
            stripped.append([item for item in row if item != ''])

        # responses all occupy more than one cell in a row
        responses = [item for item in stripped if len(item) > 1]

        # single cells are either separators, or question texts
        single_cells = [item[0] for item in stripped if len(item) == 1]

        # these are separators - check for them
        checklist = 'checklist elements'
        categories = 'answer categories'

        # more than one here means there are follow-ups
        question = [item for item in single_cells if checklist not in item.lower()
                and categories not in item.lower()]
        if len(question) > 1:
            followups = question[1:]
        else:
            followups = 0

        # separate name and text
        question = question[0]
        line_break = question.find('\n')
        if line_break > 0:
            name = question[:line_break]
            question = question[line_break+1:]
        else:
            name = question
            question = ''

        # id is 1st two chars
        question_id = name[0:name.find('.')]
        survey.append({
            'id': question_id,
            'name': name,
            'text': question,
            'follow': followups,
            'levels': [{
                'id': item[0].strip(),
                'text': item[1].strip() if categories not in item[1].lower() else 0,
                'responses': item[2:]
            } for item in responses]
        })

    io.write_json(path.assets('survey.json'), survey)
def companies():
    __create_or_delete__(path.companies("")[:-1])
    overview = io.read_json(path.assets("overview.json"))
    for company in overview:
        filename = (company["name"] + ".md").lower().replace("&", "")
        with open(path.companies(filename), "w") as f:
            f.write("---\n")
            f.write("entity: %s\n" % filename[:-3])

            f.write("\nlayout: company\n\n")

            for key, value in company.iteritems():
                if key in ["total", "commitment", "privacy", "freedom"]:
                    f.write("%s: %s" % (key, int(round(float(value)))))
                else:
                    f.write("%s: %s" % (key, value))
                f.write("\n")
            f.write("\ndescription: one-line description\n")
            f.write("website: http://example.com")
            f.write("\n---\n\n")
            f.write("Paragraph describing this company\n")
Example #4
0
def companies():
    __create_or_delete__(path.companies('')[:-1])
    overview = io.read_json(path.assets('overview.json'))
    for company in overview:
        filename = (company['name'] + '.md').lower().replace('&', '')
        with open(path.companies(filename), 'w') as f:
            f.write('---\n')
            f.write('entity: %s\n' % filename[:-3])

            f.write('\nlayout: company\n\n')

            for key, value in company.iteritems():
                if key in ['total', 'commitment', 'privacy', 'freedom']:
                    f.write('%s: %s' % (key, int(round(float(value)))))
                else:
                    f.write('%s: %s' % (key, value))
                f.write('\n')
            f.write('\ndescription: one-line description\n')
            f.write('website: http://example.com')
            f.write('\n---\n\n')
            f.write('Paragraph describing this company\n')
Example #5
0
def create(filename):
    raw = io.read_csv_as_dictionary(path.raw(filename))
    d = []
    # camelcase company name for consistency
    for x in raw:
        company = name.camel_case(x['Company'])

        # true/false whether telco
        is_telco = 'false'
        if 'telco' in x['Type'].lower():
            is_telco = 'true'

        d.append({
            'name': company,
            'id': name.filename(company),
            'display': x['Company'],
            'total': x['Total'],
            'commitment': x['Commitment'],
            'freedom': x['Freedom of Expression'],
            'privacy': x['Privacy'],
            'telco': is_telco
        })

    io.write_json(path.assets('overview.json'), d)
def indicators():
    __create_or_delete__(path.indicators("")[:-1])
    custom = io.read_json(path.assets("custom-questions.json"))
    indicators = io.read_json(path.assets("survey.json"))
    for idx, indicator in enumerate(indicators):
        indicator_id = indicator["id"].lower()

        # Determine if it's in the list of custom indicators
        is_custom = False
        if indicator_id in custom:
            is_custom = True

        filename = indicator_id + ".md"
        with open(path.indicators(filename), "w") as f:
            f.write("---\n")
            f.write("sort: %s\n" % idx)
            f.write("entity: %s\n" % filename[:-3])
            f.write("entity_type: indicator\n")

            first_letter = filename[0]
            if "c" in first_letter:
                f.write("category_ref: commitment\n")
                f.write("category: Commitment\n")
            elif "f" in first_letter:
                f.write("category_ref: freedom-of-expression\n")
                f.write("category: Freedom of Expression\n")
            else:
                f.write("category_ref: privacy\n")
                f.write("category: Privacy\n")

            f.write("\nlayout: indicator\n\n")

            # text, id, name
            for item in ["name", "text", "id"]:
                f.write("%s: %s\n" % (item, indicator[item].encode("UTF-8")))

            # possible answers
            f.write("\nlevels:\n")
            for idx, resp in enumerate(indicator["levels"]):

                # first, just make sure we write level text
                if resp["text"] != 0:
                    f.write('  - text: "%s"\n' % resp["text"].encode("UTF-8"))
                    f.write("    id: %s\n" % resp["id"].encode("UTF-8"))

                # this is really only for c1.b at this point.
                if not is_custom and resp["id"].lower() in custom:
                    custom_answer = custom[resp["id"].lower()]
                    f.write("    choices:\n")
                    for a in custom_answer:
                        f.write('      - text: "%s"\n' % a["text"].encode("UTF-8"))
                        f.write('        score: "%s"\n' % a["score"])

            f.write("\nchoices:\n")
            if is_custom:
                custom_answer = custom[indicator_id]
                for a in custom_answer:
                    f.write('  - text: "%s"\n' % a["text"].encode("UTF-8"))
                    f.write('    score: "%s"\n' % a["score"])

            f.write("\n---\n\n")
Example #7
0
def create(filename):
    raw = io.read_csv(path.raw(filename))

    # input file uses empty rows to separate questions.
    groups = array.slice_arr(raw, array.is_empty_row)

    # find where each indicator is based on row length
    survey = []
    for grouping in groups:

        # strip empty cells
        stripped = []
        for row in grouping:
            stripped.append([item for item in row if item != ''])

        # responses all occupy more than one cell in a row
        responses = [item for item in stripped if len(item) > 1]

        # single cells are either separators, or question texts
        single_cells = [item[0] for item in stripped if len(item) == 1]

        # these are separators - check for them
        checklist = 'checklist elements'
        categories = 'answer categories'

        # more than one here means there are follow-ups
        question = [
            item for item in single_cells if checklist not in item.lower()
            and categories not in item.lower()
        ]
        if len(question) > 1:
            followups = question[1:]
        else:
            followups = 0

        # separate name and text
        question = question[0]
        line_break = question.find('\n')
        if line_break > 0:
            name = question[:line_break]
            question = question[line_break + 1:]
        else:
            name = question
            question = ''

        # id is 1st two chars
        question_id = name[0:name.find('.')]
        survey.append({
            'id':
            question_id,
            'name':
            name,
            'text':
            question,
            'follow':
            followups,
            'levels': [{
                'id':
                item[0].strip(),
                'text':
                item[1].strip() if categories not in item[1].lower() else 0,
                'responses':
                item[2:]
            } for item in responses]
        })

    io.write_json(path.assets('survey.json'), survey)
Example #8
0
def indicators():
    __create_or_delete__(path.indicators('')[:-1])
    custom = io.read_json(path.assets('custom-questions.json'))
    indicators = io.read_json(path.assets('survey.json'))
    for idx, indicator in enumerate(indicators):
        indicator_id = indicator['id'].lower()

        # Determine if it's in the list of custom indicators
        is_custom = False
        if indicator_id in custom:
            is_custom = True

        filename = (indicator_id + '.md')
        with open(path.indicators(filename), 'w') as f:
            f.write('---\n')
            f.write('sort: %s\n' % idx)
            f.write('entity: %s\n' % filename[:-3])
            f.write('entity_type: indicator\n')

            first_letter = filename[0]
            if 'c' in first_letter:
                f.write('category_ref: commitment\n')
                f.write('category: Commitment\n')
            elif 'f' in first_letter:
                f.write('category_ref: freedom-of-expression\n')
                f.write('category: Freedom of Expression\n')
            else:
                f.write('category_ref: privacy\n')
                f.write('category: Privacy\n')

            f.write('\nlayout: indicator\n\n')

            # text, id, name
            for item in ['name', 'text', 'id']:
                f.write('%s: %s\n' % (item, indicator[item].encode('UTF-8')))

            # possible answers
            f.write('\nlevels:\n')
            for idx, resp in enumerate(indicator['levels']):

                # first, just make sure we write level text
                if resp['text'] != 0:
                    f.write('  - text: "%s"\n' % resp['text'].encode('UTF-8'))
                    f.write('    id: %s\n' % resp['id'].encode('UTF-8'))

                # this is really only for c1.b at this point.
                if not is_custom and resp['id'].lower() in custom:
                    custom_answer = custom[resp['id'].lower()]
                    f.write('    choices:\n')
                    for a in custom_answer:
                        f.write('      - text: "%s"\n' %
                                a['text'].encode('UTF-8'))
                        f.write('        score: "%s"\n' % a['score'])

            f.write('\nchoices:\n')
            if is_custom:
                custom_answer = custom[indicator_id]
                for a in custom_answer:
                    f.write('  - text: "%s"\n' % a['text'].encode('UTF-8'))
                    f.write('    score: "%s"\n' % a['score'])

            f.write('\n---\n\n')