Exemplo n.º 1
0
    def __init__(self,
                 optifs=True,
                 postprocess=True,
                 nobcs=False,
                 slice=False):

        self.prog = Program()

        self.fncs = {}
        self.fncsl = []
        self.fnc = None
        self.loc = None

        self.optifs = optifs
        self.postproc = postprocess
        self.slice = slice

        self.loops = []

        self.cnt = 0

        self.warns = []

        self.hasbcs = False
        self.nobcs = nobcs
Exemplo n.º 2
0
def load_program():
    """Load program from seed_data into database."""
    tablename = 'program'
    data = jsonify_seed_data(tablename)

    for item in data[tablename]:
        new_item = Program(name=item['name'], order=item['order'])
        db.session.add(new_item)
    db.session.commit()
Exemplo n.º 3
0
def create_program():
    """ Make request to/program endpoint"""
    request_data = request.get_json()
    program_name = request_data['program_name']
    description = request_data['description']
    new_program = Program(program_name=program_name, description=description)

    db.session.add(new_program)
    db.session.commit()
    program_dict = serialize_program(new_program)
    return jsonify(program_dict)
Exemplo n.º 4
0
def load_programs():
    print('Utility Green Energy Programs')
    file = open("seed_data/u.programs")

    for row in file:
        row = row.rstrip()
        prog_area, program_link = row.split(' = ')

        program = Program(prog_area=prog_area, program_link=program_link)
        db.session.add(program)
        db.session.commit()
    db.session.commit()
Exemplo n.º 5
0
def save(program, file):
	"""Program → File."""
	folder = os.path.dirname(file)
	if not os.path.exists(folder):
		os.makedirs(folder)
	with open(file, 'w') as f:
		if isinstance(program, Program):
			output_program = Program()
			output_program.abox = program.abox
			output_program.tbox.constraints = program.tbox.constraints
			output_program.tbox.rules = set()
			f.write(str(output_program))
		else:
			f.write(str(program))
		return file
Exemplo n.º 6
0
def create_program(user_id, college_id, name, cohort, minimum_gpa, label, link:"no_link"):
	"""Create and return program"""
	print("create program called")

	program = Program(college_id=college_id, name=name, cohort=cohort,minimum_gpa=minimum_gpa, label=label, link=link)
	print(program)
	print (program.program_id, program.name) 

	print('program created')
	db.session.add(program)
	db.session.commit()
	print ("after commit", program.program_id)
	user_program = UserProgram(user_id=user_id, program_id=program.program_id)
	db.session.add(user_program)
	db.session.commit()

	print("after commit 2", user_program)
	print("hello", user_program.programs)
	print("helloss", user_program.users)
	return program, user_program
Exemplo n.º 7
0
def load_programs():
    """Load programs information from seed file into the database.
    working code"""

    print("Program")

    # opening seed file with the csv library and csv reader.
    with open('seed_production/WorkingDataSet_2-19-2020.csv') as csv_file:
        # below will seed with 'test' data
        # with open('seed_test/programs_test_csv.csv') as csv_file:
        csv_reader = csv.reader(csv_file, delimiter=',')
        line_count = 0

        for row in csv_reader:
            if line_count == 0:
                # print(f'Column names are {", ".join(row)}')
                line_count += 1
            else:
                #get field values from the csv file
                application_id = row[0]

                #get the utility id
                utility_abreviation = row[1]
                #convert utility code to company name
                utility_name = get_utility_name(utility_abreviation)
                utility = get_company_id(utility_name)
                # print(f'utility: {utility}')

                city = row[18]
                county = row[19]
                zipcode = row[21]

                #get the contractor id
                contractor_name = row[44]
                c_name = Company.query.filter(
                    Company.name == contractor_name).first()
                contractor = c_name.company_id

                #get the pv manuf id
                pv_manuf_name = row[49]
                pv_manuf = get_company_id(pv_manuf_name)

                #get the invert manuf id
                invert_manuf_name = row[76]
                invert_manuf = get_company_id(invert_manuf_name)

                status = row[106]

                #add field values to an instance of Program
                program = Program(application_id=application_id,
                                  utility=utility,
                                  city=city,
                                  county=county,
                                  zipcode=zipcode,
                                  contractor=contractor,
                                  pv_manuf=pv_manuf,
                                  invert_manuf=invert_manuf,
                                  status=status)

                # add the instance of program to the database
                db.session.add(program)

                line_count += 1

        # Commit our work so it saves to the database
        db.session.commit()

        print(f'Program line_count: {line_count}')
