Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /branches/ein16/synth/d2/write.py
ViewVC logotype

View of /branches/ein16/synth/d2/write.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4458 - (download) (as text) (annotate)
Sat Aug 27 19:52:38 2016 UTC (2 years, 9 months ago) by cchiw
File size: 5380 byte(s)
fixed typos
import sys
import re
import os

from obj_counter import *
from obj_frame import  *

fld="stash"  #directory to save programs

##################################################################################################
def Title_inner(opr_inner):
    return "\n\n"+" "+opr_inner.name+"_ * |"+str(opr_inner.id)+"_ *"

def Title_outer(opr_inner, opr_outer):
    return "\n "+opr_outer.name+ "_"+ opr_inner.name+" |"+str(opr_inner.id)+"_"+str(opr_outer.id)

def Title_outer2(opr_outer):
    return "\n"+ "* _"+ opr_outer.name+" |* _"+str(opr_outer.id)+"\n"

def Title_num(opr_inner, opr_outer):
    return "\n"+opr_outer.name+ "_"+ opr_inner.name+" |"+str(opr_inner.id)+"_"+str(opr_outer.id)
def write(e):
    print (e)
def writeall(e):
    #print (e)
    # if it works continue
    f = open(fld+"/results_final.txt", 'a+')
    f.write(e)
    f.close()
def writesummary(e):
    #print (e)
    # if it works continue
    f = open(fld+"/results_summary.txt", 'a+')
    f.write(e)
    f.close()

def writetys(e):
    #print (e)
    # if it works continue
    f = open(fld+"/results_ty.txt", 'a+')
    f.write(e)
    f.close()

def writeex(e):
    print (e)
    # if it works continue
    f = open(fld+"/results_ex.txt", 'a+')
    f.write(e)
    f.close()

def write_outer(e):
    print (e)
    # if it works continue
    f = open(fld+"/results_outer.txt", 'a+')
    f.write(e)
    f.close()

def write_terrible(e):
    print (e)
    # if it works continue
    f = open(fld+"/results_terrible.txt", 'a+')
    f.write(e)
    f.close()


def writeTitle_inner(opr_inner):
    y = Title_inner(opr_inner)
    writetys(y)
    writeall(y)

def writeTitle_outer2(opr_outer):
    y = Title_outer2(opr_outer)
    writetys(y)
    writeall(y)


def writeTitle_outer(opr_inner, opr_outer):
    y = Title_outer(opr_inner, opr_outer)
    writetys("\n"+y)
    writeall(y)



def writeCumulative(cnt):
    # get cumulative breakdown
    x = counter.writeCumulativeS(cnt)
    print (x)
    writeall(x)
    writesummary(x)


def write_results(pre, testing_frame, cnt):
    # global variables needed from testing framework
    g_branch = frame.get_branch(testing_frame)
    x= "\n"
    x+= pre+"- "+g_branch
    x+=  counter.writeLocal(cnt)
    x+="\n***************************************************\n"
    writeall(x)
    writesummary(x)


def writeResults_inner(opr_inner, testing_frame, cnt):
    y = Title_inner(opr_inner)
    write_results(y, testing_frame, cnt)
    writeCumulative(cnt)

def writeResults_outer(opr_inner, opr_outer, testing_frame, cnt):
    y = Title_outer(opr_inner, opr_outer)
    write_results(y, testing_frame, cnt)
    writeCumulative(cnt)
## starts with writing heading in each txt file
def write_heading(testing_frame):
    name = "\n-name: "+frame.get_name(testing_frame)
    runtimepath = "\n-runtimepath: "+ frame.transform_runtimepath(testing_frame)
    coeff_style = "\n-coeff: "+frame.get_coeff_style(testing_frame)
    samples = "\n-samples: "+str(frame.get_samples(testing_frame))
    branch = "\n-branch: "+frame.get_branch(testing_frame)
    revision = "\n-revision: "+frame.get_revision(testing_frame)
    precision = "\n-precision:"+frame.get_precision(testing_frame)
    num_pos = "\n-number of positions:"+str(frame.get_num_pos(testing_frame))
    r = "\n\n----- Testing framework -----"+name+coeff_style+(samples)+ num_pos+branch+ precision+revision+runtimepath+"\n"
    writeall(r)
    writesummary(r)
    write_terrible(r)



# copy programs and corresponding file to new directory
def writeToRst(names, observed_data, correct_data, branch, rst):
    path = fld+"/"+names
    os.system("mkdir "+path)
    os.system("cp data/output5_p_observ.diderot "+path+"/"+names+".diderot")
    os.system("cp output5_p_observ.diderot "+path+"/"+names+".diderot")
    os.system("cp data/inputfile_0.nrrd "+path+"/inputfile_0.nrrd")
    os.system("cp data/inputfile_1.nrrd "+path+"/inputfile_1.nrrd")
    #os.system("cp data/inputfilecat_2.nrrd "+path+"/inputfilecat_2.nrrd")
    os.system("cp data/inputfile_2.nrrd "+path+"/inputfile_2.nrrd")
    a= names
    b= "\n\nobserved data from "+branch+" "+str(observed_data)
    # correct values from python
    c= "\n\ncorrect data from python"+str(correct_data)
   
    f = open(path+"/rst.txt", 'w+')
    f.write(a+b+c+rst+"\n\n")
    f.close()



def write_rst(names, x, extraname, phrase):
    x = "\n\t-"+x+"\n\t"+phrase
    m = "\n\n***"+ phrase+"__"+names +"\n\t -: " + extraname+x
    writeall(x)
    writesummary(x)
    write_terrible(m)
    print (x)
    return



# does not compile
def rst_compile(names, x, extraname,  branch):
    dir = "c"
    write_rst(names, x, extraname, "did not compile")
    labl = dir+"__"+names
#writeToRst(labl, None, None, branch, x)

# not available
def rst_NA(names, x, extraname, branch):
    dir = "na"
    labl = dir+"__"+names
    write_rst(names, x, extraname, "NA")
#writeToRst(labl, None, None, branch, x)

# check results
def rst_check(names, x, extraname, branch, observed_data, correct_data):
    dir = "k"
    labl = dir+"__"+names
    write_rst(names, x, extraname, "check")
    #writeToRst(labl, observed_data, correct_data, branch, x)
def rst_terrible(names, x, extraname,  branch, observed_data, correct_data) :
    dir = "t"
    labl = dir+"__"+names
    write_rst(names, x, extraname, "terrible")
    #writeToRst(labl, observed_data, correct_data, branch, x


root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0