<commit_before># Python script to organize PixelPOS "Profit by Summary Group" sales reports
# tidied up by saleswiz.py into single tables for chart production.

import os
import csv
import sys

from glob import glob
from collections import OrderedDict
from copy import deepcopy


# *sales_clean.csv columns.
cols = ['Category', 'Subcategory', 'Item', 'Quantity', 'Value',]


def flip(out_base, files):
    """Consolidate monthly or weekly sales_clean.csv files into single table."""
    dl = []
    q = OrderedDict()
    q['Item'] = []
    for i, f in enumerate(files):
        dl.append(OrderedDict())
        for c in cols:
            dl[i][c] = []

        try:
            with open(f, 'rb') as in_f:
                in_d = csv.DictReader(in_f, fieldnames=cols, delimiter=',', quotechar='"')
                for row in in_d:
                    [dl[i][c].append(row[c].strip()) for c in cols]
                in_f.close()
        except:
            print 'Problem reading file "%s".' % f.split('/')[-1]
            return False

        period = f.split('/')[-1].split('sales')[0]
        q[period] = []

    for r in xrange(1, len(dl[0][cols[0]]) - 1):
        row = [dl[0][c][r] for c in cols]
        if dl[0]['Item'][r]:
            q['Item'].append(dl[0]['Item'][r])
        elif dl[0]['Subcategory'][r] and any(row[2:]):
            q['Item'].append('Subcategory - ' + dl[0]['Subcategory'][r])
        elif dl[0]['Category'][r] and any(row[1:]):
            q['Item'].append('Category - ' + dl[0]['Category'][r])

    v = deepcopy(q)

    for i, d in enumerate(dl):
        for r in xrange(1, len(dl[0][cols[0]]) - 1):
            if d['Quantity'][r]:
                q[q.keys()[i+1]].append(d['Quantity'][r])
                v[v.keys()[i+1]].append(d['Value'][r])

    ok_q = write_file(q, out_base + 'quantity.csv', q.keys())
    ok_v = write_file(v, out_base + 'value.csv', v.keys())<commit_msg>Included Grand Totals in flipwiz.py.<commit_after># Python script to organize PixelPOS "Profit by Summary Group" sales reports
# tidied up by saleswiz.py into single tables for chart production.

import os
import csv
import sys

from glob import glob
from collections import OrderedDict
from copy import deepcopy


# *sales_clean.csv columns.
cols = ['Category', 'Subcategory', 'Item', 'Quantity', 'Value',]


def flip(out_base, files):
    """Consolidate monthly or weekly sales_clean.csv files into single table."""
    dl = []
    q = OrderedDict()
    q['Item'] = []
    for i, f in enumerate(files):
        dl.append(OrderedDict())
        for c in cols:
            dl[i][c] = []

        try:
            with open(f, 'rb') as in_f:
                in_d = csv.DictReader(in_f, fieldnames=cols, delimiter=',', quotechar='"')
                for row in in_d:
                    [dl[i][c].append(row[c].strip()) for c in cols]
                in_f.close()
        except:
            print 'Problem reading file "%s".' % f.split('/')[-1]
            return False

        period = f.split('/')[-1].split('sales')[0]
        q[period] = []

    for r in xrange(1, len(dl[0][cols[0]])):
        row = [dl[0][c][r] for c in cols]
        if dl[0]['Item'][r]:
            q['Item'].append(dl[0]['Item'][r])
        elif dl[0]['Subcategory'][r] and any(row[2:]):
            q['Item'].append('Subcategory - ' + dl[0]['Subcategory'][r])
        elif dl[0]['Category'][r] and any(row[1:]):
            q['Item'].append('Category - ' + dl[0]['Category'][r])

    v = deepcopy(q)

    for i, d in enumerate(dl):
        for r in xrange(1, len(dl[0][cols[0]])):
            if d['Quantity'][r]:
                q[q.keys()[i+1]].append(d['Quantity'][r])
                v[v.keys()[i+1]].append(d['Value'][r])

    ok_q = write_file(q, out_base + 'quantity.csv', q.keys())
    ok_v = write_file(v, out_base + 'value.csv', v.keys())
{'fraction_non_alphanumeric': 0.18252933507170796, 'fraction_numerical': 0.010951760104302478, 'mean_word_length': 2.421944692239072, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '41022', 'n_tokens_mistral': 1325, 'n_tokens_neox': 1286, 'n_words': 325}