Exemplo n.º 1
0
def load_hit_helper(label, input2, question2, properties2, comment):
    if comment != None:
        fname = log_root + "/" + label + "_" + comment + ".comment"
        tools.my_write(fname, "blah")
    st = "loadHITs -input " + input2 + " -question " + question2 + " -properties " + properties2 + " -label " + label
    text = tools.my_run(st, turk_root)
    my_log("[LOAD HIT] " + st + "\nLABEL: " + label + "\n" + text)
    shutil.move(turk_root + "/" + label + ".success",
                log_root + "/" + label + ".success")
    #now find errors, try to reload 10 times
    #    for i in range(10):
    #        etxt = text.split("[ERROR] Error creating HIT ")[1:]
    #        errors = [int(a[:a.find(" ")]) for a in etxt]
    #        n = len(errors)
    #        if n==0:
    #            return (label,text)
    #        for i in range(n):
    #            print "...trying to fix ",etxt[i][:30]
    #            input3=input2+"_temp.input"
    #            s = tools.my_read(input2).splitlines()
    #            s2 = [s[0]]+[s[i] for i in errors]
    #            print "new inputs:",s2
    #            s3 = string.join(s2,"\n")
    #            tools.my_write(input3,s3)
    #            st = "loadHITs -input "+input3+" -question "+question2+" -properties "+properties2+" -label "+label
    #            text = tools.my_run(st,turk_root)
    #            my_log("[LOAD HIT] "+st+"\nLABEL: "+label+"\n"+text)
    #            shutil.move(turk_root+"/"+label+".success",log_root+"/"+label+".success")
    #
    #
    #    for i in range(10):
    #        print "*** FAILED TO LOAD ALL HITS!"
    return (label, text)
Exemplo n.º 2
0
Arquivo: turk.py Projeto: omert/simexp
def load_hit_helper(label,input2, question2, properties2, comment):
    if comment!=None:
        fname = log_root+"/"+label+"_"+comment+".comment"
        tools.my_write(fname,"blah")
    st = "loadHITs -input "+input2+" -question "+question2+" -properties "+properties2+" -label "+label
    text = tools.my_run(st,turk_root)
    my_log("[LOAD HIT] "+st+"\nLABEL: "+label+"\n"+text)   
    shutil.move(turk_root+"/"+label+".success",log_root+"/"+label+".success")    
    #now find errors, try to reload 10 times
#    for i in range(10):
#        etxt = text.split("[ERROR] Error creating HIT ")[1:]
#        errors = [int(a[:a.find(" ")]) for a in etxt]
#        n = len(errors)
#        if n==0:
#            return (label,text)
#        for i in range(n):
#            print "...trying to fix ",etxt[i][:30]
#            input3=input2+"_temp.input"
#            s = tools.my_read(input2).splitlines()
#            s2 = [s[0]]+[s[i] for i in errors]
#            print "new inputs:",s2
#            s3 = string.join(s2,"\n")
#            tools.my_write(input3,s3)
#            st = "loadHITs -input "+input3+" -question "+question2+" -properties "+properties2+" -label "+label
#            text = tools.my_run(st,turk_root)
#            my_log("[LOAD HIT] "+st+"\nLABEL: "+label+"\n"+text)   
#            shutil.move(turk_root+"/"+label+".success",log_root+"/"+label+".success")    
#            
#            
#    for i in range(10):
#        print "*** FAILED TO LOAD ALL HITS!"
    return (label,text)
Exemplo n.º 3
0
def doppel_trips(S, trips, radius):
    lps = posts(S, trips, readem=True)  #posterior distribution
    n = S.shape[0]
    st = "<html><head></head><body><table>"
    for a in range(100):
        prior = np.array([2**(lps[a, a] - lps[a, j]) for j in range(n)])
        prior[a] = 0
        prior /= sum(prior)
        # p is posteriors
        for rrr in range(300):
            b = random.randrange(n)
            c = random.randrange(n)
            if b == c or b == a or c == a:
                continue
            #evaluate quality of trip a b c for a's uncertainty
            pb = 0.
            for j in range(n):
                pb += prior[j] * p(S, j, b, c)
            pc = 1 - pb
            u = 0
            for j in range(n):
                t = p(S, j, b, c)
                if t > 1:
                    print "UH OH: ", j, b, c, S[j, j] + S[
                        b, b] - 2. * S[j, b], S[j, j] + S[b, b] - 2. * S[j, b]
                if prior[j] > 1e-17:
                    u += prior[j] * t * np.log2(
                        pb / (prior[j] * t)) + prior[j] * (1 - t) * np.log2(
                            pc / (prior[j] * (1 - t)))
            if rrr == 0 or u < best:
                best = u
                bestb = b
                bestc = c
                bestpb = pb
        print "Best entropy", best
        st += "<tr>"
        st += '<td><img src="' + im_filename(a) + '"></td>'
        st += '<td><img src="' + im_filename(bestb) + '"></td>'
        st += '<td><img src="' + im_filename(bestc) + '"></td>'
        st += '<td><table border=1>'
        b = bestb
        c = bestc
        t = [(prior[j] * (p(S, j, b, c) - bestpb), j) for j in range(n)]
        t.sort()
        st += '<tr>'
        for j in range(20):
            st += '<td><img src="' + im_filename(t[j][1]) + '" alt="' + str(
                t[j][0]) + '"></td>'
        st += '</tr>'
        st += '<tr>'
        for j in range(20):
            st += '<td><img src="' + im_filename(
                t[-j - 1][1]) + '" alt="' + str(t[-j - 1][0]) + '"></td>'
        st += '</tr>'
        st += "</table></td></tr>\n"
        tools.my_write("c:/temp/doppels_exp" + str(radius) + ".html",
                       st + "</table></body></html>")
        print "c:/temp/doppels_exp" + str(radius) + ".html"
Exemplo n.º 4
0
def load_hit_helper(label,input2, question2, properties2, comment):
    if comment!=None:
        fname = log_root+"/"+label+"_"+comment+".comment"
        tools.my_write(fname,"blah")
    st = "loadHITs -input "+input2+" -question "+question2+" -properties "+properties2+" -label "+label
    text = tools.my_run(st,turk_root)
    my_log("[LOAD HIT] "+st+"\nLABEL: "+label+"\n"+text)   
    shutil.move(turk_root+"/"+label+".success",log_root+"/"+label+".success")    
    return (label,text)
Exemplo n.º 5
0
def load_hit_helper(label, input2, question2, properties2, comment):
    if comment != None:
        fname = log_root + "/" + label + "_" + comment + ".comment"
        tools.my_write(fname, "blah")
    st = "loadHITs -input " + input2 + " -question " + question2 + " -properties " + properties2 + " -label " + label
    text = tools.my_run(st, turk_root)
    my_log("[LOAD HIT] " + st + "\nLABEL: " + label + "\n" + text)
    shutil.move(turk_root + "/" + label + ".success",
                log_root + "/" + label + ".success")
    return (label, text)
Exemplo n.º 6
0
def doppel_trips(S,trips):
    lps = posts(S,trips,readem=True) #posterior distribution
    n = S.shape[0]
    st = "<html><head></head><body><table>"  
    for a in range(n):
        prior = np.array([2**(lps[a,a]-lps[a,j]) for j in range(n)])
        prior[a]=0
        prior /= sum(prior)
        # p is posteriors
        for rrr in range(600):
            b = random.randrange(n)
            c = random.randrange(n)
            if b==c or b==a or c==a:
                continue
            #evaluate quality of trip a b c for a's uncertainty           
            pb = 0.
            for j in range(n):
                pb += prior[j]*p(S,j,b,c)
            pc = 1-pb    
            u = 0
            for j in range(n):
                t = p(S,j,b,c)
                if t>1:
                    print "UH OH: ",j,b,c,S[j,j]+S[b,b]-2.*S[j,b],S[j,j]+S[b,b]-2.*S[j,b]
                if prior[j]>1e-17:
                    u += prior[j]*t*np.log2(pb/(prior[j]*t)) + prior[j]*(1-t)*np.log2(pc/(prior[j]*(1-t)))
            if rrr==0 or u<best:
                best = u
                bestb = b
                bestc = c
                bestpb = pb
        print "Best entropy",best
        st+="<tr>"
        st+='<td><img src="'+im_filename(a)+'"></td>'
        st+='<td><img src="'+im_filename(bestb)+'"></td>'
        st+='<td><img src="'+im_filename(bestc)+'"></td>'
        st+='<td><table border=1>'
        b = bestb
        c = bestc
        t = [ (prior[j]*(p(S,j,b,c)-bestpb),j) for j in range(n)]
        t.sort()
        st+='<tr>'
        for j in range(20):
            st+='<td><img src="'+im_filename(t[j][1])+'" alt="'+str(t[j][0])+'"></td>'
        st+='</tr>'
        st+='<tr>'
        for j in range(20):            
            st+='<td><img src="'+im_filename(t[-j-1][1])+'" alt="'+str(t[-j-1][0])+'"></td>'
        st+='</tr>'
        st+="</table></td></tr>\n"
        tools.my_write("c:/temp/doppels_rel"+str(alpha)+".html",st+ "</table></body></html>")
        print "c:/temp/doppels_rel"+str(alpha)+".html"
Exemplo n.º 7
0
def fit_letters():
    print "Fitting twice-exhaustive letters"
    trips = read_out_files(glob.glob("c:/sim/turkexps/calibrialpha/*.out"))    
    print len(trips),"trips"
    S = grad_proj2(trips,trips,step_size=0.2,its=100)
    st = ""
    for i in range(len(S)):
        for j in range(len(S[i])):
            st+=str(S[i][j])
            if j!=len(S[i])-1:
                st+=" "
        if i!=len(S)-1:
            st+="\n"
    tools.my_write("c:/users/adum/simexp/data/calibrialpha/calibrialphas_fit.txt",st)
Exemplo n.º 8
0
def show_nn(S):
    n = S.shape[0]
    st = "<html><head></head><body><table border=1>"
    for i in range(n):
        st+="<tr>"
        dists = []
        for j in range(n):
            dists.append((S[i,i]+S[j,j]-2*S[i,j],j))
        dists.sort()
        for j in range(n/5):
            st+='<td><img src="'+im_filename(dists[j][1])+'"></td>'
        st+="</tr>\n"
    st+= "</table></body></html>"
    tools.my_write("c:/temp/nn.html",st)
Exemplo n.º 9
0
def show_nn(S):
    n = S.shape[0]
    st = "<html><head></head><body><table border=1>"
    for i in range(n):
        st += "<tr>"
        dists = []
        for j in range(n):
            dists.append((S[i, i] + S[j, j] - 2 * S[i, j], j))
        dists.sort()
        for j in range(n / 5):
            st += '<td><img src="' + im_filename(dists[j][1]) + '"></td>'
        st += "</tr>\n"
    st += "</table></body></html>"
    tools.my_write("c:/temp/nn.html", st)
Exemplo n.º 10
0
def fit_letters():
    print "Fitting twice-exhaustive letters"
    trips = read_out_files(glob.glob("c:/sim/turkexps/calibrialpha/*.out"))
    print len(trips), "trips"
    S = grad_proj2(trips, trips, step_size=0.2, its=100)
    st = ""
    for i in range(len(S)):
        for j in range(len(S[i])):
            st += str(S[i][j])
            if j != len(S[i]) - 1:
                st += " "
        if i != len(S) - 1:
            st += "\n"
    tools.my_write(
        "c:/users/adum/simexp/data/calibrialpha/calibrialphas_fit.txt", st)
Exemplo n.º 11
0
def show_posts(S,trips,readem=True):
    n = S.shape[0]
    st = "<html><head></head><body><table border=1>"
    lps = posts(S,trips,readem)
    for i in range(n):
        st+="<tr>"
        r = [(lps[i,j],j) for j in range(n)]
        r.sort()
        r = [(-10000,i)]+r
        ttt = np.array([2**(lps[i,i]-lps[i,j]) for j in range(n)])
        ttt /= sum(ttt)
        for j in range(n):
            k=r[j][1]
            st+='<td><img alt="p '+str(ttt[k])+'" src="'+im_filename(k)+'"></td>'
        st+="</tr>\n"
    st+= "</table></body></html>"
    tools.my_write("c:/temp/posts.html",st)
Exemplo n.º 12
0
def show_posts(S, trips, readem=True):
    n = S.shape[0]
    st = "<html><head></head><body><table border=1>"
    lps = posts(S, trips, readem)
    for i in range(n):
        st += "<tr>"
        r = [(lps[i, j], j) for j in range(n)]
        r.sort()
        r = [(-10000, i)] + r
        ttt = np.array([2**(lps[i, i] - lps[i, j]) for j in range(n)])
        ttt /= sum(ttt)
        for j in range(n):
            k = r[j][1]
            st += '<td><img alt="p ' + str(
                ttt[k]) + '" src="' + im_filename(k) + '"></td>'
        st += "</tr>\n"
    st += "</table></body></html>"
    tools.my_write("c:/temp/posts.html", st)
