Commit 5b0ce9a9 by Shirley He

create output file

parent 036f6805
......@@ -6,8 +6,10 @@ import argparse
from argparse import ArgumentParser
from pprint import pprint
from itertools import product
from itertools import permutations
import sys
def parse_field_arguments():
parser = argparse.ArgumentParser()
parser.add_argument('--fields', nargs="*", action="append", default=None,
......@@ -15,34 +17,47 @@ def parse_field_arguments():
parser.add_argument('filename')
num_args = parser.parse_args()
field_length = len(num_args.fields[0])
if (field_length > 3):
raise argparse.ArgumentTypeError("--fields can only take a max of 3 values")
file = open(num_args.filename)
permutation_data = json.load(file)
file_data = json.load(file)
fields = {}
default_data = file_data["default_data"]
permutation_data = file_data["permutation_data"]
default_data_keys = permutation_data.keys()
# first_field = permutation_data
# second_field = permutation_data
# third_field = permutation_data
# print default_data_keys
fields = {}
# if no field arguments are given, just print out default data
if not num_args.fields:
default_permutation = permutation_data["default_data"]
print default_permutation
default_permutation = file_data["default_data"]
fields = default_permutation
else:
field_length = len(num_args.fields[0])
if (field_length > 3):
raise argparse.ArgumentTypeError("--fields can only take a max of 3 values")
for permutation_choices in num_args.fields:
for i in range(0, field_length):
fields[permutation_choices[i]] = permutation_data["permutation_data"][permutation_choices[i]]
fields[permutation_choices[i]] = permutation_data[permutation_choices[i]]
# for j in range(field_length, total_num_fields):
# fields[permutation_choices[j]] =
# print permutation_data.keys() not in permutation_choices
return fields
def generate_permutations(fields):
#permutation_generation = [first_field, second_field, third_field]
# print list(product(*fields))
print fields
field_permutations = list(product(*fields.values()))
# make JSON output file
with open("test_courses.json", "w") as outfile:
json.dump(field_permutations, outfile)
if __name__ == "__main__":
......
[["past", true, "past"], ["past", true, "future"], ["past", true, null], ["past", false, "past"], ["past", false, "future"], ["past", false, null], ["past", null, "past"], ["past", null, "future"], ["past", null, null], ["future", true, "past"], ["future", true, "future"], ["future", true, null], ["future", false, "past"], ["future", false, "future"], ["future", false, null], ["future", null, "past"], ["future", null, "future"], ["future", null, null], [null, true, "past"], [null, true, "future"], [null, true, null], [null, false, "past"], [null, false, "future"], [null, false, null], [null, null, "past"], [null, null, "future"], [null, null, null]]
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment