Example #1
0
def insertVacancy(cursor, vacancy):
    print("in insert: ", vacancy)
    try:
        cursor.execute("INSERT INTO vacancies(id, \
                                              name, \
                                              premium, \
                                              has_test, \
                                              letter_required, \
                                              type, \
                                              employer_id, \
                                              created_at, \
                                              published_at, \
                                              requirement, \
                                              responsibility, \
                                              last_update, \
                                              job, \
                                              developer_experience) \
                        VALUES(" + str(vacancy['id']) + "," + "\'" +
                       vacancy['name'] + "\'," + str(vacancy['premium']) +
                       "," + str(vacancy['has_test']) + "," +
                       str(vacancy['response_letter_required']) + "," + "\'" +
                       str(vacancy['type']['id']) + "\'," +
                       str(vacancy['employer']['id']) + "," + "TIMESTAMP \'" +
                       str(vacancy['created_at']) + "\'," + "TIMESTAMP \'" +
                       str(vacancy['published_at']) + "\'," + "\'" +
                       str(vacancy['snippet']['requirement']) + "\'," + "\'" +
                       str(vacancy['snippet']['responsibility']) + "\'," +
                       "TIMESTAMP \'" + str(getTime().isoformat()) + "\'," +
                       "\'" + str(category(jobs, vacancy)) + "\', " + "\'" +
                       str(category(developer_experience, vacancy)) + "\');")
        cursor.execute("INSERT INTO employers(id, name) VALUES(" +
                       str(vacancy['employer']['id']) + ",\'" +
                       str(vacancy['employer']['name']) + "\') " +
                       "ON CONFLICT ON CONSTRAINT id_constr DO NOTHING;")
        # check if there's the same first
        if vacancy['address'] != "null":
            insertAddress(cursor, vacancy)
        if vacancy['contacts'] != "null":
            insertContact(cursor, vacancy)
        if vacancy['salary'] != "null":
            cursor.execute("UPDATE vacancies SET \
                                   salary_from = " +
                           str(vacancy['salary']['from']) + "," +
                           "salary_to = " + str(vacancy['salary']['to']) +
                           "," + "currency = " + "\'" +
                           vacancy['salary']['currency'] + "\'," + "gross = " +
                           str(vacancy['salary']['gross']) + " WHERE id =" +
                           vacancy['id'] + ";")
    except KeyError:
        print("Vacancy wasn't inserted")
    cursor.execute("SELECT * FROM vacancies;")
    print(cursor.fetchall())
    def get_by_id(self, id):
        cur = self.conn.cursor()
        cur.execute(
            """SELECT id, code, name, created_by FROM categories WHERE id=%s""",
            (id, ))
        row = cur.fetchone()
        cur.close()

        return category.category(row[0], row[1], row[2], row[3])
    def get_all(self):
        cur = self.conn.cursor()
        cur.execute("""SELECT id, code, name, created_by FROM categories""")
        rows = cur.fetchall()
        cur.close()

        categories = []

        for row in rows:
            categories.append(category.category(row[0], row[1], row[2],
                                                row[3]))

        return categories
Example #4
0
 def do_atom_category(self):
     return category()
Example #5
0
 def do_category(self):
   self.metadata()
   from category import category
   return category()
Example #6
0
 def do_category(self):
     return category()
Example #7
0
 def do_atom_category(self):
     from category import category
     return category()
Example #8
0
 def do_atom_category(self):
     self.metadata()
     from category import category
     return category()
Example #9
0
 def do_category(self):
     self.metadata()
     return category()