Exemplo n.º 13
0
def check_results(label=None, outfile=None, init_trips=None):
    g = get_results(label)
    trips, mis = results2tripsplus(label)
    bad_wids, really_bad_wids = get_bad_wids(trips)
    print len(bad_wids), "bad workers and ", len(
        really_bad_wids), "really bad workers"
    amdone = (g.find("100%") != -1)
    if amdone:
        hitids = {}
        for i in mis:
            hitids[i] = 0
        for (a, b, c, e, wid, hid) in trips:
            hitids[hid] = 0
        for (a, b, c, e, wid, hid) in trips:
            if wid not in bad_wids:
                hitids[hid] += 1
        redo = []
        for hid in hitids:
            if hitids[hid] == 0:
                redo.append(hid)


#        if len(redo)>0:
#            amdone = False
#            print "About to redo",len(redo),"hits."
#            print "You have 10 seconds to kill job"
#            time.sleep(10)
#            redo_work(hitids = redo,label = label)
    if outfile != None:
        assert init_trips != None
        t = []
        for (a, b, c, e, wid, hid) in trips:
            if wid not in bad_wids and a != b and a != c:
                t.append((a, b, c, e))
        random.shuffle(t)
        t2 = []

        s = ""
        for (a, b, c, e) in t:
            s += str(a) + " " + str(b) + " " + str(c) + " " + str(e) + "\n"
        tools.my_write(outfile, s)

    return amdone, really_bad_wids
Exemplo n.º 14
0
Arquivo: turk.py Projeto: omert/simexp
def redo_work(wids=[],hitids=[],label=None):
    label = label or get_last_label()
    file = open(log_root+"/"+label+".results","r")
    blah = csv.DictReader(file,delimiter='\t')
    st = "hitid\thittypeid\n"
    for r in blah:
        wid = r['workerid']
        if r['hitid'] in hitids:
            st+=r['hitid']+"\t"+r['hittypeid']+"\n"
            hitids.remove(r['hitid'])
        else:
            if wid in wids:
                st+=r['hihttp://www.mturk.com/mturk/preview?groupId=1DS91QNJYJ9DKY1BZYKGZ13YD5OGVLtid']+"\t"+r['hittypeid']+"\n"
        
    file.close()
    sfname = log_root+"/"+label+"_temp.success"
    tools.my_write(sfname,st)
    st = "extendHITs -assignments 1 -hours 24 -successfile " + sfname
    text = tools.my_run(st,turk_root).strip()    
    my_log("[EXTEND_HITS]"+st+text+"\n")
    return st+"\n"+text+"\n"
Exemplo n.º 15
0
Arquivo: turk.py Projeto: omert/simexp
def check_results(label=None,outfile=None,init_trips=None):
    g = get_results(label)
    trips,mis = results2tripsplus(label)
    bad_wids, really_bad_wids = get_bad_wids(trips)
    print len(bad_wids),"bad workers and ",len(really_bad_wids),"really bad workers"
    amdone= (g.find("100%")!=-1)
    if amdone:
        hitids = {}
        for i in mis:
            hitids[i]=0
        for (a,b,c,e,wid,hid) in trips:
            hitids[hid]=0
        for (a,b,c,e,wid,hid) in trips:
            if wid not in bad_wids:
                hitids[hid]+=1
        redo = []
        for hid in hitids:
            if hitids[hid]==0:
                redo.append(hid)
#        if len(redo)>0:
#            amdone = False
#            print "About to redo",len(redo),"hits."
#            print "You have 10 seconds to kill job"
#            time.sleep(10)
#            redo_work(hitids = redo,label = label)
    if outfile!=None:
        assert init_trips!=None
        t = []
        for (a,b,c,e,wid,hid) in trips:
            if wid not in bad_wids and a!=b and a!=c:
                t.append((a,b,c,e))
        random.shuffle(t)
        t2 = []
        
        s = ""
        for (a,b,c,e) in t:
            s+=str(a)+" "+str(b)+" "+str(c)+" "+str(e)+"\n"
        tools.my_write(outfile,s)

    return amdone, really_bad_wids
Exemplo n.º 16
0
def load_external_hit(url="http://65.215.1.20/faces/simp_sim3.py",
                      assignments=1,
                      input="1",
                      title="A nice HIT",
                      description="Please help with our AI task",
                      reward="0.15",
                      duration=900,
                      autoapproval=259200,
                      approvalrate=95,
                      height=500,
                      keywords="image, similarity",
                      numapproved=48,
                      comment=None):
    ell = locals()
    label = get_next_label()
    input2 = log_root + "/" + label + ".input"
    question2 = log_root + "/" + label + ".question"
    properties2 = log_root + "/" + label + ".properties"
    itmpl = tools.my_read(input_template)
    qtmpl = tools.my_read(question_template)
    ptmpl = tools.my_read(properties_template)
    st = string.Template(itmpl).substitute(ell)
    tools.my_write(input2, input_shortcutifier(st))
    st = string.Template(qtmpl).substitute(ell)
    tools.my_write(question2, st)
    st = string.Template(ptmpl).substitute(ell)
    tools.my_write(properties2, st)
    return load_hit_helper(label, input2, question2, properties2, comment)
Exemplo n.º 17
0
def redo_work(wids=[], hitids=[], label=None):
    label = label or get_last_label()
    file = open(log_root + "/" + label + ".results", "r")
    blah = csv.DictReader(file, delimiter='\t')
    st = "hitid\thittypeid\n"
    for r in blah:
        wid = r['workerid']
        if r['hitid'] in hitids:
            st += r['hitid'] + "\t" + r['hittypeid'] + "\n"
            hitids.remove(r['hitid'])
        else:
            if wid in wids:
                st += r[
                    'hihttp://www.mturk.com/mturk/preview?groupId=1DS91QNJYJ9DKY1BZYKGZ13YD5OGVLtid'] + "\t" + r[
                        'hittypeid'] + "\n"

    file.close()
    sfname = log_root + "/" + label + "_temp.success"
    tools.my_write(sfname, st)
    st = "extendHITs -assignments 1 -hours 24 -successfile " + sfname
    text = tools.my_run(st, turk_root).strip()
    my_log("[EXTEND_HITS]" + st + text + "\n")
    return st + "\n" + text + "\n"
Exemplo n.º 18
0
def create_data(dir,att,info_file,fit_file,data_file):
    x = tools.my_read(fit_file).strip().splitlines()
    x = [[float(zz) for zz in z.split()] for z in x]
    m = len(x)
    d = len(x[0])
    
    f = open(info_file,"r")
    csvr = csv.DictReader(f)
    y = [int(r[att]) for r in csvr]
    f.close()
    st = ""
    for i in range(m):
        if y[i]!=-100:
            if y[i]==1:
                st+="+1"
            else: #translate 0 to -1
                st+="-1" 
            for j in range(d):
                st+=" "+str(j+1)+":"+str(x[i][j])
            st+=" # "+str(i)
            st+="\n"
    st = st.strip()
    tools.my_write(data_file,st)   
    return (x,y)
Exemplo n.º 19
0
Arquivo: turk.py Projeto: omert/simexp
def load_external_hit(url="http://65.215.1.20/faces/simp_sim3.py",assignments=1,input="1",title="A nice HIT",description="Please help with our AI task",reward="0.15",duration=900,autoapproval=259200,approvalrate=95,height=500,keywords="image, similarity",numapproved=48,comment=None):    
    ell = locals()
    label = get_next_label()
    input2 = log_root+"/"+label+".input"
    question2 = log_root+"/"+label+".question"
    properties2 = log_root+"/"+label+".properties"
    itmpl=tools.my_read(input_template)
    qtmpl=tools.my_read(question_template)
    ptmpl=tools.my_read(properties_template)
    st = string.Template(itmpl).substitute(ell)
    tools.my_write(input2,input_shortcutifier(st))
    st = string.Template(qtmpl).substitute(ell)
    tools.my_write(question2,st)
    st = string.Template(ptmpl).substitute(ell)
    tools.my_write(properties2,st)
    return load_hit_helper(label,input2,question2,properties2, comment)
Exemplo n.º 20
0
def list_to_str(lst):
    res = "["
    for i in lst:
        if type(i)==list:
            res+=list_to_str(i)
        else:
            res+=str(i)
        res+=","
    if res[-1]==",":
        return res[:-1] + "]"
    return res+"]"
    
tree = []
inf = tools.my_read(infile).splitlines()
for line in inf:
    (a,b) = line.split(":")
    tree.append([a.split(),b.split()])
    