Exemplo n.º 8
0
def load_dummy_data():
    """ Load dummy data to test database for testing purposes. """

    salt = binascii.hexlify(os.urandom(SALT_SIZE))
    denise = User(
        username='******',
        password=hashlib.sha256(os.environ['PASSWORD_ONE'].encode('utf-8') +
                                salt).hexdigest(),
        salt=salt.decode('utf-8'),
        first_name='Denise',
        last_name='Codes',
        email='*****@*****.**')
    salt = binascii.hexlify(os.urandom(SALT_SIZE))
    roy = User(
        username='******',
        password=hashlib.sha256(os.environ['PASSWORD_TWO'].encode('utf-8') +
                                salt).hexdigest(),
        salt=salt.decode('utf-8'),
        first_name='Roy',
        last_name='Codes',
        email='*****@*****.**')
    salt = binascii.hexlify(os.urandom(SALT_SIZE))
    leo = User(
        username="******",
        password=hashlib.sha256(os.environ['PASSWORD_THREE'].encode('utf-8') +
                                salt).hexdigest(),
        salt=salt.decode('utf-8'),
        first_name='Leo',
        last_name='Codes',
        email='*****@*****.**')
    salt = binascii.hexlify(os.urandom(SALT_SIZE))
    turing = User(
        username='******',
        password=hashlib.sha256(os.environ['PASSWORD_FOUR'].encode('utf-8') +
                                salt).hexdigest(),
        salt=salt.decode('utf-8'),
        first_name='Turing',
        last_name='Codes',
        email='*****@*****.**')
    salt = binascii.hexlify(os.urandom(SALT_SIZE))
    denisedenise = User(
        username='******',
        password=hashlib.sha256(os.environ['PASSWORD_FIVE'].encode('utf-8') +
                                salt).hexdigest(),
        salt=salt.decode('utf-8'),
        first_name='Denise',
        last_name='Salazar',
        email='*****@*****.**')

    angels = Facility(address='100 A St',
                      city='CityOfAngels',
                      fac_name='fac_name_1',
                      state='CA',
                      zipcode=10000)
    devils = Facility(address='100 B St',
                      city='CityOfDevils',
                      fac_name='fac_name_2',
                      state='CA',
                      zipcode=20000)
    wizards = Facility(address='100 C St',
                       city='CityOfWizards',
                       fac_name='fac_name_3',
                       state='CA',
                       zipcode=30000)
    denise.facilities.append(angels)
    denise.facilities.append(devils)
    denise.facilities.append(wizards)
    roy.facilities.append(devils)
    roy.facilities.append(wizards)

    cake = Program(program_name='Cake')
    pudding = Program(program_name='Pudding')
    bread = Program(program_name='Bread')
    angels.programs.append(cake)
    angels.programs.append(pudding)
    angels.programs.append(bread)
    devils.programs.append(pudding)
    devils.programs.append(bread)

    ocean = Recording(name='Ocean',
                      description='Ocean sounds',
                      file_path='/static/ocean')
    wind = Recording(name='Wind',
                     description='Wind sounds',
                     file_path='/static/wind')
    park = Recording(name='Park',
                     description='Park sounds',
                     file_path='/static/park')
    denise.recordings.append(ocean)
    denise.recordings.append(wind)
    denise.recordings.append(park)
    roy.recordings.append(wind)
    roy.recordings.append(park)

    family = Message(
        message_type='Family',
        message=
        'I am not feeling well. I will contact you when I start feeling better.'
    )
    boss = Message(
        message_type='Co-worker',
        message=
        'I am out sick today. Please message me if there are any immediate deliverables for today.'
    )
    friend = Message(
        message_type='Friend',
        message=
        'I really wanted to see you but I cannot visit with you today. Will get in touch when I am feeling better.'
    )
    denise.messages.append(family)
    denise.messages.append(boss)
    denise.messages.append(friend)
    roy.messages.append(boss)
    roy.messages.append(friend)

    db.session.add_all([denise, roy, leo, turing, denisedenise])
    db.session.commit()
Exemplo n.º 9
0
def load_facilities_and_programs_from_file_and_remove_duplicates():
    """ Load all rows from programs.txt file, remove duplicates, seed tables in database.

    All rows from programs.txt goes into the programs_staging table.
    The data from the rows is then broken down into two tables: facilities and programs."""

    file = open('programs.txt', 'r')

    # remove diplicates
    staging_set = set()
    facility_set = set()
    program_set = set()
    facility_program_set = set()

    for line in file:
        fac_id, fac_name, address, city, state, zipcode, program_name = line.split(
            '|')
        staging_tup = (fac_id, fac_name, address, city, state, zipcode[:5],
                       program_name)

        facility_tup = (fac_id, fac_name, address, city, state, zipcode)

        program_tup = (program_name, )

        facility_program_tup = (fac_id, program_name)

        staging_set.add(staging_tup)
        facility_set.add(facility_tup)
        program_set.add(program_tup)
        facility_program_set.add(facility_program_tup)

    file.close()

    # add items to programs_staging table
    for item in staging_set:
        program_staging = ProgramStaging(fac_id=item[0],
                                         fac_name=item[1],
                                         address=item[2],
                                         city=item[3],
                                         state=item[4],
                                         zipcode=item[5],
                                         program_name=item[6])
        db.session.add(program_staging)

    db.session.commit()

    # add items to facilities table
    for item in facility_set:
        facility = Facility(fac_id=item[0],
                            fac_name=item[1],
                            address=item[2],
                            city=item[3],
                            state=item[4],
                            zipcode=item[5])
        db.session.add(facility)

    db.session.commit()

    # add items to programs table
    for item in program_set:
        program = Program(program_name=item[0])
        db.session.add(program)
    db.session.commit()

    # create mapping program_name to program_id
    program_dict = {}
    for program in Program.query.all():
        program_dict[program.program_name] = program.program_id

    # add items to facilities_programs table
    for item in facility_program_set:
        program_id = program_dict[item[1]]
        facility_program = FacilityProgram(fac_id=item[0],
                                           program_id=program_id)
        db.session.add(facility_program)
    db.session.commit()
Exemplo n.º 10
0
def run(input_folder,
        output_folder,
        program_file='program.lp',
        query_file='queries.lp',
        mode='gif'):
    """Initiate."""
    program = parser.parse_program(os.path.join(input_folder, program_file))
    queries = parser.parse_program(os.path.join(input_folder,
                                                query_file)).tbox.rules
    statistics = {
        "name": os.path.basename(input_folder).upper(),
        "rules": len(program.tbox),
        "facts": len(program.abox),
        "queries": []
    }
    if mode == 'gcf':
        program = gcf.convert_program(program)
        if not os.path.exists(output_folder):
            os.makedirs(output_folder)
        with open(os.path.join(output_folder, 'program(*+-^).lp'), 'w') as f:
            f.write(str(program))
        statistics.update({
            "rules(*+-^)": len(program.tbox.rules),
            "constraints(*+-^)": len(program.tbox.constraints),
        })
    for query_index, query in enumerate(queries):
        print(query)
        query_name = "q{}".format(query_index)
        p = Program()
        p.tbox = copy(program.tbox)
        p.abox = copy(program.abox)
        if mode == 'gcf':
            # GCF Algorithm
            result = gcf.run(p, query, os.path.join(output_folder, query_name))
            # Statistics
            statistics['queries'].append({
                "name": query_name,
                "query": str(query),
                "length": len(query.body),
                "generate": result.generated,
                "forest": result.forest,
                "time(s)": {
                    "grounding": result.instantiation_time,
                    "solving": result.solving_time,
                    "total": result.instantiation_time + result.solving_time
                },
                "answer": result.result,
            })
        else:
            # GIF Algorithm
            result = gif.run(p, query, os.path.join(output_folder, query_name))
            # Statistics
            statistics['queries'].append({
                "name": query_name,
                "query": str(query),
                "length": len(query.body),
                "generate": result.generated,
                "time(s)": {
                    "grounding":
                    result.instantiation_time,
                    "solving":
                    result.solving_time,
                    "validating":
                    result.validating_time,
                    "total":
                    result.instantiation_time + result.solving_time +
                    result.validating_time
                },
                "answer": result.result,
            })
    with open(os.path.join(output_folder, "result.json"), 'w') as result_file:
        json.dump(statistics, result_file, indent=4)
