Exemplo n.º 1
0
def parse_adjustments(adjustments_path):
    dicts = parse_csv(adjustments_path)
    return [
        AdjustmentRecord(
            day=str_to_date(d['day']),
            delta=str_to_timedelta(d['delta']),
        )
        for d in dicts
    ]
Exemplo n.º 2
0
    def _preprocess_path_contexts(self, result_path):

        result = {}

        for file in ["node_types", "paths", "tokens"]:

            file_path = result_path / "{}.csv".format(file)
            if not os.path.exists(file_path):
                raise Exception(
                    "File {} was not created by astminer.".format(file_path))

            result[file] = parse_csv(str(file_path), delimiter=",")

        path_contexts = parse_line_csv(result_path / "path_contexts.csv",
                                       delimiter=" ")
        file_paths = {}

        for index, paths in path_contexts:

            all_paths = []
            for path in paths:
                path = path.split(",")
                if len(path) != 3:
                    logging.critical("No valid paths for {} !".format(index))
                    break
                all_paths.append({
                    "start": path[0],
                    "path_index": path[1],
                    "end": path[2]
                })

            index = index.split(os.path.sep)[-1][:-4]
            file_paths[index] = all_paths

        result["file_paths"] = file_paths

        def _create_index_map(data, field_name):

            field2index = "{}2index".format(field_name)
            index2field = "index2{}".format(field_name)

            result[field2index] = {}
            result[index2field] = {}

            for match in data:
                idx = match["id"]
                field = match[field_name]
                result[field2index][field] = idx
                result[index2field][idx] = field

        _create_index_map(result["node_types"], "node_type")
        _create_index_map(result["tokens"], "token")
        _create_index_map(result["paths"], "path")

        return result
Exemplo n.º 3
0
def parse_month(month_path, year):
    month = int(os.path.basename(month_path).split('.')[0])
    dicts = parse_csv(month_path)
    return MonthRecord(
        year=year,
        month=month,
        records=[
            _day_dict_from_csv_to_day_record(d=d, year=year, month=month)
            for d in dicts
        ]
    )
Exemplo n.º 4
0
def main():
    arguments = docopt(__doc__)

    db_path = arguments['<db_path>']
    csv_path = arguments['<csv_path>']

    dicts = parse_csv(csv_path)
    day_records_from_csv = (dict_to_day_record(d) for d in dicts)
    day_records_from_csv = [r for r in day_records_from_csv if r]

    for day_record_from_csv in day_records_from_csv:
        inserted = write_day_record(db_path, day_record_from_csv)
        if inserted:
            print 'Inserted {}'.format(day_record_from_csv)
        else:
            print 'Discarded: {}'.format(day_record_from_csv)
Exemplo n.º 5
0
	random_number_of_days = random.randrange(days_between_dates)
	random_date = start_date + datetime.timedelta(days=random_number_of_days)
	return random_date


# DATABASE SCHEMA
# items(name, brand, type, RFID, price)                                                     IMPLEMENTED
# stock(itemRFID, amt, expirationDate, location)                                            _
# employees(lastName, firstName, ID, role)                                                  IMPLEMENTED
# hours(employeeID, day, checkIn, checkOut, dayHours)                                       _
# tasks(taskName, description, taskID, state, employeeID, timeCreated, timeCompleted)       implemented
# sales(transactionID, time, totalPaid)                                                     _
# transactions(transactionID, time, item, amt)                                              _
# logins(username, password, accountType)                                                   IMPLEMENTED

items = util.parse_csv("items.csv", 0)
# util.print_nested_list(items)

employees = util.parse_csv("employees.csv", 0)
# util.print_nested_list(employees)

# CREATING THE STOCK CSV

stock = [["itemRFID", "amt", "expirationDate", "location"]]
stock_item_no = util.parse_csv("random_items_numbers.csv", 0)
# util.print_nested_list(stock_item_no)

sin_len = len(stock_item_no[0])-1
sin_half_len = sin_len/2
for i in range(0, sin_len):
	insert = []
Exemplo n.º 6
0
## Written by: Kimberly Chang
## Tested by: Kimberly Chang
## Debugged by: Kimberly Chang

import random
import datetime

import util

items = util.parse_csv("items.csv", 0)
# util.print_nested_list(items)

customerIDs = ["katie587", "coolcat53", "lakes", "laura", "LeaAnderson", "jjohnson", "flyingpigs43", "ilovecats", "amy67", "roger23"]

shopping_list = [["username", "item"]]
for customer in customerIDs:
	no = random.randint(1, 30)
	insert = []
	for j in range(0, no):
		insert.append(customer)

		i = random.randint(1, 10000)

		# items(name, brand, type, RFID, price)
		insert.append(items[i][3])

		shopping_list.append(insert)

		insert = []

util.print_nested_list(shopping_list)