Example #10
0
def test():
    #holds the results
    results = []
    #defaults the percent value
    percent = 0.0
    #gets dictionary from filterNames
    subCategories = getNameFiles()
    #get the global variable data
    global data
    #get json file containing the imageString from android app
    data = request.get_json(cache=True)
    #get photo from data
    photo = data["photo"]
    #open photo and decode base64 string
    with open("test.png", mode="wb") as f:
        f.write(base64.b64decode(photo))
    #run modeil
    subCat = executeWithParameter("subcategoriesgraph.pp",
                                  "subcategorieslabels.txt", "test.png")
    #format subcategory to be upercase and get subcategory prediction
    subCat = subCat.get("prediction").title()
    #set empty variable to check if there is a valid solution
    predictionName = None
    #for each key and value in subcategories dictionary
    for key, value in subCategories.items():
        #TEST PRINT
        print(key)
        #TEST PRINT
        print(key == subCat)
        #if subcategory contains more than one name
        if key == subCat:
            #run model
            modelPredictionName = executeWithParameter(value[0], value[1],
                                                       "test.png")
            #get prediction value
            predictionName = modelPredictionName.get("prediction")
            #get prediction accuracy
            percent = modelPredictionName.get("accuracy")
            #TEST PRINT
            print("*********", percent)
            #format unique name
            predictionName = predictionName.title()
    #TEST PRINT
    print(subCat)
    #if subcategory predicts a value with only one unique name
    if subCat == "Air Conditioning":
        predictionName = "HVAC Unit"
        percent = 100
    elif subCat == "Fondant Warmer":
        predictionName = "Fondat Warmer"
        percent = 100
    elif subCat == "Ice Cream Machine":
        predictionName = "Ice Cream Machine"
        percent = 100
    elif subCat == "Ice Machine":
        predictionName = "Ice Machine"
        percent = 100
    elif subCat == "Juice Dispenser":
        predictionName = "Juicer"
        percent = 100
    elif subCat == "Lighting":
        predictionName = "Air Curtain"
        percent = 100
    elif subCat == "Microwave":
        predictionName = "Microwave"
        percent = 100
    elif subCat == "Reach In Cooler":
        predictionName = "Cooler (Reach In)"
        percent = 100
    elif subCat == "Walk In Coolers":
        predictionName = "Cooler (Walk In)"
        percent = 100
    elif subCat == "Walk In Freezers":
        predictionName = "Freezer (Walk In)"
        percent = 100
    elif subCat == "Water Heaters":
        predictionName = "Hot Water Heater"
        percent = 100
    #get top 5 predictions
    results = getResults()
    #reset results
    refreshResults()
    #TEST PRINT
    str(results)
    print(results)
    #if no prediction exists
    if predictionName == None:
        subCat = "Invalid"
    #get category name
    categoryName = category(subCat)
    # result = f'{"name":"{prediction}", "category":"Test", "subCat":"Sub_CAT", "brand":"", "model":"112131111", location:"On the left wall"}'
    #build json to be sent in response
    result = json.dumps({
        "name": predictionName,
        "category": categoryName,
        "subCat": subCat,
        "results": results,
        "percent": str(percent)
    })
    #result = json.dumps({"name": predictionName})
    #result = json.dumps({"category": categoryName})
    #close photo file
    f.close()
    #return JSON
    return result
Example #11
0
from category import category 

#S_1 = [{'title': 'Trump Bombs Mexico', 'summary': 'Trump'}]
#S_2 = [{'title': 'Trump Bombs Mexico', 'summary': 'Trump'}]

S_1 = [{'title': 'Trump Bombs Mexico', 'summary': 'Trump'}, {'title': 'Putin', 'summary': 'Putin'}, {'title': 'Trump Bombs BBC', 'summary': 'Trump'}, {'title': 'Putin Loves Snakes', 'summary': 'Putin'}]
S_2= [{'title': 'Putin', 'summary': 'Putin'}, {'title': 'Trump Bombs BBC', 'summary': 'Trump'}, {'title': 'Putin Loves Snakes', 'summary': 'Putin'}]
#S_2 = [{'title': 'Trump Bombs Mexico', 'summary': 'Trump'}, {'title': 'Putin', 'summary': 'Putin'}]

thresh = 30.0

new_var = category(S_1, S_2, thresh)

for n_list in new_var:
	print '----------'
	print n_list
	print
	for story in new_var[n_list]:
		print story
Example #12
0
 def do_category(self):
     return category()
Example #13
0
import dps_meminfo
import category
import time

import proc_meminfo

from pandas import Series, DataFrame, ExcelWriter

#p = sp.Popen("adb shell dumpsys -t 60 meminfo", shell=True, stdout=sp.PIPE, stderr=sp.STDOUT)
#p = sp.Popen("cat ./dpmeminfo.txt", shell=True, stdout=sp.PIPE, stderr=sp.STDOUT)
#dumpsys_meminfo = p.stdout.readlines()
#print dumpsys_meminfo

process = {}
oom_adj = oom_adj.oom_adj()
category = category.category()
dps_meminfo_0 = dps_meminfo.dps_meminfo(process, oom_adj, category)

#'''

df_OOM_ADJ = DataFrame()
df_OOM_ADJ_Persist = DataFrame()
df_category = DataFrame()
df_all = DataFrame()

writer = ExcelWriter('output.xlsx')
index = 0
Persist_len = 0

while index < 100:
    index = index + 1
nBlocks         = data['exptdesign']['numSessions'][0,0][0]
subjectName     = data['exptdesign']['subName'][0,0][0]

#############################################################################
#Calculations by Frequency Pair
#############################################################################

FS = FrequencySpecific(stimuli=stimuli)
mF, countTotal = FS.frequencyPair_parse(accuracy)
catA = FS.category_parse(accuracy)