Exemplo n.º 11
0
def example_data():
    """ Create some sample data. """

    #Programs
    first_program = Program(
        name="Leadership Development Program",
        description="Leadership Development Program Description")

    second_program = Program(
        name="Cognitive Behavioral Therapy",
        description="Cognitive Behavioral Therapy Description")

    third_program = Program(name="New Parenting",
                            description="New Parenting Description")

    fourth_program = Program(name="Mindful Communication",
                             description="Mindful Communication Description")

    #First program's sections
    section_1 = Section(program_id=1,
                        name="Section 1 Program 1'",
                        description="Section 1 Program 1 Description",
                        order_index=1,
                        image_link="",
                        is_last=False)

    section_2 = Section(program_id=1,
                        name="Section 2 Program 1'",
                        description="Section 2 Program 1 Description",
                        order_index=2,
                        image_link="",
                        is_last=False)

    section_3 = Section(program_id=1,
                        name="Section 3 Program 1'",
                        description="Section 3 Program 1 Description",
                        order_index=3,
                        image_link="",
                        is_last=False)

    section_4 = Section(program_id=1,
                        name="Section 4 Program 1'",
                        description="Section 4 Program 1 Description",
                        order_index=4,
                        image_link="",
                        is_last=False)

    section_5 = Section(program_id=1,
                        name="Section 5 Program 1'",
                        description="Section 5 Program 1 Description",
                        order_index=5,
                        image_link="",
                        is_last=False)

    section_6 = Section(program_id=1,
                        name="Section 6 Program 1'",
                        description="Section 6 Program 1 Description",
                        order_index=6,
                        image_link="",
                        is_last=False)

    section_7 = Section(program_id=1,
                        name="Section 7 Program 1'",
                        description="Section 7 Program 1 Description",
                        order_index=7,
                        image_link="",
                        is_last=False)

    section_8 = Section(program_id=1,
                        name="Section 8 Program 1'",
                        description="Section 8 Program 1 Description",
                        order_index=8,
                        image_link="",
                        is_last=False)

    section_9 = Section(program_id=1,
                        name="Section 9 Program 1'",
                        description="Section 9 Program 1 Description",
                        order_index=9,
                        image_link="",
                        is_last=False)

    section_10 = Section(program_id=1,
                         name="Section 10 Program 1'",
                         description="Section 10 Program 1 Description",
                         order_index=10,
                         image_link="",
                         is_last=False)

    activity_1 = Activity(section_id=1,
                          html_content="",
                          question="Question Activity 1")

    activity_2 = Activity(section_id=2,
                          html_content="<html></html>",
                          question="")

    answer_1 = Answer(activity_id=1, answer_text="Activity 1 Answer Text")

    db.session.add_all([
        first_program, second_program, third_program, fourth_program,
        section_1, section_2, section_3, section_4, section_5, section_6,
        section_7, section_8, section_9, section_10, activity_1, activity_2,
        answer_1
    ])
    db.session.commit()