s+='var tree = '+list_to_str(tree)+";\n"
s+='var ids = ['
ids = tools.my_read(dataroot+"/"+db+"/ids.txt").splitlines()
for i in ids:
    s+='"'+i+'",'
s=s[:-1]
s+='];\n'

s+= '</script></head>\n'
s+= tools.my_read(htmlfile)
tools.my_write(outfile,s)
Exemplo n.º 21
0
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 30 19:12:38 2010

@author: adum
"""

import sys
import os
import glob  # needed for file globbing with wildcards
import tools, string

if len(sys.argv) == 1:
    sys.argv.append(os.getcwd())

for d in sys.argv[1:]:
    if os.path.exists(d + '\\ids.txt'):
        continue
    os.chdir(d)
    lst = glob.glob('*.jpg') + glob.glob('*.png')
    assert (len(lst) > 0)
    #no jpegs in directory?
    tools.my_write(d + '\\ids.txt', string.join(lst, '\n'))
    print "Created " + d + '\\ids.txt, ' + str(len(lst)) + " distinct ids"
Exemplo n.º 22
0
TSPLIB_format()

tools.my_run("lkh MyFonts.par","c:/sim/tsp")

tour = tools.my_read("c:/sim/tsp/MyFonts.tour").strip().splitlines()
tour = tour[6:-2]
tour = [int(i)-1 for i in tour]
#real_tour = []
#for i in tour:
#    if i<5:
#        real_tour.append(i)
#    if i>5:
#        real_tour.append(i-1)
#tour=real_tour
print tour

fonts3 = []
for i in range(len(fonts2)):
    fonts3.append(fonts2[tour[i]])

s= "<html><head></head><body><table cellpadding=100><td>"

s+=draw_fonts(fonts2,"Alphabetical")
s+="</td><td>"
s+=draw_fonts(fonts3,"Human similarity")
s+="</td></table></body></html>\n"

tools.my_write("c:/sim/trees/fonts.html",s)


Exemplo n.º 23
0
print "Creating " + str(len(t)) + " hits..."

label, t = turk.load_external_hit(
    url="http://65.215.1.20/faces/simp_sim4.py?instructions=" + inst_shortcut,
    assignments=1,
    input=inp,
    title="Compare things to see which is most similar",
    description="Compare things and say which is more similar",
    reward=payment,
    duration=900,
    autoapproval=259200,
    approvalrate=95,
    height=height,
    keywords="image, similarity",
    numapproved=48,
    comment=comment)

tools.my_write(turk.log_root + + "/" + label + ".out_file_loc", sys.argv[3])
shutil.copy(sys.argv[2], turk.log_root + + "/" + label + ".trips")
shutil.copy(sys.argv[1], turk.log_root + + "/" + label + ".config2")

print "**** The ID of this batch is ", label

print "Waiting 2 minutes"

time.sleep(120)

#label=None
turk.check_til_done(label, sys.argv[3], trips)  #outfile
Exemplo n.º 24
0

s=""
for i in range(163):
    s+=str(i)+"_"
    
    
print s
exit(0)

imgs2 = []
for p in range(2,4):
    url = urlstring.replace("pG",str(p))
    print url
    html = tools.my_url_open(url).read()
    #print html
    imgs = html.split("AA160_.jpg")
    
    for im in imgs[:-1]:
        if im.rfind("http:")!=-1:
            imgs2.append(im[im.rfind("http:"):]+"AA160_.jpg")
    
    st = "<html>"
    for i in imgs2:
        st+="<img src='"+i+"'>\n "
    tools.my_write('c:/temp/tiles/massive2.html',st)
    
    print "Page ",p,"got ",len(imgs2),"images"
    time.sleep(2)

Exemplo n.º 25
0
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 30 19:12:38 2010

@author: adum
"""

import sys
import os
import glob                     # needed for file globbing with wildcards
import tools, string

if len(sys.argv)==1:
    sys.argv.append(os.getcwd())
    
for d in sys.argv[1:]:
    if os.path.exists(d+'\\ids.txt'):
        continue
    os.chdir(d)
    lst = glob.glob('*.jpg')+glob.glob('*.png')
    assert(len(lst)>0); #no jpegs in directory?
    tools.my_write(d+'\\ids.txt',string.join(lst,'\n'))
    print "Created "+d+'\\ids.txt, '+str(len(lst))+" distinct ids"

Exemplo n.º 26
0
import tools, time
from PIL import Image