#############################################################################
#Calculations by morph
#############################################################################

catObj = category(stimuli = stimuli)
RT, ACC = catObj.wrapper(accuracy, reactionTime)
pos_acc = catObj.parseData_freq_block(accuracy, stimuli)

#############################################################################
#Calculating mean acc and RT overall
#############################################################################
#calculate the mean overall accuracy by block
O_accuracy = []
iBlock = 0
for iBlock in range(accuracy.size):
    O_accuracy.append(np.mean([accuracy[0,iBlock]]))

#calculate the mean RT overall by block
O_reactionTime = []
iBlock = 0
Example #15
0
 def do_atom_category(self):
   return category()
Example #16
0
    def do_category(self):
        from category import category

        return category()
def CategoryTrainingFigure_Funnel(fileDirectory, filename, session):
    #Use when debugging or manually editing
    #filename      = ('20160630_1430-MR1040_block6')
    #fileDirectory = '/Users/courtney/GoogleDrive/Riesenhuber/05_2015_scripts/Vibrotactile/01_CategoryTraining/data/1040/'
    #session       = '2'

    #load matfile
    data = sio.loadmat(fileDirectory + filename, struct_as_record=True)

    #pull relevant data from structures
    reactionTime = data['trialOutput']['RT']
    sResp = data['trialOutput']['sResp']
    correctResponse = data['trialOutput']['correctResponse']
    accuracy = data['trialOutput']['accuracy']
    level = data['trialOutput']['level']
    stimuli = data['trialOutput']['stimuli']
    nTrials = data['exptdesign']['numTrialsPerSession'][0, 0][0]
    nBlocks = data['exptdesign']['numSessions'][0, 0][0]
    subjectName = data['exptdesign']['subName'][0, 0][0]

    #############################################################################
    #Calculations by Frequency Pair
    #############################################################################

    FS = FrequencySpecific(stimuli=stimuli)
    mF, countTotal = FS.frequencyPair_parse(accuracy)
    catA = FS.category_parse(accuracy)

    #############################################################################
    #Calculations by morph
    #############################################################################

    catObj = category(stimuli=stimuli)
    RT, ACC = catObj.wrapper(accuracy, reactionTime)
    pos_acc = catObj.parseData_freq_block(accuracy, stimuli)

    #############################################################################
    #Calculating mean acc and RT overall
    #############################################################################
    #calculate the mean overall accuracy by block
    O_accuracy = []
    iBlock = 0
    for iBlock in range(accuracy.size):
        O_accuracy.append(np.mean([accuracy[0, iBlock]]))

    #calculate the mean RT overall by block
    O_reactionTime = []
    iBlock = 0
    for iBlock in range(reactionTime.size):
        O_reactionTime.append(np.mean(reactionTime[0, iBlock]))

    #x-axis label
    x = []
    i = 0
    for i in range(accuracy.size):
        x.append("Block: " + str(i + 1) + ", Level: " +
                 str(level[0, i][0, 0])),

    #############################################################################
    #Generating figures
    #############################################################################

    #make trace containing each frequency pair
    x2 = [
        '[25,100]', '[27,91]', '[29,91]', '[31,83]', '[33,77]', '[36,71]',
        '[38,67]', '[40,62.5]', '[62.5, 40]', '[67, 38]', '[71, 36]',
        '[77, 33]', '[83, 31]', '[91, 29]', '[91, 27]', '[100, 25]'
    ]
    x3 = [
        '100%', '95%', '90%', '85%', '80%', '75%', '70%', '65%', '35%', '30%',
        '25%', '20%', '15%', '10%', '5%', '0%'
    ]
    x4 = ['[27,91]', '[40,62.5]', '[62.5, 40]', '[91, 27]']

    #trace_PG_ACC_7  = make_trace_bar(x4, [pos_acc[0][0], pos_acc[0][1], pos_acc[0][2], pos_acc[0][3]], 'pos3')
    trace_PG_ACC_7 = make_trace_bar(
        x4, [pos_acc[0], pos_acc[1], pos_acc[2], pos_acc[3]], 'pos3')

    trace_ACC_FP = make_trace_bar(x2, mF, '')

    #make trace containing acc and RT for morph
    prototypeAcc = [0] * (len(ACC) // 3)
    middleAcc = [0] * (len(ACC) // 3)
    boundaryAcc = [0] * (len(ACC) // 3)
    prototypeRT = [0] * (len(ACC) // 3)
    middleRT = [0] * (len(ACC) // 3)
    boundaryRT = [0] * (len(ACC) // 3)

    for i in range(len(ACC) // 3):
        prototypeAcc[i] = ACC[3 * i]
        middleAcc[i] = ACC[3 * i + 1]
        boundaryAcc[i] = ACC[3 * i + 2]
        prototypeRT[i] = RT[3 * i]
        middleRT[i] = RT[3 * i + 1]
        boundaryRT[i] = RT[3 * i + 2]

    trace1 = make_trace_bar(x, prototypeAcc, "Category Prototype Acc")
    trace2 = make_trace_bar(x, middleAcc, "Middle Morph Acc")
    trace3 = make_trace_bar(x, boundaryAcc, "Category Boundary Acc")
    trace4 = make_trace_line(x, prototypeRT, "Category Prototype RT", 'n')
    trace5 = make_trace_line(x, middleRT, "Middle Morph RT", 'n')
    trace6 = make_trace_line(x, boundaryRT, "Category Boundary RT", 'n')

    #make trace containing overall acc and rt
    trace7 = make_trace_line(x, O_accuracy, "Overall Accuracy", 'y')
    trace8 = make_trace_line(x, O_reactionTime, "Overall RT", 'n')

    # make categorization curve
    traceCatCurve = []
    for index, obj in enumerate(catA):
        traceCatCurve.append(make_trace_line(x3, obj, '', 'n'))

    # Generate Figure object with 2 axes on 2 rows, print axis grid to stdout
    fig = tls.make_subplots(rows=1, cols=1, shared_xaxes=True)
    fig_FP = tls.make_subplots(rows=1, cols=1, shared_xaxes=True)
    fig_CatCurve = tls.make_subplots(rows=1, cols=1)
    fig_pos = tls.make_subplots(rows=1, cols=1, shared_xaxes=True)

    #set figure layout to hold mutlitple bars
    fig['layout'].update(barmode='group',
                         bargroupgap=0,
                         bargap=0.25,
                         title=subjectName +
                         " Accuracy and RT By Morph Session " + session,
                         yaxis=dict(dtick=.1))

    xZip = x2[:len(x2)]
    yZip = countTotal

    fig_FP['layout'].update(barmode='group',
                            bargroupgap=0,
                            bargap=0.25,
                            title=subjectName +
                            " Accuracy By Frequency Pair, Session " + session,
                            yaxis=dict(dtick=.1),
                            annotations=[
                                dict(
                                    x=xZip[i],
                                    y=mF[i],
                                    showarrow=False,
                                    text=yZip[i],
                                    xanchor='center',
                                    yanchor='bottom',
                                ) for i in range(len(xZip))
                            ])

    fig_CatCurve['layout'].update(barmode='group',
                                  bargroupgap=0,
                                  bargap=0.25,
                                  title=subjectName +
                                  " Categorization Curve " + session,
                                  xaxis=dict(autorange='reversed',
                                             dtick=5,
                                             range=[0, 100],
                                             showgrid=True),
                                  yaxis=dict(range=[0, 100], dtick=5))

    fig_pos['layout'].update(barmode='group',
                             bargroupgap=0,
                             bargap=0.25,
                             title=subjectName + " Pos Accuracy RA stimuli " +
                             session,
                             yaxis=dict(dtick=.1))

    colorRA = [
        'black', 'blue', 'black', 'black', 'black', 'black', 'black', 'blue',
        'blue', 'black', 'black', 'black', 'black', 'black', 'blue', 'black'
    ]

    fig['data'] = [
        trace1, trace2, trace3, trace7, trace4, trace5, trace6, trace8
    ]
    fig_FP['data'] = [go.Bar(x=x2, y=mF, marker=dict(color=colorRA))]
    fig_CatCurve['data'] = [
        go.Scatter(x=x3, y=catA, name='SubjectData'),
        go.Scatter(x=[50, 50],
                   y=[0, 100],
                   name='Category Boundary',
                   line=dict(color='red'))
    ]
    fig_pos['data'] = [trace_PG_ACC_7]

    #bread crumbs to make sure entered the correct information
    print("Your graph will be saved in this directory: " + fileDirectory +
          "\n")
    print("Your graph will be saved under: " + filename + "\n")
    print("The session number you have indicated is: " + session + "\n")

    #save images as png in case prefer compared to html
    py.image.save_as(
        fig, fileDirectory + filename + "_CategTrainingMorphAccSession" +
        session + ".jpeg")
    py.image.save_as(
        fig_FP,
        fileDirectory + filename + "_FP_AccSession" + session + ".jpeg")
    py.image.save_as(
        fig_CatCurve,
        fileDirectory + filename + "_CatCurve_Session" + session + ".jpeg")
    #py.image.save_as(fig_pos, fileDirectory + filename + "_PosRA_ACC_Session" + session + ".jpeg")

    print("Done!")
Example #18
0
 def do_category(self):
     self.metadata()
     return category()