urlstring = "http://www.amazon.com/s/qid=1285958507/ref=sr_pg_pG?ie=UTF8&sort=-price&keywords=ties&bbn=1036592&rh=k%3Aties%2Cn%3A1036592%2Cn%3A%211036682%2Cp_6%3AA32FQKBE4XLKI7&page=pG"

a=tools.SimpleDisplay()

imgs2 = []
for p in range(66):
    html = tools.my_url_open(urlstring.replace("pG",str(p))).read()
    imgs = html.split("190,246_.jpg")
    
    for im in imgs[:-1]:
        if im.rfind("http:")!=-1:
            imgs2.append(im[im.rfind("http:"):]+"190,246_.jpg")
    
    st = "<html>"
    for i in imgs2:
        st+="<img src='"+i+"'>\n "
    tools.my_write('c:/temp/ties/massive2.html',st)
    
    print "Page ",p,"got ",len(imgs2),"images"
    time.sleep(2)

Exemplo n.º 27
0
#sys.argv = ["","c:/sim/font_sample.config","c:/sim/sample.trips","c:/sim/sample.out"]

#print "Usage: checktrips.py"
#print "or"
#print "checktrips.py batch_id, where batch_id is the integer id of the batch"

s = "<html><body>"

fnames = glob.glob(turk.log_root+"/*.results")
fnames = [f.replace("\\","/") for f in fnames]
idfnames = [ (int(filename[filename.rindex("/")+1:-8]),filename) for filename in fnames]
idfnames.sort()
for (id,filename) in idfnames:
    s+="<h2>"+str(id)+"</h2>"
    file = open(filename,"r")
    blah = csv.DictReader(file,delimiter='\t')
    c = []
    for r in blah:
        if 'Answer.comment' in r and r['Answer.comment']!=None and len(r['Answer.comment'])>2:
            c.append((len(r['Answer.comment']),r['Answer.comment']))
    c.sort()
    for (a,b) in c:
        s+=b+"<br>"
    file.close()

s+= "</body></html>"

tools.my_write(turk.log_root+"/"+commentfile,s)

print s
Exemplo n.º 28
0
label,t = turk.load_external_hit(url="http://65.215.1.20/faces/simp_sim4.py?instructions="+inst_shortcut,
                                 assignments=reps,
                                 input=inp,
                                 title="Compare things to see which is most similar",
                                 description="Compare things and say which is more similar",
                                 reward=payment,
                                 duration=900,
                                 autoapproval=259200,
                                 approvalrate=95,
                                 height=height,
                                 keywords="image, similarity",
                                 numapproved=48,
                                 comment=comment)    


tools.my_write(turk.log_root+"/"+label+".out_file_loc",sys.argv[3])
shutil.copy(sys.argv[2],turk.log_root+"/"+label+".trips")
shutil.copy(sys.argv[1],turk.log_root+"/"+label+".config2")


print "**** The ID of this batch is ",label

print "Waiting 2 minutes"

time.sleep(120)



#label=None
turk.check_til_done(label,sys.argv[3],trips) #outfile
Exemplo n.º 29
0
import tools, time
from PIL import Image

urlstring = "http://www.amazon.com/gp/search/ref=sr_hi_4?rh=n:228013,n:!468240,n:551240,n:13397641,n:324030011&bbn=324030011&sort=pmrank&ie=UTF8&qid=1286037602#/ref=sr_pg_4?rh=n%3A228013%2Cn%3A%21468240%2Cn%3A551240%2Cn%3A13397641%2Cn%3A324030011%2Cp_6%3AA3KN51DK5IJ2IF&page=pG&bbn=324030011&sort=pmrank&ie=UTF8&qid=1286037702"

a = tools.SimpleDisplay()

imgs2 = []
hout = '<html><head></head><frameset rows="200px'
for i in range(20):
    hout += ",200px"
hout += '">\n'
for p in range(24, 40):
    url = urlstring.replace("pG", str(p))
    hout += "<frame src='" + url + "'>"

hout += "</frameset></html>"
tools.my_write("c:/temp/tiles/frameit3.html", hout)
Exemplo n.º 30
0
#label=None
turk.wait_til_done(label)


trips2,mis = turk.results2tripsplus(label)
bad_wids, really_bad_wids = turk.get_bad_wids(trips2)
print "bad wids",bad_wids
t = []
for (a,b,c,e,wid,hid) in trips2:
    if wid not in bad_wids:
        t.append((a,b,c,e))
random.shuffle(t)
t2 = []
for (a,b,c) in trips:
    found = False
    for i in range(len(t)):
        (x,y,z,e) = t[i]
        if x==a and (y==b and c==z or y==c and b==z):
            t2.append(t[i])
            t.pop(i)
            found = True
            break
    if found == False:
        #print "SHOOT!",(a,b,c)
        1

s = ""
for (a,b,c,e) in t2:
    s+=str(a)+" "+str(b)+" "+str(c)+" "+str(e)+"\n"
tools.my_write(sys.argv[3],s)
Exemplo n.º 31
0
#print "Usage: checktrips.py"
#print "or"
#print "checktrips.py batch_id, where batch_id is the integer id of the batch"

s = "<html><body>"

fnames = glob.glob(turk.log_root + "/*.results")
fnames = [f.replace("\\", "/") for f in fnames]
idfnames = [(int(filename[filename.rindex("/") + 1:-8]), filename)
            for filename in fnames]
idfnames.sort()
for (id, filename) in idfnames:
    s += "<h2>" + str(id) + "</h2>"
    file = open(filename, "r")
    blah = csv.DictReader(file, delimiter='\t')
    c = []
    for r in blah:
        if 'Answer.comment' in r and r['Answer.comment'] != None and len(
                r['Answer.comment']) > 2:
            c.append((len(r['Answer.comment']), r['Answer.comment']))
    c.sort()
    for (a, b) in c:
        s += b + "<br>"
    file.close()

s += "</body></html>"

tools.my_write(turk.log_root + "/" + commentfile, s)

print s
Exemplo n.º 32
0
import tools, time
from PIL import Image

urlstring = "http://www.amazon.com/gp/search/ref=sr_hi_4?rh=n:228013,n:!468240,n:551240,n:13397641,n:324030011&bbn=324030011&sort=pmrank&ie=UTF8&qid=1286037602#/ref=sr_pg_4?rh=n%3A228013%2Cn%3A%21468240%2Cn%3A551240%2Cn%3A13397641%2Cn%3A324030011%2Cp_6%3AA3KN51DK5IJ2IF&page=pG&bbn=324030011&sort=pmrank&ie=UTF8&qid=1286037702"

a=tools.SimpleDisplay()

imgs2 = []
hout = '<html><head></head><frameset rows="200px'
for i in range(20):
    hout+=",200px"
hout+='">\n'
for p in range(24,40):
    url = urlstring.replace("pG",str(p))
    hout+="<frame src='"+url+"'>"
    
hout+="</frameset></html>"
tools.my_write("c:/temp/tiles/frameit3.html",hout)

Exemplo n.º 33
0
#label=None
turk.wait_til_done(label)

trips2, mis = turk.results2tripsplus(label)
bad_wids, really_bad_wids = turk.get_bad_wids(trips2)
print "bad wids", bad_wids
t = []
for (a, b, c, e, wid, hid) in trips2:
    if wid not in bad_wids:
        t.append((a, b, c, e))
random.shuffle(t)
t2 = []
for (a, b, c) in trips:
    found = False
    for i in range(len(t)):
        (x, y, z, e) = t[i]
        if x == a and (y == b and c == z or y == c and b == z):
            t2.append(t[i])
            t.pop(i)
            found = True
            break
    if found == False:
        #print "SHOOT!",(a,b,c)
        1

s = ""
for (a, b, c, e) in t2:
    s += str(a) + " " + str(b) + " " + str(c) + " " + str(e) + "\n"
tools.my_write(sys.argv[3], s)
Exemplo n.º 34
0
def list_to_str(lst):
    res = "["
    for i in lst:
        if type(i) == list:
            res += list_to_str(i)
        else:
            res += str(i)
        res += ","
    if res[-1] == ",":
        return res[:-1] + "]"
    return res + "]"


tree = []
inf = tools.my_read(infile).splitlines()
for line in inf:
    (a, b) = line.split(":")
    tree.append([a.split(), b.split()])

s += 'var tree = ' + list_to_str(tree) + ";\n"
s += 'var ids = ['
ids = tools.my_read(dataroot + "/" + db + "/ids.txt").splitlines()
for i in ids:
    s += '"' + i + '",'
s = s[:-1]
s += '];\n'

s += '</script></head>\n'
s += tools.my_read(htmlfile)
tools.my_write(outfile, s)