Example #1
0
 def __str__(self):
     return ('Data_Owner : %s, Min_Variation : %s,' +
     'Min_Value : %s, Min_Value : %s, Dis_Interval : %s') % (str(self._data_owner),
                                        str(self._min_variation),
                                        str(self._min_val),
                                        str(self._max_val),
                                        str(self._dis_interval))
def query_lowest(shreshold_price):
    title = ''
    content = ''
    isSendMail = False;
    try: 
        init_cookie()
        content = query_step1()
        parser_step1 = Setp1Parser()
        parser_step1.feed(content)
        result = query_step2(parser_step1.url, parser_step1.formData)
        title = u"new lowest price: " + result
        content = u"today lowest price is:" + result
        print u"lowest price:: " + result
        if float(result) < float(shreshold_price):
            isSendMail = True
    except Exception as e:
        isSendMail = True
        title = u"ticket error"
        content = str(e)
        print str(e)

    if isSendMail:
        return str(title) + "\n" + sendmail(title, content);
    else :
        return str(title) + "\n" + "Not send email"
Example #3
0
    def push(self, args):
        """
            Push is actually only a shortcut for bzr and git push commands
            that automatically takes care of using the correct repository url.

            It queries the deployment details and uses whatever is in branch.

            If deployment exists will clear the buildpack cache if
            --clear-cache flag is set.

            If no deployment exists we automatically create one.


        """
        if not check_installed_rcs("bzr") and not check_installed_rcs("git"):
            raise InputErrorException("NeitherBazaarNorGitFound")

        if args.deploy and args.ship:
            raise InputErrorException("ShipAndDeploy")

        app_name, deployment_name = self.parse_app_deployment_name(args.name)
        deployment, push_deployment_name = self._get_or_create_deployment(app_name, deployment_name, args.clear_cache)

        cmd = self._push_cmd(deployment, push_deployment_name, args.source)

        try:
            check_call(cmd)
        except CalledProcessError, e:
            print str(e)
            sys.exit(1)
Example #4
0
    def addFileParameters(self, source, source_path, params_data, params_for_request):
        if source == 'dropbox':
            params_data['dropbox_path'] = source_path
        else:  # path given by user is on local system
            files = self.filesInDirectory(source_path.rstrip('/'))
            i = 0

            if not exists(join(source_path.rstrip('/'), 'resized')):
                makedirs(join(source_path.rstrip('/'), 'resized'))
                chmod(join(source_path.rstrip('/'), 'resized'), 0776)

            self.resize(files, join(source_path.rstrip('/'), 'resized'), source_path)

            if len(files) > 50:
                raise Exception("No. of files is more than the specified limit:50")
            if len(files) == 0:
                raise Exception("No of images in the directory is zero. "
                                "Please check the path, and the extension of the files present.")
            print 'No of files to be uploaded: ',len(files)
            for f in files:
                params_for_request['file' + str(i)] = open(source_path+'/resized/'+f, 'rb')
                #params_for_request['file' + str(i)] = self.openFile(source_path+'/resized/'+f)
                i += 1


            #print params_for_request
            params_data['count'] = str(len(files))
Example #5
0
def decode_version_byte(ecnKeyInput,outputVersion=False):
    """
    Strips version byte from a '6V' encrypted private key.
    Optionally, returns the version byte in addition to the
    6P non-version key output.

    >>> decode_version_byte("6VC7VZmC7nP6XdUDFyd9VbMeN9CokzqzkPn8aZDF9xMdUkZWETAFB8EJUEgA")
    '6PRQvv84z2zaLJHt96j7LNuCXUt1z8FTY76MAzRUJuNVHPTrwASw8SA5bJ'
    >>> decode_version_byte("6VC7VZmC7nP6XdUDFyd9VbMeN9CokzqzkPn8aZDF9xMdUkZWETAFB8EJUEgA",True)
    ('6PRQvv84z2zaLJHt96j7LNuCXUt1z8FTY76MAzRUJuNVHPTrwASw8SA5bJ', '80')
    >>> decode_version_byte("6VHZKGUhVJi6XUc3JiFAVNpbJ4of1k2oXU9JwYeDjp6RSyMEGhR4yEZTeZpi")
    '6PgMhJbWE3chLKeWF2YhpDURxR4uWKGtxby6Amx7ttcJJbP7PK6ga8c8Mj'
    """

    try:
        encKeyHex, isValid = base58_decode(ecnKeyInput,True,False)
    except:
        raise TypeError("Input must be encrypted private key str beginning with '6V'.")
    if ecnKeyInput[:2] != '6V' or len(ecnKeyInput) != 60:
        raise TypeError("Input is not a version-encrypted private key str beginning with '6V'.")
    if not isValid:
        raise Exception("Input private key checksum failed on base58 decode attempt. Check for typos.")
    encKeyHex = hex_to_hexstr(encKeyHex)
    if encKeyHex[:3] == '10d':
        newFirstBytes = '0142'
    elif encKeyHex[:3] == '10e':
        newFirstBytes = '0143'
    else:
        raise Exception("Unknown error with input.")
    outputHexStr = str(newFirstBytes) + encKeyHex[6:]
    if outputVersion:
        return base58_check_and_encode(outputHexStr), str(encKeyHex[4:6])
    else:
        return base58_check_and_encode(outputHexStr)
Example #6
0
def execTask(commandLine):
    result=None
    cmdList=commandLine #.split()
    try:
        funcName=cmdList[0]
        funcArgs=cmdList[1:]
    except:
        return None
    for i,arg in enumerate(funcArgs):
        try:
            funcArgs[i]=eval(arg) # Try parsing parameters as numbers, if possible
        except:
            pass
    if QUIET:
        try:
            result = callableTasks[funcName]['func'](callableTasks[funcName]['inst'],*funcArgs)
        except Exception as e:
            print ('Error while executing %s %s'%(funcName,str(funcArgs)))
            print ("QUIET=%d"%QUIET)
            try:
                funcFArgs= callableTasks[funcName]['args']
            except:
                print ("Unknown task: %s"%(funcName))
                return None
            sFuncArgs=""
            if funcFArgs:
                sFuncArgs+='<'+str(funcFArgs[0])+'>'
            for a in funcFArgs[1:]:
                sFuncArgs+=' <'+str(a)+'>'
            print ("Usage:\n%s %s"%(funcName,sFuncArgs))
            print ("exception message:"+str(e))
    else:
        result = callableTasks[funcName]['func'](callableTasks[funcName]['inst'],*funcArgs)
    return result
Example #7
0
 def visita(self):
     print "Visitou:",self.chave,"(Nível "+str(self.h)+")",
     if self.esq:
         print "|| esq:",str(self.esq.chave)+"("+str(self.esq.h)+")",
     if self.dir:
         print "|| dir:",str(self.dir.chave)+"("+str(self.dir.h)+")",
     print
Example #8
0
def loginToInterface(isMac, chrome, driver, host, port=8686, username='******', password='******'):
    logCommon.info('Will start web browser and perform test case.')
    chromeDriver = os.path.normpath(driver)
    logCommon.info('Browser driver path: ' + str(chromeDriver))
    os.environ["webdriver.chrome.driver"] = chromeDriver
    opts = Options()
    if (not isMac):
        opts = Options()
        opts.binary_location = os.path.normpath(chrome)
    else:
        opts.add_argument("--start-maximized")
    driver = webdriver.Chrome(chromeDriver, chrome_options=opts)
    # options.add_argument("--start-maximized")
    # driver.set_window_size(1024, 600)
    driver.maximize_window()
    # go to the google home page
    index = 'http://' + str(host) + ':' + str(port) + '/XOAM/login/index.html'
    logCommon.info('Web page: ' + str(index))
    driver.get(index)
    driver.find_element_by_id('loginUsername').clear()
    driver.find_element_by_id('loginUsername').send_keys(username)
    driver.find_element_by_id('loginPassword').clear()
    driver.find_element_by_id('loginPassword').send_keys(password)
    driver.find_element_by_id('submit').click()
    try:
        WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, "ebBtnSearch")))
        logCommon.info('Login to the InterfaceManagement page successfully.')
    except Exception as e:
        logCommon.error('Login to the InterfaceManagement page failed.')
        return False
    return driver
Example #9
0
 def connectionMade(self):
     global client_id
     global alias
     global debug
     print 'Client connected successfully...'
     print 'Waiting for more commands....'
     
     if debug:
         print ' -- Your client ID is: {0} , and your alias is: {1}'.format(str(client_id), str(alias))
     
     euid = os.geteuid()
     
     # Do not send the euid, just tell if we are root or not.
     if euid == 0:
         # True
         iamroot = 1
     else:
         # False
         iamroot = 0
     
     # 'Client ID' text must be sent to receive another commands
     line = 'Starts the Client ID:{0}:Alias:{1}:Version:{2}:ImRoot:{3}'.format(str(client_id),str(alias),vernum,iamroot)
     if debug:
         print ' -- Line sent: {0}'.format(line)
     self.sendLine(line)
     
     line = 'Send more commands'
     if debug:
         print ' -- Line sent: {0}'.format(line)
     self.sendLine(line)    
def get_mysql_info(sys,infolist):
    if sys == "Linux":
        templist = list()
        tempdict = dict()
        templist = get_info("ps -ef|grep mysqld|grep basedir").split("--")
        if len(templist) <= 1:
            tempdict["mysql"]=False
            print "mysql server:"+str(tempdict["mysql"])
        else:
            tempdict["mysql"]=True
            print "mysql server:"+str(tempdict["mysql"])
            for i in templist:
                if i.find("basedir")>=0:
                    tempdict["basedir"]=i.split("=")[1].split()[0]
                    print "basedir:"+tempdict["basedir"]
                if i.find("datadir")>=0:
                    tempdict["datadir"]=i.split("=")[1]
                    print "datadir:"+tempdict["datadir"]
        #version 
            binpath =  tempdict["basedir"]+"/bin/mysql"
            if os.path.exists(binpath):
                ver = get_info(tempdict["basedir"]+"/bin/mysql -V")
                tempdict["version"] = ver.split("mysql")[1]
                print "version:"+tempdict["version"]
            else:
                tempdict["version"]=""
    infolist.append(tempdict)
Example #11
0
def process_commands():
    global server_ip
    global server_port
    global client_id
    global factory
    
    try:
        print 'Client Started...'
        
        # Generate the client unique ID
        client_id = str(random.randrange(0, 100000000, 1))
        
        # Create the output directory
        print 'Masscan output files stored in \'masscan_output\' directory...'
        os.system('mkdir masscan_output > /dev/null 2>&1')
        
        factory = MasscanClientFactory()
        # Do not wait more that 10 seconds between reconnections
        factory.maxDelay = 10
        reactor.connectSSL(str(server_ip), int(server_port), factory, ssl.ClientContextFactory())
        reactor.run()
    except Exception as inst:
        print 'Problem in process_commands function'
        print type(inst)
        print inst.args
        print inst 
Example #12
0
def main():
    global server_ip
    global server_port
    global alias
    global debug
    global maxrate
    
    try:
        opts, args = getopt.getopt(sys.argv[1:], "a:dm:p:s:", ["server-ip=","server-port","max-rate","alias=","debug"])
    except getopt.GetoptError: usage()
    
    for opt, arg in opts:
        if opt in ("-s", "--server-ip"): server_ip=str(arg)
        if opt in ("-p", "--server-port"): server_port=arg
        if opt in ("-a", "--alias"): alias=str(arg).strip('\n').strip('\r').strip(' ')
        if opt in ("-d", "--debug"): debug=True
        if opt in ("-m", "--max-rate"): maxrate=str(arg)
        
    try:
        if server_ip and server_port:
            version()
            
            # Start connecting
            process_commands()
            
        else:
            usage()
            
    except KeyboardInterrupt:
        # CTRL-C pretty handling.
        print 'Keyboard Interruption!. Exiting.'
        sys.exit(1)   
Example #13
0
def scatter_plane(df_plot, axis_list=['x','y'], title = "Scatter Plot", fname="plot_scatter_plane.png"):
    #
    unique_plots = pd.DataFrame(df_plot['K_means'].unique())
    colors = cm.rainbow(np.linspace(0, 1, len(unique_plots)))
    #
    # setup the plot
    plt.close('all')
    fig, ax = plt.subplots(1,1, figsize=(8,8))
    # setup legend labels
    legend_labels = pd.DataFrame(columns=["Labels"])
    # plot all the points color coded by delay clusters
    for plot_index, plot_rows in unique_plots.iterrows():
        y_list = df_plot[axis_list[1]].loc[df_plot['K_means'] == plot_rows[0]]
        x_list = df_plot[axis_list[0]].loc[df_plot['K_means'] == plot_rows[0]]
        leg_min = ("%.2f" % y_list.min())
        leg_max = ("%.2f" % y_list.max())
        index_value = len(legend_labels)
        legend_labels.set_value(index_value, 'Labels', "Delay "+str(leg_min)+" to "+str(leg_max))
        scat = ax.scatter(x_list,y_list,color=colors[index_value],s=300,linewidths=1)
    #
    # add titile, labels, and axis names
    ax.set_title(title, color='grey', fontsize=14, fontweight='bold')
    ax.set_xlabel(axis_list[0],color='grey', fontsize=14)
    ax.set_ylabel(axis_list[1],color='grey', fontsize=14)
#    legend_labels = df_plot['K_means'].unique()
    legend_labels = legend_labels['Labels'].unique()
    ax.legend(legend_labels, loc='best')
    plt.savefig("./plots/"+fname, dpi=300, bbox_inces='tight')
    #
    return fig
Example #14
0
    def generate_second_initialisation(self):
        loop = [Symbol('_'+x.name) for x in self.index]  # symbols for loop
        m = self.margin.value
        statements = []
        v = symbols("v")
        for field in self.fields:
            body = []
            if self.omp:
                statements.append(cgen.Pragma('omp for schedule(static,1)'))
            # populate xvalue, yvalue zvalue code
            for d in range(self.dimension-1, -1, -1):
                i = loop[d]
                i0 = m
                i1 = ccode(self.dim[d]-m)
                pre = []

                post = []
                if d == self.dimension-1:
                    # inner loop
                    # first time step
                    kernel = self.transform_kernel(field)
                    for arg in kernel.args:
                        if str(arg).startswith("-") and str(self.t - 1) in str(arg):
                            kernel = kernel.subs({arg: 0}, simultaneous=True)
                            arg = 2*v*self.dt
                            kernel = 0.5*(kernel + arg)
                    kernel = kernel.subs({self.t: self.time[0]})
                    for idx in self.index:
                        kernel = kernel.subs(idx, '_'+idx.name)
                    body = [cgen.Assign(ccode(field[[self.time[1]]+loop]), ccode(kernel))]
                body = pre + body + post
                body = [cgen.For(cgen.InlineInitializer(cgen.Value('int', i), i0), cgen.Line('%s<%s' % (i, i1)), cgen.Line('++%s' % i), cgen.Block(body))]

            statements.append(body[0])
        return statements
Example #15
0
    def set_order(self, order):
        """
        - set the order of approximation of the scheme
        - create the t variables for time stepping
        e.g. t0, t1 for 2nd order scheme, t0, t1, t2, t3 for 4th order scheme
        :param order: list of time order followed by spatial orders
        e.g. [2,4,4,4] for (2,4) scheme
        """
        for x in order:
            if x % 2 == 1:
                raise ValueError(str(x) + ' is not a valid order (require even integer)')
        self.order = order
        num_time_vars = max(self.order[0], self.max_derivative_order+1)
        # periodicity for time stepping
        self.tp = Variable('tp', num_time_vars, 'int', True)
        # add time variables for time stepping: t0, t1 ...
        self.time = []

        for k in range(num_time_vars):
            name = str(self.t) + str(k)
            v = Variable(name, k, 'int', False)
            self.time.append(v)
        self.margin.value = self.order[1]/2
        self.set_grid_size(self.grid_size)
        self.update_field_order()
        self._update_spacing()
def base58_encode(a,version='',postfix=''):
    """
    Base58 encode input

    Mostly ripped from:
    https://github.com/jgarzik/python-bitcoinlib/blob/master/bitcoin/base58.py
    """

    try:
        a = hexlify(unhexlify(a))
        version = hexlify(unhexlify(version))
        postfix = hexlify(unhexlify(postfix))
    except:
        raise Exception('base58_encode() Invalid input')
    a, version, postfix = hex_to_hexstr(a), hex_to_hexstr(version), hex_to_hexstr(postfix)
    b = version + a + postfix
    b58_digits = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
    n1 = int(b,16)
    res = []
    while n1 > 0:
        n1, r = divmod(n1,58)
        res.append(b58_digits[r])
    res = ''.join(res[::-1])
    pad = 0
    for i in range(len(b) // 2):
        j = int(2*i)
        teststr = str(b[j] + b[j+1])
        if teststr == '00':
            pad += 1
        else:
            break
    return str(b58_digits[0] * pad + res)
Example #17
0
 def movefile(self,case,value):
     now = datetime.datetime.now()
     nowprint=now.strftime('%Y%m%d%H%M%S') ##当前时间
     srcpath = self.picpath()     ##获取图片本地存储路径
     #dstpath = self.movetodir()       
     os.chdir(srcpath)      ##切换到图片存储路径
     files = os.listdir(".")    ##遍历目录中图片信息
     for filename in files:
         li = os.path.splitext(filename)   ##分离文件名与扩展名
         print li
         if li[1] == ".jpg":
             value=str(value)
             newname = str(nowprint)+'-'+case+'___'+value+li[1]   ##拼接图片新名称
             print newname  
             self.wait()
             try:
                 os.rename(filename,newname)
             except BaseException as msg:
                 print msg
             srcfilename = self.picpath()+'\\'+newname  ##拼接更改更改名称后图片完整路径
             print "srcfilename:"+srcfilename
             os.chdir(nowlogdir)
             self.wait()
             try:
                 shutil.move(srcfilename,datelogdir)
             except BaseException as msg:
                 print msg
 def execute(self):
     tpx_in = open("tpx_in.txt", "w")
     tpx_in.write("Name of project (up to 255 characters)\n")
     tpx_in.write(self.projectname.get() + "\n")
     tpx_in.write("Rows, Columns, flow-direction numbering scheme (ESRI=1, TopoIndex=2)\n")
     tpx_in.write(str(int(self.ncols_e)) + ", " + str(int(self.nrows_e)) + ", " + str(self.flowdirection) + "\n")
     tpx_in.write("Exponent, Number of iterations\n")
     tpx_in.write(self.exponent.get() + ", " + self.iterations.get() + "\n")
     tpx_in.write("Name of elevation grid file\n")
     tpx_in.write(self.elevationname + "\n")
     tpx_in.write("Name of direction grid\n")
     tpx_in.write(self.directionname + "\n")
     tpx_in.write("Save listing of D8 downslope neighbor cells?  Enter T (.true.) or F (.false.)\n")
     tpx_in.write(self.box1.get() + "\n")
     tpx_in.write("Save grid of D8 downslope neighbor cells? Enter T (.true.) or F (.false.)\n")
     tpx_in.write(self.box2.get() + "\n")
     tpx_in.write("Save cell index number grid?  Enter T (.true.) or F (.false.)\n")
     tpx_in.write(self.box3.get() + "\n")
     tpx_in.write("Save list of cell number and corresponding index number? Enter T (.true.) or F (.false.)\n")
     tpx_in.write(self.box4.get() + "\n")
     tpx_in.write("Save flow-direction grid remapped from ESRI to TopoIndex? Enter T (.true.) or F (.false.)\n")
     tpx_in.write(self.box5.get() + "\n")
     tpx_in.write("Name of folder to store output?\n")
     tpx_in.write(self.maps.get() + "\n")
     tpx_in.write("ID code for output files? (8 characters or less)\n")
     tpx_in.write(self.idname.get() + "\n")
     tpx_in.close()
     os.system("TopoIndex.exe")
     return True
def fitting_process(wavelength, real_intensity, center_wavelength, center_intensity, FWHM):
    # 1. calculate the initial r2_score
    fitted = fitted_total_spectrum(wavelength, center_wavelength, center_intensity, FWHM)
        
    r2_score = r_square_score(real_intensity, fitted)
    previous = 0.0
    
    # iteration until get same r2 score
    while r2_score != previous :
        previous = copy.deepcopy(r2_score)
        result = \
        universe_optimization(wavelength, real_intensity, center_wavelength, center_intensity, FWHM)
        center_wavelength, center_intensity, FWHM = result[0],result[1], result[2]
        fitted = fitted_total_spectrum(wavelength, center_wavelength, center_intensity, FWHM)
        r2_score = r_square_score(real_intensity, fitted)
    print "r2_score : " + str(r2_score)
    
    
    ######
    #plot#
    ######
    
    plt.plot(wavelength, real_intensity, label = "real")
    plt.plot(wavelength, fitted, label = "fitted")
    for i in range(len(center_intensity)) :
        y = guassion_fun(xData, center_wavelength[i], center_intensity[i], FWHM[i])
        plt.plot(xData,y,label = str(i))
    plt.legend()
    plt.show()
    
    return center_intensity
Example #20
0
 def __repr__(self):
     """Returns string representation of the given piece"""
     return_string = " "
     return_string += str(self.points) + " "
     return_string += self.name + " "
     return_string += "(" + str(self.location[0]) + "," + str(self.location[1]) + ")"
     return return_string
def longest_substring_with_K_distinct(s, k):

    max_len = 0
    start_max = 0
    end_max = 0
    curr_max = 0

    start = 0
    end = 0
    len_str = len(s)

    freq_table = collections.defaultdict(int)
    # print freq_table

    while end < len_str:

        print "Start: " + str(start) + " End: " + str(end)

        if (len(freq_table) == k) and (s[end] not in freq_table):
            start = chop_trailing_chars(s, freq_table, start, k)

        freq_table[s[end]] += 1

        if end - start + 1 > max_len:
            max_len = end - start + 1
            start_max = start
            end_max = end

            print "Max changed: start_max: " + str(start_max) + " end_max: " + str(end_max)

        end += 1
        print freq_table
        print "*****************\n"

    return s[start_max : start_max + max_len]
Example #22
0
def print_values():
#    print json.dumps(count_values, indent=4)
    print ("{")
    for k,v in count_values.items():
        if k in sum_values and v > 0:
            print ('"' + k + '"'+ ": " + str(float(sum_values[k])/v) + ",")
    print ('"total": ' + str(total) + '\n}')
Example #23
0
def get_months_object_list(startDate, endDate):
    try:
        if not startDate and not endDate:
            endDate = date.today()
            a = relativedelta.relativedelta(months=-12)

            startDate = endDate + a

        elif startDate and not endDate:
            a = relativedelta.relativedelta(months=12)
            endDate = startDate + a

        elif endDate and not startDate:
            a = relativedelta.relativedelta(months=-12)
            startDate = endDate + a

        m_list = []
        startDate = datetime.datetime(
            startDate.year, startDate.month, startDate.day
        )  # thedatetime(startDate, '%Y-%m-%d')   #datetime.datetime(2013, 2, 5)
        endDate = datetime.datetime(endDate.year, endDate.month, endDate.day)
        for d in arrow.Arrow.range("month", startDate, endDate):
            m_list.append([d.format("MMMM"), d.format("YYYY")])

        return m_list
    except Exception, err:
        raise Http404(str(err) + str(endDate))
Example #24
0
    def getNextHop(self, myID, msgClass):
        '''myID is my current ID 
           msgClass is class description like: "0019" or "???8", etc...
           this method attempts to find the next valid class for the msg.
           Currently no logic to perform a query such as greater or less than.
        '''
        # Get the class from the ID
        classID = self.getClassFromID(myID)
        plusOne = str(int(classID)+1)
        if self.isValidInClass(plusOne,msgClass):
            return plusOne
        else:
            # Increase the class until it's valid            
            msgClass = str(msgClass)
            classID = str(classID)
            #print ("classID: %s" % classID)
            myClass = int(classID[0:len(msgClass)])
            #print ("myClass: %s" % myClass)
            tooHigh = int("1" + (len(msgClass) * "0"))
            nextClass = myClass + 1
            while nextClass < tooHigh:
                if self.isValidClass(nextClass, msgClass):
                    # Make the nextClass a String of the right length
                    strClass = str(nextClass)
                    diff = len(msgClass) - len(strClass)
                    strClass = "0"*diff + strClass

                    return strClass

                nextClass += 1
            
            return None
Example #25
0
def readCachedFileContent(FileName):
    Data = ''
    try:
        with open(FileName,'r') as File:
            Data = File.read()
            
    except Exception,e:
        print str(e)
Example #26
0
    def sendPostRequest(self):
        """
        Sends POST request containing the images to the server. For the payload data refer ``params_data`` parameter of :func:`this <connections.uploadData.UploadData.addFileParameters>` function.
        """
        try:
            params_for_request = {}
            params_data = {}

            token = self.getRequest('http://cloudcv.org/api')
            print token
            if token is None:
                logging.log('W', 'token not found')
                raise SystemExit

            source, source_path = self.identifySourcePath()
            self.addAccountParameters(params_data, source)
            self.addFileParameters(source, source_path, params_data, params_for_request)


            job.job.imagepath = source_path

            params_data['token'] = token
            params_data['socketid'] = ''
            params_data['executable'] = self.exec_name
            params_data['exec_params'] = str(self.params)

            logging.log('D', 'Source Path: ' + self.source_path)
            logging.log('D', 'Executable: ' + params_data['executable'])
            logging.log('D', 'Executable Params: ' + params_data['exec_params'])

            while True:
                if self.socketid != '' and self.socketid is not None:
                    params_data['socketid'] = (self.socketid)
                    print 'SocketID: ', (self.socketid)
                    break
                else:
                    self._redis_obj.publish('intercomm2', 'getsocketid')
                    time.sleep(3)
                    logging.log('W', 'Waiting for Socket Connection to complete')



            # for k,v in params_for_request.items():
            #     params_data[k] = v
            logging.log('D', 'Starting The POST request')
            for i in range(1,5):
                try:
                    request = requests.post("http://cloudcv.org/api/", data=params_data,
                                            files=params_for_request)

                    # logging.log('D', 'Response:   ' + request.text)
                    logging.log('D', 'Info:   ' + 'Please wait while CloudCV runs your job request')
                    break
                except Exception as e:
                    logging.log('W', 'Error in sendPostRequest' + str(traceback.format_exc()))
        except Exception as e:
            logging.log('W', str(traceback.format_exc()))
            self._redis_obj.publish('intercomm', '***end***')
Example #27
0
    def __str__(self):
        r"""**str**\ (*object*)

        Renvoie une version LaTeX de la :class:`Fraction`.
            >>> from pyromaths.classes.Fractions import Fraction
            >>> str(Fraction(8,1))
            '8'
            >>> str(Fraction(5,6))
            '\\dfrac{5}{6}'
            >>> str(Fraction('-5*2', '3*2', 'r'))
            '\\dfrac{-5_{\\times 2}}{3_{\\times 2}}'
            >>> str(Fraction('5*-7*2', '11*2*5', 's'))
            '\\dfrac{\\cancel{5}\\times \\left( -7\\right) \\times \\cancel{2}}{11\\times \\cancel{2}\\times \\cancel{5}}'
            >>> str(Fraction('-144', '22', 's'))
            '\\dfrac{-72\\times \\cancel{2}}{11\\times \\cancel{2}}'
            >>> from pyromaths.classes.SquareRoot import SquareRoot
            >>> str(Fraction(SquareRoot([[-10, None], [-1, 80]]), -2))
            '\\dfrac{-10-\\sqrt{80}}{-2}'
            >>> str(Fraction(SquareRoot([[-10, None], [-4, 5]]), -2, 's'))
            '\\dfrac{\\left( 5+2\\,\\sqrt{5}\\right) \\times \\cancel{-2}}{1\\times \\cancel{-2}}'
            
        :rtype: string
        """
        from pyromaths.outils.Priorites3 import splitting
        #=======================================================================
        # print (repr(self))
        #=======================================================================
        if self.n == 0 or self.n == '0':
            return '0'
        lnum, lden = [], []
        if isinstance(self.n, str): lnum = splitting(self.n)
        if isinstance(self.d, str): lden = splitting(self.d)
        if len(lnum) == 1: self.n, lnum = eval(self.n), []
        if len(lden) == 1: self.d, lden = eval(self.d), []
        if self.d == 1:
            return (str(self.n), texify([lnum])[0])[lnum != []]
        if self.code == "r":
            # lnum et lden doivent être définis et se terminer par [..., '*', valeur]
            if not lnum or not lden or lnum[-2:] != lden[-2:]:
                raise ValueError(u'Mauvais usage de l\'étiquettes "r" dans %r' % self)
            lden[-2], lden[-1], lnum[-2], lnum[-1] = [lden[-2], 'indice'], [lden[-1], 'indice'], [lnum[-2], 'indice'], [lnum[-1], 'indice']
            return '\\dfrac{%s}{%s}' % (texify([lnum])[0], texify([lden])[0])
        if self.code == "s":
            if isinstance(self.n, (int, float, SquareRoot)) and isinstance(self.d, (int, float, SquareRoot)):
                lepgcd = pgcd(self.n, self.d)
                lnum, lden = [repr(self.n // lepgcd), '*', [str(lepgcd), 'cancel']], [repr(self.d // lepgcd), '*', [str(lepgcd), 'cancel']]
            else:
                for i in range(len(lnum)):
                    if lnum[i] != '*' and lden.count(lnum[i]):
                        # On doit simplifier la fraction par ce nombre
                        j = lden.index(lnum[i])
                        lden[j] = [lden[j], 'cancel']
                        lnum[i] = [lnum[i], 'cancel']
            return '\\dfrac{%s}{%s}' % (texify([lnum])[0], texify([lden])[0])
        s = r'\dfrac'
        s += '{%s}' % (self.n, texify([lnum])[0])[lnum != []]
        s += '{%s}' % (self.d, texify([lden])[0])[lden != []]
        return s
Example #28
0
def parseXmlFile(XMLFileData, handler):
    """
    Parses XML file by a given handler
    """
    try:
        with contextlib.closing(StringIO(XMLFileData)) as stream:
            parse(stream, handler)
    except Exception,e:
        print str(e)
def prepareDistinguish_Input_Output_Folder_PerEachProcess(folder_name):
    #current = time.time()
    output_direction = full_path + "\Rosetta_Model_Application\Output\%s" % str(folder_name)
    if not os.path.exists(output_direction):
        os.makedirs(output_direction)
    input_direction = full_path + "\Rosetta_Model_Application\Input\%s" % str(folder_name)
    if not os.path.exists(input_direction):
        os.makedirs(input_direction)
    return str(folder_name)
Example #30
0
 def gen_random_file_name(self):
     """returns a true random file name starting with the current time
     followed by a uuid1:
     [year]-[month]-[day]_[hour]-[minute]-[second].[us]-[uuid1].dat"""
     
     random_name = str(datetime.datetime.now())
     random_name = random_name.replace(" ", "_").replace(":","-")
     random_name += "-"+ str(uuid.uuid1())+".dat"
     return random_name
Example #31
0
    def filesInDirectory(self, dir):
        """
        A regex filter for images in the input directory.

        :param dir: An input directory. 
        :type dir: str
        :return: A list of all the image files that match the regex for image formats. 
        """ 
        onlyfiles = [f for f in listdir(dir) if isfile(join(dir, f)) is not None]
        onlyfiles = [f for f in onlyfiles if (re.search('([^\s]+(\.(jpg|png|gif|bmp|jpeg|JPG|PNG|GIF|BMP|JPEG))$)', str(f)) is not None)]
        return onlyfiles
Example #32
0
 def stop(self):
     f = open(self.path + 'enable', 'w')
     f.write(str(0))
     f.close()
Example #33
0
 def setValue(self, value):
     f = open(self.path + 'value', 'w')
     f.write(str(value))
     f.close()
Example #34
0
if __name__ == "__main__":
    obj_spider = Spider()
    obj_sender = Sender()
    url1 = "https://hz.lianjia.com/ershoufang/rs%E5%8D%97%E5%B2%B8%E6%99%B6%E9%83%BD%E8%8A%B1%E5%9B%AD/"
    url2 = "https://hz.lianjia.com/ershoufang/rs%E9%A3%8E%E6%99%AF%E8%9D%B6%E9%99%A2/"
    while True:
        try:
            hour = int(time.strftime('%H'))
            print time.strftime('%Y%m%d %H:%M:%S')

            if 0 < hour < 24:
                new_data = obj_spider.craw(url1)
                new_data.extend(obj_spider.craw(url2))
                add_items = check(new_data)
                if len(add_items) > 0:
                    print "New items!!!"
                    title = time.strftime('%Y%m%d %H:%M:%S')
                    content = ''
                    for house in add_items:
                        content += house['title'] + house['price'] + house[
                            'house_info'] + '\n'
                    obj_sender.send_email(title, content)
                else:
                    print "No change."
                time.sleep(20)
            else:
                time.sleep(3600)
        except Exception, e:
            print str(e)
Example #35
0
def fPostAssignmentData(jsondatavalues, location):
    returnValue = "Begin 111 fPostAssignmentData:"

    assignmentId, qlTitle, qlId, studentId, sessionId, assignmentTitle, studentName, role, objectiveDetails = "", "", "", "", "", "", "", "", ""
    numberOfAttempts = 0
    targetPoints = 0.0

    try:
        if "Assignment_Id" in jsondatavalues:
            assignmentId = jsondatavalues["Assignment_Id"]

        if "QLTitle" in jsondatavalues:
            qlTitle = jsondatavalues["QLTitle"]

        if "QL_Id" in jsondatavalues:
            qlId = jsondatavalues["QL_Id"]

        if "Student_Id" in jsondatavalues:
            studentId = jsondatavalues["Student_Id"]

        if "Session_Id" in jsondatavalues:
            sessionId = jsondatavalues["Session_Id"]

        if "AssignmentTitle" in jsondatavalues:
            assignmentTitle = jsondatavalues["AssignmentTitle"]

        if "NumberOfAttempts" in jsondatavalues:
            numberOfAttempts = int(str(
                jsondatavalues["NumberOfAttempts"]))  # int ??

        if "TargetPoints" in jsondatavalues:
            targetPoints = float(str(
                jsondatavalues["TargetPoints"]))  # double ??

        if "StudentName" in jsondatavalues:
            studentName = jsondatavalues["StudentName"]

        if "Role" in jsondatavalues:
            role = jsondatavalues["Role"]

        if "ObjectiveDetails" in jsondatavalues:
            objectiveDetails = jsondatavalues["ObjectiveDetails"]

        # enter assignment details on launch if details are not present
        filter1 = {"Assignment_Id": assignmentId, "QL_Id": qlId}
        diad = None
        try:
            diad = m.ql_assignmentdetails.objects.get(**filter1)
        except Exception as e:
            diad = None

        returnValue = returnValue + "abc Id:"

        if diad is not None:
            returnValue = returnValue + "efgttt Id:"
            diad.AssignmentTitle = assignmentTitle
            diad.NumberOfAttempts = numberOfAttempts
            diad.ObjectiveDetails = str(objectiveDetails)
            diad.save()

            returnValue = returnValue + "efg Id:"
        else:
            returnValue = returnValue + "efgggg Id:"
            diad = m.ql_assignmentdetails.objects.create(
                Assignment_Id=assignmentId,
                QL_Id=qlId,
                NumberOfAttempts=numberOfAttempts,
                TargetPoints=targetPoints,
                QLTitle=qlTitle,
                AssignmentTitle=assignmentTitle,
                Status=True,
                ObjectiveDetails=str(objectiveDetails))

        filter1['Student_Id'] = studentId
        returnValue = returnValue + "hij Id:"
        attemCount = m.ql_masterattempts.objects.filter(**filter1).count()

        returnValue = returnValue + "klm Id:"

        # filter1 is updated here.
        filter1['CompletionStatus'] = 'inprogress'

        dima = None
        try:
            dima = m.ql_masterattempts.objects.get(**filter1)
        except Exception as e:
            dima = None
            returnValue = returnValue + "innercatch" + str(e)

        if dima is not None:
            dima.Session_Id = sessionId
            dima.save()
        else:
            if diad.NumberOfAttempts == None or diad.NumberOfAttempts <= 0 or (
                    diad.NumberOfAttempts > 0
                    and attemCount < diad.NumberOfAttempts):
                ReportStatus = 'inactive'
                dima = m.ql_masterattempts.objects.create(
                    Assignment_Id=assignmentId,
                    AssignmentTitle=assignmentTitle,
                    Student_Id=studentId,
                    Session_Id=sessionId,
                    StudentName=studentName,
                    Score=0,
                    Points=0,
                    Role=role,
                    QL_Id=qlId,
                    CompletionStatus='inprogress',
                    TimeSpent=0,
                    ReportStatus=ReportStatus,
                    StartDate=datetime.now(),
                    EndDate=datetime.now())

        returnValue = returnValue + " - Launch Data Success"

    except Exception as e:
        #DBLog("QL Interaction Error: Command=launch jsondata=" + "", e);
        returnValue = returnValue + "maincatch1" + str(e)

    return returnValue
Example #36
0
def fPostAttemptData(jsondatavalues, location):
    returnValue = "Begin 111 fPostAttemptData:"
    assignmentId, qlId, studentId, completionStatus = "", "", "", ""
    overallScore = 0.0
    overallTimeSpent = 0.0
    overallPoints = 0.0

    try:
        if "Assignment_Id" in jsondatavalues:
            assignmentId = jsondatavalues["Assignment_Id"]

        if "QL_Id" in jsondatavalues:
            qlId = jsondatavalues["QL_Id"]

        if "Student_Id" in jsondatavalues:
            studentId = jsondatavalues["Student_Id"]

        if "CompletionStatus" in jsondatavalues:
            completionStatus = jsondatavalues["CompletionStatus"]

        if "OverallScore" in jsondatavalues:
            overallScore = Decimal(str(jsondatavalues["OverallScore"]))

        if "OverallTimeSpent" in jsondatavalues:
            overallTimeSpent = Decimal(str(jsondatavalues["OverallTimeSpent"]))

        if "OverallPoints" in jsondatavalues:
            overallPoints = Decimal(str(jsondatavalues["OverallPoints"]))

        # enter assignment details on launch if details are not present
        filter1 = {
            "Assignment_Id": assignmentId,
            "QL_Id": qlId,
            "Student_Id": studentId,
            "CompletionStatus": "inprogress"
        }

        qlma = None
        try:
            qlma = m.ql_masterattempts.objects.get(**filter1)
        except Exception as e:
            returnValue = returnValue + "Error" + str(e)
            qlma = None

        maxscore = 0.0

        filterMaxScr = {
            "Assignment_Id": assignmentId,
            "QL_Id": qlId,
            "Student_Id": studentId,
            "ReportStatus": "active",
            "CompletionStatus": "complete"
        }

        qlmaMaxScr = m.ql_masterattempts.objects.filter(**filterMaxScr).count()

        try:
            if qlmaMaxScr > 0:
                maxscorelist = m.ql_masterattempts.objects.filter(
                    **filterMaxScr).values_list("Score", flat=True)
                if maxscorelist is not None and len(maxscorelist) > 0:
                    maxscore = maxscorelist[0]

        except Exception as e:
            returnValue = returnValue + "Error" + str(e)

        if maxscore is None:
            maxscore = 0.0

        returnValue = returnValue + "-maxscore:" + \
            str(maxscore) + "overallScore:" + str(overallScore)

        if qlma is not None:
            # update master attempt
            if overallScore is None:
                overallScore = 0.0

            qlma.Score = overallScore
            qlma.Points = overallPoints
            if overallTimeSpent != 0:
                qlma.TimeSpent = overallTimeSpent

            returnValue = returnValue + \
                "completionStatus:" + str(completionStatus)

            if completionStatus != "" and completionStatus.lower(
            ) == "complete":
                qlma.CompletionStatus = completionStatus.lower()
                returnValue = returnValue + "-qlma.Score:" + str(qlma.Score)
                if qlma.Score is not None and maxscore < qlma.Score:
                    qlma.ReportStatus = "active"

                qlma.EndDate = datetime.now()
                qlma.AssignmentLocation = ""
                qlma.save()
                # Update other attempts
                if qlma.ReportStatus == "active":
                    filterRStat = {
                        "Assignment_Id": assignmentId,
                        "QL_Id": qlId,
                        "Student_Id": studentId
                    }
                    m.ql_masterattempts.objects.filter(**filterRStat).exclude(
                        Id=qlma.Id).update(ReportStatus="inactive")

            addquesdetail = AddQuestionDetails(qlma, jsondatavalues)
            returnValue = returnValue + addquesdetail

        returnValue = returnValue + " - Update Attempt Data Success"
    except Exception as e:
        #DBLog("QL Interaction Error: Command=postAttemptData jsondata=" + "", e);
        returnValue = returnValue + str(e)

    return returnValue
Example #37
0
def GetQuestionDetailsModel(urlorigin,
                            selsim,
                            selloc,
                            ASGN="",
                            isStudentDetails=False):
    # 'unicode-escape' is used to escape sequences in string
    selsim = selsim.decode('unicode-escape')

    filter1 = {"QL_Id": selsim}
    lstQLMasterQ = m.ql_masterquestions.objects.filter(**filter1).all()
    packagerelPath = getOptionPath(urlorigin, selsim)
    '''
    if (packagerelPath.find('/qualsims') != -1):
        packagerelPath = packagerelPath.replace('/qualsims', 'content/qualsims/')   
    '''

    filter2 = {"QL_Id": selsim, 'ReportStatus': 'active'}
    qlMasterAttempts = None

    if ASGN:
        filter2["Assignment_Id"] = ASGN
        qlMasterAttempts = m.ql_masterattempts.objects.filter(**filter2)
    else:
        qlMasterAttempts = m.ql_masterattempts.objects.filter(**filter2)

    if qlMasterAttempts.count() == 0:
        return " No data found"

    lstQLMasterAttemptsId = qlMasterAttempts.values_list("Id")

    filter3 = {'MstAttemptId__in': lstQLMasterAttemptsId}
    lstQLQuestionAttemptDetails = m.ql_questionattemptdetails.objects.filter(
        **filter3).all()

    sameqs = []

    qlQDRV = Classes.QLQuestionDetailReportView()
    qlQDRV.Results = []

    for qlMqd in lstQLMasterQ:
        qlQDR = Classes.QLQuestionDetailReport()

        if qlMqd.QuestionText is not None:
            qlQDR.Text = qlMqd.QuestionText.encode("utf-8")

        qlQDR.Id = qlMqd.QuestionId
        qlQDR.OccurenceNo = ""

        if qlMqd.QuestionTitle is not None:
            qlQDR.QuestionTitle = qlMqd.QuestionTitle.encode("utf-8")
            # same question occurance no
            filtersmq = {'QL_Id': selsim, 'QuestionTitle': qlQDR.QuestionTitle}
            if m.ql_masterquestions.objects.filter(**filtersmq).count() > 1:
                supval = ""
                occrnc = sameqs.count(qlQDR.QuestionTitle) + 1
                qlQDR.OccurenceNo = str(occrnc)

                if occrnc == 1:
                    supval = "<sup>st</sup>"
                elif occrnc == 2:
                    supval = "<sup>nd</sup>"
                elif occrnc == 3:
                    supval = "<sup>rd</sup>"
                else:
                    supval = "<sup>th</sup>"

                qlQDR.OccurenceNo = " (" + qlQDR.OccurenceNo + \
                    supval + " instance)"
                sameqs.append(qlQDR.QuestionTitle)

        qlQDR.Points = str(int(qlMqd.TotalPoints))
        qlQDR.Options = []
        qlQDR.OptionAlignment = "V"

        if qlMqd.AdditionalInfo is not None and qlMqd.AdditionalInfo != '""':
            qlQDR.OptionAlignment = "V"
            # str(jsonObjDetail["OptionAlignment"])
        # end if qlMqd.AdditionalInfo

        filter4 = {"QuestionId": qlMqd.QuestionId}
        lstattemptedforQuestion = lstQLQuestionAttemptDetails.filter(**filter4)
        lstattemptedforQuestionId = lstQLQuestionAttemptDetails.values(
            "MstAttemptId").distinct()

        if isStudentDetails:
            qlQDR.Students = []
            filterstd = {'Id__in': lstattemptedforQuestionId}
            lstMasterQsnAttempt = qlMasterAttempts.filter(**filterstd).all()
            for qma in lstMasterQsnAttempt:
                student = Classes.QLStudentDetails()
                student.Name = qma.StudentName
                student.Id = qma.Student_Id
                student.MasterAttemptId = qma.Id
                filterques = {
                    'MstAttemptId': qma.Id,
                    'QuestionId': qlMqd.QuestionId
                }
                # print lstattemptedforQuestion.count()
                if lstattemptedforQuestion.count() > 0:
                    studentQAttempt = lstattemptedforQuestion.filter(
                        **filterques).values_list("Points").all()
                    if studentQAttempt:
                        # print studentQAttempt
                        student.Points = str(int(studentQAttempt[0][0]))
                        qlQDR.Students.append(student)
        # end if isStudentDetails

        # no of times question answered
        qlQDR.NumberOfTimesAnswered = lstattemptedforQuestion.count()
        qlQDR.QuestionAttempted = str(qlQDR.NumberOfTimesAnswered)

        # no of time question attempted
        ttlAttmpt = lstQLMasterAttemptsId.count()
        qlQDR.TotalAttempted = str(ttlAttmpt)

        if ttlAttmpt > 0:
            qlQDR.Presented = str(
                int(
                    float(qlQDR.NumberOfTimesAnswered) / float(ttlAttmpt) *
                    100)) + "%"
        else:
            qlQDR.Presented = "0" + "%"

        if qlQDR.NumberOfTimesAnswered > 0:
            avgscr = lstattemptedforQuestion.aggregate(Avg('Score'))
            if avgscr.__len__() > 0:
                qlQDR.AverageScorePercent = str(int(avgscr["Score__avg"]))
            else:
                qlQDR.AverageScorePercent = "0"
        else:
            qlQDR.AverageScorePercent = "0"

        lstqloption = []
        correctCnt = 0
        incorrectCnt = 0
        partialCorrCnt = 0

        if qlMqd.Options == "" or qlMqd.Options == '[""]' or qlMqd.Options == '[]':
            pass
        else:
            try:
                lstqloption = literal_eval(qlMqd.Options)
            except Exception:
                pass

            for qloption in lstqloption:
                qlOptionReport = Classes.QlOptionReport()
                try:
                    qlOptionReport.Text = qloption["Text"]
                except Exception as ine:
                    qlOptionReport.Text = ''

                try:
                    qlOptionReport.Status = qloption["Status"]
                except Exception as ine:
                    qlOptionReport.Status = ''

                try:
                    qlOptionReport.Points = qloption["Points"]
                except Exception as ine:
                    qlOptionReport.Points = "0"

                try:
                    qlOptionReport.Image = packagerelPath + \
                        "/" + qloption["Img"]
                except Exception as ine:
                    qlOptionReport.Image = ""

                # print qloption["Points"]
                seloptid = ""
                try:
                    seloptid = qloption["Id"]
                except Exception as ine:
                    seloptid = ""

                filter5 = {"SelOptionId": seloptid}
                qlOptionReport.NumberOfTimesAnswered = lstattemptedforQuestion.filter(
                    **filter5).count()

                percent = 0
                if qlOptionReport.NumberOfTimesAnswered > 0:
                    percent = (float(qlOptionReport.NumberOfTimesAnswered) /
                               float(qlQDR.NumberOfTimesAnswered)) * 100

                if percent > 0:
                    qlOptionReport.Percent = str(round(percent, 2)) + "%"

                if qlOptionReport.Status.lower(
                ) == "correct" and qlOptionReport.NumberOfTimesAnswered > 0:
                    correctCnt += 1

                if qlOptionReport.Status.lower(
                ) == "incorrect" and qlOptionReport.NumberOfTimesAnswered > 0:
                    incorrectCnt += 1

                if qlOptionReport.Status.lower(
                ) == "partial" and qlOptionReport.NumberOfTimesAnswered > 0:
                    partialCorrCnt += 1


#                 basePath = ""
#                 if qlOptionReport.Image :
#                     splitarr = qlOptionReport.Image.split('/')
#                     if splitarr != None and splitarr.length() == 0 :
#                         basePath = "/assets/115/images/"
#                     else :
#                         basePath = qlOptionReport.Image.Replace(splitarr[splitarr.Length - 1], "")

                if qlOptionReport.Points >= 5:
                    qlOptionReport.PointsImage = k_ANALYTICS_STATIC + "images/5point.png"
                else:
                    qlOptionReport.PointsImage = k_ANALYTICS_STATIC + \
                        "images/" + str(qlOptionReport.Points) + "point.png"

                qlQDR.Options.append(qlOptionReport)
        # for qloption in lstqloption ends

        # question graph
        qlQDR.ForGraph = str(qlQDR.NumberOfTimesAnswered) + "###" + str(
            correctCnt) + "###" + str(incorrectCnt) + "###" + str(
                partialCorrCnt)

        qlQDRV.Results.append(qlQDR)
    #for qlMqd in lstQLMasterQ : ends

    if qlQDRV.Results.__len__() > 0:

        totalattempts = qlMasterAttempts.count()

        filterComp = {"CompletionStatus": "complete"}
        totalcompleted = qlMasterAttempts.filter(**filterComp).count()
        # print " totalcompleted " + str(totalcompleted )
        compltcnt = 0
        if totalattempts > 0:
            compltcnt = int(float(totalcompleted) / float(totalattempts) * 100)

        qlQDRV.AverageCompleted = float(compltcnt)
        # print " compltcnt " + str(compltcnt )

        filterscr = {"CompletionStatus": "complete", "Score__isnull": False}
        scorelist = qlMasterAttempts.filter(**filterscr).values("Score").all()
        if scorelist.count() > 0:
            # print scorelist
            qlQDRV.AverageScore = qlMasterAttempts.filter(
                **filterscr).aggregate(Avg('Score'))["Score__avg"]
            qlQDRV.MedianScore = getMedian(scorelist)
        else:
            qlQDRV.AverageScore = 0
            qlQDRV.MedianScore = 0
    else:
        qlQDRV.AverageScore = 0
        qlQDRV.MedianScore = 0
        qlQDRV.AverageCompleted = 0
    return qlQDRV
Example #38
0
 def VerificarTV(self):
     if self.tipov != False:
         # Si el tipo de venta es exento o no sujeto, se vacia impuesto
         if (self.tipov == "exento" or self.tipov == "no_sujeto"):
             # Vacio el impuesto
             self.invoice_line_tax_ids = False
             self.invoice_line_tax_ids = []
             # Elimina registros existentes en la tabla que relaciona impuestos y detalle que le corresponden al detalle actual
             # Como puede darse el caso de que el registro no tenga id porque no existe, entonces primero verifico que si exista
             # Si el ID es diferente de False es porque existe un registro asociado
             if (self._origin.id != False):
                 self.env.cr.execute("delete from account_invoice_line_tax where invoice_line_id = " + str(self._origin.id))
Example #39
0
def isValidRecord(otherId):
    if otherId != "":
        print "OtherId disqualification: " + str(otherId)
        return False
    else:
        return True
Example #40
0
def isValidTxnAmt(txnAmt):
    if txnAmt <= 0:
        print "Transaction Amt invalid: " + str(txnAmt)
        return False
    else:
        return True
Example #41
0
 def getString(self):
     tuple = math.modf(self.angle)
     Y = round(tuple[0] * 60.0, 1)
     X = int(tuple[1])
     string = str(X) + "d" + str(Y)
     return string
Example #42
0
                                "Overscan Height %", "100")
        #tde4.setWidgetValue(req,"model_selection","1")
        tde4.addOptionMenuWidget(req, "units", "Units", "cm", "m", "mm", "in",
                                 "ft", "yd")

        tde4.addSeparatorWidget(
            req, 'sep01')  #######################################

        tde4.addToggleWidget(req, "export_jpg", "Export JPG", 0)

        cam = tde4.getCurrentCamera()
        offset = tde4.getCameraFrameOffset(cam)

        tde4.setWidgetValue(
            req, "startframe_field",
            builtin.str(tde4.getCameraSequenceAttr(cam)
                        [0]))  # Startframe Value same as Sequence In Frame.

        ## Export JPG Auto Toggle ##
        if _is_LD_default(cam) == False or os.path.isdir(jpgPlateDir) == True:
            tde4.setWidgetSensitiveFlag(req, "export_jpg", 0)
        else:
            tde4.setWidgetValue(req, "export_jpg", "1")

        ret = tde4.postCustomRequester(
            req, "Export Maya 75mm Studio v2 (MEL-Script)...", 700, 0, "Ok",
            "Cancel")
        if ret == 1:
            camera_selection = tde4.getWidgetValue(req, "camera_selection")
            model_selection = tde4.getWidgetValue(req, "model_selection")

            overscan_w_pc = builtin.float(
            for i in range(len(param_bl[0])):
                for j in range(len(param_bl[1])):
                    #Bilateral
                    img_filtered = cv2.bilateralFilter(img_Eq,param_bl[0][i],param_bl[1][j],param_bl[1][j])
                   
                    #apply frangi for different scales
                    for t in range(len(param_beta1)):
                        for z in range(len(param_beta2)):
                            
                            for k in range(len(param_x)):
                                for l in range(len(param_y)):
                                        img_fr=img_as_ubyte(frangi(img_filtered,sigma_x = param_x[k],sigma_y = param_y[l],beta1=param_beta1[t],beta2= param_beta2[z],  black_ridges=True))
                                        _, img_thresh = cv2.threshold(img_fr,0,255,cv2.THRESH_BINARY) 
                                

                                        cv2.imwrite(str(im)+"x_"+str(param_x[k])+"_y_"+str(param_y[l])+"_bl_"+str(param_bl[0][i])+'_'+str(param_bl[1][j])+ '_beta1_' + str(param_beta1[t]) + '_beta2_' + str(param_beta2[z])+'.tif', img_thresh)
            #for sigma_index in range(len(v)-1):
                #img_fr = np.minimum(img_fr,v[sigma_index+1])
            #img_fr = img_fr*img_roi                                                
            
             
            #check f! score of all possibilities
                                        new_result = (classification_report(labeled_crack.reshape((labeled_crack.shape[0]*labeled_crack.shape[1])),img_thresh.reshape((img_thresh.shape[0]*img_thresh.shape[1]))))
                                        bl_class_result = bl_class_result+"x_"+str(param_x[k])+"_y_"+str(param_y[l])+"_bl_"+str(param_bl[0][i])+"_"+str(param_bl[1][j])+ "_beta1_" + str(param_beta1[t]) + "_beta2_" + str(param_beta2[z]) +"\n" +new_result
            
            
                                    #save the data
                                        with open(str(im)+'_bl_classification_results.txt','w') as output:
                                            output.write(bl_class_result)

        if(index == 1):
Example #44
0
        f = open('NewExpt/expt5/testRegretGLBUCB0RR1.txt', 'a')
        for r in range(len(self.actionRegret)):
            f.write(str(self.actionRegret[r]) + "\n")
        f.close()

        return cumulativeReward, bestActionCumulativeReward, regret, self.action, self.t


if __name__ == "__main__":

    wrong = 0
    user = 64
    action = 10
    rank = 2

    for turn in range(0,100):
        obj = GLBUCB()
        random.seed(turn + action)
        cumulativeReward, bestActionCumulativeReward, regret, arm, timestep = obj.GLBUCB(user, action, rank)
        #if obj.check(bestSet) == False:
            # print bestSet
        #    wrong = wrong + 1
        print "turn: " + str(turn + 1) + "\t wrong: " + str(wrong) + "\t arms: " + str(action) + "\t barm: " + str(arm) + "\t Reward: " + str(cumulativeReward) + "\t bestCumReward: " + str(bestActionCumulativeReward) + "\t regret: " + str(regret)
        f = open('NewExpt/expt5/testGLBUCB0RR1.txt', 'a')
        f.writelines("arms: %d\t bArms: %d\t timestep: %d\t regret: %d \t cumulativeReward: %.2f \t bestCumulativeReward: %.2f \n" % (action, arm, timestep, regret, cumulativeReward, bestActionCumulativeReward))
        f.close()

        turn = turn + 1
        

Example #45
0
def fullScan(model, trait):
    ### no magic number! here are constants
    nInd = 1846

    covFolder = '/home/sxue2/thirdProject/Data_prep/'
    phenoFolder = '/home/sxue2/thirdProject/data/'
    phenoFileName = 'Traits_S0S1.txt'
    genoFolder = '/home/sxue2/thirdProject/data/'
    outFolder = '/home/sxue2/thirdProject/outputs/'
    VCdir = '/home/sxue2/thirdProject/data/'

    covList = ['F.exp']  #a list of covariate names
    phenoR = getPheno(phenoFolder, phenoFileName, trait, covList)
    pheno = phenoR[1]
    covariate = phenoR[2]
    #print(type(covariate))
    #print(covariate)

    VarComps = [11.2658749, 8.533966e-08]  #Vg and Verr for trait from asreml
    ########################## read in cov matrix
    #read in the dense relationship matrix, it has no header or indicator columns
    #by default loadtxt makes a float matrix
    #current format of G matrix is square numeric with no row or column headings
    #sort order is enforced outside of this program to match row order of genotype scores
    K = np.loadtxt('/home/sxue2/thirdProject/data/Gmatrix_all_families.txt.gz')
    #type(K)
    # read in corresponding parameters (from asreml output)

    Vg = float(VarComps[0])
    Ve = float(VarComps[1])
    ######################### error variance matrix
    error = np.zeros((nInd, nInd), float)
    np.fill_diagonal(error, Ve)
    ######################### Genetic covariance matrix
    # g-cov matrix
    ksigmaG = Vg * K
    V = ksigmaG + error

    ######################### genotype
    add = np.loadtxt(genoFolder + 'ZeaSyn6_numeric_add_trans_shang.txt',
                     skiprows=1,
                     dtype=str)
    dom = np.loadtxt(genoFolder + 'ZeaSyn6_numeric_dom_trans_shang.txt',
                     skiprows=1,
                     dtype=str)
    #add = np.loadtxt(genoFolder+'tryadd.txt',skiprows=1,dtype=str)
    #dom = np.loadtxt(genoFolder+'tryadd.txt',skiprows=1,dtype=str)

    totalMarker = add.shape[
        0]  # shape[0] is marker number, shape[1] is individual number

    f_pvalue = open(outFolder + model + trait + 'pvalues.txt', 'w', 1)
    f_beta = open(outFolder + model + trait + 'beta.txt', 'w', 1)
    f_dfMarker = open(outFolder + model + trait + 'dfMarker.txt', 'w', 1)

    count = 1
    for index in range(add.shape[0]):
        thisAdd = add[index, :]
        thisDom = dom[index, :]

        keepAddI = [
            item for item in range(len(thisAdd)) if thisAdd[item] != 'NA'
        ]
        keepDomI = [
            item for item in range(len(thisDom)) if thisDom[item] != 'NA'
        ]
        nonMissI = list(set(keepAddI).intersection(keepDomI))
        # the following two lines confirmed that if add had NA then dom had NA too
        #if(set(keepAddI) != set(keepDomI)):
        #print("this one doesn't match",count)

        addFilter = [float(thisAdd[i]) for i in nonMissI]
        domFilter = [float(thisDom[i]) for i in nonMissI]
        covFilter = [covariate[i] for i in nonMissI]
        phenoFilter = [float(pheno[i][0]) for i in nonMissI]
        V1 = [(np.squeeze(np.asarray(V[i]))) for i in nonMissI]
        Vsub = np.asmatrix([V1[item][nonMissI] for item in range(len(V1))])

        print("Vshape", Vsub.shape)
        print("Do inverse OMG")
        inverseV = inv(Vsub)
        print("Inverse done")
        result = markerTest(addFilter, domFilter, covFilter, phenoFilter, nInd,
                            inverseV, nonMissI)
        #if(model == "model5" ):
        #ksigmaG9 =
        #V = ksigmaG9 + error
        #result = markerTest(addFilter,domFilter,covFilter, phenoFilter, nInd, V,nonMissI)
        p = result[0]
        beta = result[1]
        dfMarker = result[2]
        print("p:", p)
        print("beta", beta)
        thisp = [str(p)]
        if (type(beta) is int):
            thisBeta = [str(beta)]
        else:
            thisBeta = beta.tolist()[0]
        pString = "\t".join(str(x) for x in thisp)
        betaString = "\t".join(str(x) for x in thisBeta)
        f_pvalue.write(pString + "\n")
        f_beta.write(betaString + "\n")

        dfMarker = result[2]
        f_dfMarker.write(str(dfMarker) + "\n")
        count = count + 1
        print("count", count)
    f_pvalue.close()
    def post(self):

        conditions = []  #initializing conditions [boolean] array
        password_list = []  #initializing password [string] array

        def check_uppercase(pw):  #checking for an uppercase letter
            return any(char.isupper() for char in pw)

        def check_lowercase(pw):  #checking for a lowercase letter
            return any(char.islower() for char in pw)

        def check_cases(
                pw):  #returns true if there are upper and lowercase letters
            return bool(check_uppercase(pw) == 1 & check_lowercase(pw) == 1)

        def check_digit(pw):  #checking for a digit
            return any(char.isdigit() for char in pw)

        def check_other(pw,
                        search=re.compile(
                            r'[^A-Za-z0-9]').search):  #checking for other
            return bool(search(pw))

        def check_length(pw):  #checking length at least 6
            return bool(len(pw) >= 6)

        def check_conditions(conditions):  #counting conditions met
            return conditions.count(1)

        def search_recursive(password_list, pw, low,
                             high):  #search password list for user password
            if (high < low):
                return -1
            else:
                mid = low + ((high - low) / 2)
                if pw == password_list[mid]:
                    return mid
                elif (password_list[mid] > pw):
                    return search_recursive(password_list, pw, low, mid - 1)
                else:
                    return search_recursive(password_list, pw, mid + 1, high)

        #retrieving list of passwords from file
        file = open("passwords common.txt", mode="U")
        for line in file:
            password_list.append(line)
        file.close()

        pw = self.request.get('content')

        #check conditions, save to array
        conditions.append(check_cases(pw))
        conditions.append(check_digit(pw))
        conditions.append(check_other(pw))
        conditions.append(check_length(pw))

        conditions_count = check_conditions(conditions)

        new_pw = pw.lower()
        new_pw += "\n"

        #print to terminal strength of password
        self.response.write(
            '<html><body><BODY BGCOLOR="E6E6FA" TEXT="4B0082"> <h2>Password Check Results:</h2><pre>'
        )
        if conditions_count == 0:
            self.response.write('Your Password is VERY WEAK!\n')
        elif conditions_count == 1:
            self.response.write('Your Password is WEAK\n')
        elif conditions_count == 2:
            self.response.write('Your Password is MEDIUM in strength\n')
        elif conditions_count == 3:
            self.response.write('Your Password is HIGH MEDIUM in strength\n')
        elif conditions_count == 4:
            self.response.write('Your Password is STRONG!\n')
        else:
            self.response.write('Something went very very wrong\n')

        #print to terminal specific conditions met
        self.response.write('\n')
        self.response.write('Conditions Your Password Must Meet:\n\n')
        if conditions[0] == 1:
            pass_fail = "CONDITION MET: "
        else:
            pass_fail = "CONDITION NOT MET: "
        self.response.write(
            str(pass_fail) +
            'It has at least one uppercase and at least one lowercase letter \n'
        )

        if conditions[1] == 1:
            pass_fail = "CONDITION MET: "
        else:
            pass_fail = "CONDITION NOT MET: "
        self.response.write(str(pass_fail) + 'It has at least one digit \n')

        if conditions[2] == 1:
            pass_fail = "CONDITION MET: "
        else:
            pass_fail = "CONDITION NOT MET: "
        self.response.write(
            str(pass_fail) +
            'It has at least one character that is not a letter or a digit \n')

        if conditions[3] == 1:
            pass_fail = "CONDITION MET: "
        else:
            pass_fail = "CONDITION NOT MET: "
        self.response.write(
            str(pass_fail) + 'It has a length of at least six characters \n')

        self.response.write('\n')
        if search_recursive(password_list,
                            new_pw,
                            low=0,
                            high=len(password_list) - 1) == -1:
            self.response.write(
                'Good job! Your password is NOT on the list of most common passwords, please hit the browser back button to try again.'
            )
        else:
            self.response.write(
                'Your password FAILED, it is on the list of most common passwords, please hit the browser back button to try again.'
            )
        conditions[:] = []

        self.response.write('\n')
        self.response.write('</pre></body></html>')
Example #47
0
def GetStudentDetailModel(urlorigin, selsim, selloc, ASGN=""):
    selsim = selsim.decode('unicode-escape')
    filter1 = {"QL_Id": selsim}
    lstQLMasterQ = m.ql_masterquestions.objects.filter(**filter1).all()
    packagerelPath = getOptionPath(urlorigin, selsim)
    filter2 = {"QL_Id": selsim, 'ReportStatus': 'active'}
    qlMasterAttempts = None

    if ASGN:
        filter2["Assignment_Id"] = ASGN
        qlMasterAttempts = m.ql_masterattempts.objects.filter(**filter2)
    else:
        qlMasterAttempts = m.ql_masterattempts.objects.filter(**filter2)

    if qlMasterAttempts.count() == 0:
        return "No data found"

    lstQLMasterAttemptsId = qlMasterAttempts.values_list("Id")

    filter3 = {'MstAttemptId__in': lstQLMasterAttemptsId}
    lstQLQuestionAttemptDetails = m.ql_questionattemptdetails.objects.filter(
        **filter3).all()

    qlSRV = Classes.QLStudentReportView()
    qlSRV.Results = []  # List<QLStudentDetails>()
    qlSRV.QuestionsDetails = []  # List<QlQuestionMasterForStudentReport>()
    qlSRV.RelPackagePath = packagerelPath

    for qlMa in qlMasterAttempts:
        student = Classes.QLStudentDetails()
        stuattempts = None
        student.Name = qlMa.StudentName
        student.Id = qlMa.Student_Id
        student.MasterAttemptId = qlMa.Id
        student.Score = 0.0 if qlMa.Score is None else qlMa.Score
        student.CompletionStatus = "Completed" if qlMa.CompletionStatus == "complete" else "In Progress"

        stuattempts = None

        filterSAttmpt = {"QL_Id": selsim, 'CompletionStatus': 'complete'}
        if ASGN:
            filterSAttmpt["Student_Id"] = qlMa.Student_Id
            filterSAttmpt["Assignment_Id"] = ASGN
            stuattempts = m.ql_masterattempts.objects.filter(
                **filterSAttmpt).all()
        else:
            stuattempts = m.ql_masterattempts.objects.filter(
                **filterSAttmpt).all()

        student.Attempts = []  # List<QLStudentAttempt>()
        if stuattempts is not None and stuattempts.count() > 0:
            k = 1
            for std in stuattempts:
                statt = Classes.QLStudentAttempt()
                statt.AttemptNo = k
                statt.Score = 0.00 if std.Score is None else float(
                    "{0:.2f}".format(std.Score))
                statt.SessionId = std.Session_Id
                student.Attempts.append(statt)
                k = k + 1
        # end if stuattempts is not None and stuattempts.count() > 0 :

        student.Questions = []  # List<QLQuestionForStudentReport>()
        filterSQues = {"MstAttemptId": qlMa.Id}
        studentQuestionsDetails = lstQLQuestionAttemptDetails.filter(
            **filterSQues).all()
        if studentQuestionsDetails and studentQuestionsDetails.count() > 0:
            sameqs = []
            for qlqd in studentQuestionsDetails:
                filterQues = {"QuestionId": qlqd.QuestionId}
                quesMasterLst = lstQLMasterQ.filter(**filterQues).all()
                quesMaster = quesMasterLst[0]
                if ObjectExistInArray(qlSRV.QuestionsDetails, "Id",
                                      qlqd.QuestionId) is False:
                    question = Classes.QlQuestionMasterForStudentReport()
                    question.Id = qlqd.QuestionId.encode("utf-8")
                    question.OptionAlignment = "V"
                    if quesMaster.AdditionalInfo is not None and quesMaster.AdditionalInfo != '""' and quesMaster.AdditionalInfo != '' and quesMaster.AdditionalInfo != '{}':
                        jsonObjDetail = literal_eval(quesMaster.AdditionalInfo)
                        question.OptionAlignment = str(
                            jsonObjDetail["OptionAlignment"])

                    question.Text = quesMaster.QuestionText.replace(
                        "Select an option from the choices below and click Submit.",
                        "")

                    lstqloption = []  # List<QlOption>()
                    if quesMaster.Options != "" and quesMaster.Options != '[""]' and quesMaster.Options != '[]':
                        try:
                            lstqloption = literal_eval(quesMaster.Options)
                        except Exception:
                            pass

                        question.Options = lstqloption

                    question.OccurenceNo = ""

                    if quesMaster.QuestionTitle is not None:
                        question.QuestionTitle = quesMaster.QuestionTitle.encode(
                            "utf-8")
                        # same question occurance no
                        filtersmq = {
                            'QL_Id': selsim,
                            'QuestionTitle': question.QuestionTitle
                        }
                        if m.ql_masterquestions.objects.filter(
                                **filtersmq).count() > 1:
                            supval = ""
                            occrnc = sameqs.count(question.QuestionTitle) + 1
                            question.OccurenceNo = str(occrnc)

                            if occrnc == 1:
                                supval = "<sup>st</sup>"
                            elif occrnc == 2:
                                supval = "<sup>nd</sup>"
                            elif occrnc == 3:
                                supval = "<sup>rd</sup>"
                            else:
                                supval = "<sup>th</sup>"

                            question.OccurenceNo = " (" + \
                                question.OccurenceNo + supval + " instance)"
                            sameqs.append(question.QuestionTitle)
                        # if end question occ more that once
                    # end if qlqd.QuestionTitle is not None
                    qlSRV.QuestionsDetails.append(question)
                # if end ObjectExistInArray
                qlquestion = Classes.QLQuestionForStudentReport()
                qlquestion.Id = qlqd.QuestionId
                qlquestion.PointsObtained = int(qlqd.Points)
                qlquestion.TotalPoints = int(quesMaster.TotalPoints)
                qlquestion.SelectedOption = qlqd.SelOptionId

                if int(qlqd.Points) >= 5:
                    qlquestion.PointsImage = k_ANALYTICS_STATIC + "images/5point.png"
                else:
                    qlquestion.PointsImage = k_ANALYTICS_STATIC + "images/" + \
                        str(qlquestion.PointsObtained) + "point.png"

                student.Questions.append(qlquestion)
            # endfor qlqd in studentQuestionsDetails :

        qlSRV.Results.append(student)

    # endfor qlMa in qlMasterAttempts :

    if qlSRV.Results.__len__() > 0:
        filterscr = {"CompletionStatus": "complete", "Score__isnull": False}
        scorelist = qlMasterAttempts.filter(**filterscr).values("Score").all()
        if scorelist.count() > 0:
            # print scorelist
            qlSRV.AverageScore = qlMasterAttempts.filter(
                **filterscr).aggregate(Avg('Score'))["Score__avg"]
        else:
            qlSRV.AverageScore = 0
    else:
        qlSRV.AverageScore = 0

    return qlSRV
Example #48
0
    def __str__(self):
        r"""**str**\ (*object*)

        Renvoie une version LaTeX de la :class:`Fraction`.
            >>> from pyromaths.classes.Fractions import Fraction
            >>> str(Fraction(8,1))
            8
            >>> str(Fraction(5,6))
            \dfrac{5}{6}
            >>> str(Fraction('-5*2', '3*2', 'r'))
            \dfrac{-5_{\times 2}}{3_{\times 2}}
            >>> str(Fraction('5*-7*2', '11*2*5', 's'))
            \dfrac{\cancel{5}\times \left( -7\right) \times \cancel{2}}{11\times \cancel{2}\times \cancel{5}}
            >>> str(Fraction('-144', '22', 's'))
            \dfrac{-72\times \cancel{2}}{11\times \cancel{2}}
            >>> from pyromaths.classes.SquareRoot import SquareRoot
            >>> str(Fraction(SquareRoot([[-10, None], [-1, 80]]), -2))
            \dfrac{-10-\sqrt{80}}{-2}
            >>> str(Fraction(SquareRoot([[-10, None], [-4, 5]]), -2, 's'))
            \dfrac{\left( 5+2\,\sqrt{5}\right) \times \cancel{-2}}{1\times \cancel{-2}}

        :rtype: string
        """
        from pyromaths.outils.Priorites3 import splitting
        #=======================================================================
        # print (repr(self))
        #=======================================================================
        if self.n == 0 or self.n == '0':
            return '0'
        lnum, lden = [], []
        if isinstance(self.n, str): lnum = splitting(self.n)
        if isinstance(self.d, str): lden = splitting(self.d)
        if len(lnum) == 1: self.n, lnum = eval(self.n), []
        if len(lden) == 1: self.d, lden = eval(self.d), []
        if self.d == 1:
            return (str(self.n), texify([lnum])[0])[lnum != []]
        if self.code == "r":
            # lnum et lden doivent être définis et se terminer par [..., '*', valeur]
            if not lnum or not lden or lnum[-2:] != lden[-2:]:
                raise ValueError(
                    u'Mauvais usage de l\'étiquettes "r" dans %r' % self)
            lden[-2], lden[-1], lnum[-2], lnum[-1] = [lden[-2], 'indice'], [
                lden[-1], 'indice'
            ], [lnum[-2], 'indice'], [lnum[-1], 'indice']
            return '\\dfrac{%s}{%s}' % (texify([lnum])[0], texify([lden])[0])
        if self.code == "s":
            if isinstance(self.n, (int, float, SquareRoot)) and isinstance(
                    self.d, (int, float, SquareRoot)):
                lepgcd = pgcd(self.n, self.d)
                lnum, lden = [
                    repr(self.n // lepgcd), '*', [str(lepgcd), 'cancel']
                ], [repr(self.d // lepgcd), '*', [str(lepgcd), 'cancel']]
            else:
                for i in range(len(lnum)):
                    if lnum[i] != '*' and lden.count(lnum[i]):
                        # On doit simplifier la fraction par ce nombre
                        j = lden.index(lnum[i])
                        lden[j] = [lden[j], 'cancel']
                        lnum[i] = [lnum[i], 'cancel']
            return '\\dfrac{%s}{%s}' % (texify([lnum])[0], texify([lden])[0])
        s = r'\dfrac'
        s += '{%s}' % (self.n, texify([lnum])[0])[lnum != []]
        s += '{%s}' % (self.d, texify([lden])[0])[lden != []]
        return s
Example #49
0
def GetOutcomesModel(selsim, selloc, ASGN=""):
    selsim = selsim.decode('unicode-escape')

    model = Classes.QLOutcomesModel()
    filterASGN = {"QL_Id": selsim}
    if ASGN:
        filterASGN["Assignment_Id"] = ASGN
    assignment = m.ql_assignmentdetails.objects.filter(
        **filterASGN).values("ObjectiveDetails").all()

    if assignment.count() == 0:
        return model
    asgnob = assignment[0]
    jsonObjDetail = literal_eval(asgnob["ObjectiveDetails"])
    model.Description = str(jsonObjDetail["Title"])
    model.Title = str(jsonObjDetail["CustomTarget"])

    filterASGN['ReportStatus'] = 'active'
    mstattempts = m.ql_masterattempts.objects.filter(**filterASGN).all()

    # get total attempted count
    mstattempids = mstattempts.values_list("Id")
    model.TotalAttempted = mstattempts.values("Student_Id").distinct().count()
    j_objectives = jsonObjDetail["ObjectiveDetails"]
    model.ChartData = "["
    for obj in j_objectives:
        objective = Classes.QLOutcomeObjectiveModel()
        objective.Id = obj["Id"]
        objective.Name = obj["Name"]
        objective.Title = obj["Title"]
        objective.Questions = []  # new List<QLOutcomesQuestionModel>()
        j_pageids = obj["PageIds"]
        pageids = []
        for pg in j_pageids:
            question = Classes.QLOutcomesQuestionModel()
            question.QuestionId = pg
            filterQues = {"QL_Id": selsim, "QuestionId": question.QuestionId}
            masterQ = m.ql_masterquestions.objects.filter(**filterQues).all()
            if masterQ is not None and masterQ.count() > 0:
                mQues = masterQ[0]
                question.QuestionText = mQues.QuestionText
                question.QuestionTitle = mQues.QuestionTitle
                filterScr = {
                    "QuestionId": question.QuestionId,
                    "MstAttemptId__in": mstattempids
                }
                attscorequery = m.ql_questionattemptdetails.objects.filter(
                    **filterScr)
                if attscorequery is not None and attscorequery.count() > 0:
                    question.PresentedCount = attscorequery.values(
                        "Score").count()
                    avgscr = attscorequery.aggregate(Avg('Score'))
                    if avgscr.__len__() > 0:
                        question.AverageScore = round(avgscr["Score__avg"], 2)
                    else:
                        question.AverageScore = 0
                else:
                    question.PresentedCount = 0
                    question.AverageScore = 0

                pageids.append(question.QuestionId)
                objective.Questions.append(question)
            # if ends masterQ
        # for ends pageids

        filterScr1 = {
            "QuestionId__in": pageids,
            "MstAttemptId__in": mstattempids
        }
        presscorelist = m.ql_questionattemptdetails.objects.filter(
            **filterScr1)
        if presscorelist is not None and presscorelist.count() > 0:
            objective.PresentedCount = presscorelist.values("Score").count()
            avgscr1 = presscorelist.aggregate(Avg('Score'))
            if avgscr1.__len__() > 0:
                objective.AverageScore = round(avgscr1["Score__avg"], 2)
            else:
                objective.AverageScore = 0
        else:
            objective.PresentedCount = 0
            objective.AverageScore = 0

        model.Objectives.append(objective)
        if model.ChartData == "[":
            model.ChartData = model.ChartData + \
                "['" + objective.Name + "'," + \
                str(objective.AverageScore) + "]"
        else:
            model.ChartData = model.ChartData + \
                ",['" + objective.Name + "'," + \
                str(objective.AverageScore) + "]"

    # for ends j_objectives
    model.ChartData = model.ChartData + "]"

    return model
Example #50
0
    def get_forbidden_time_intervals(self,
                                     cr,
                                     uid,
                                     order,
                                     min_date=None,
                                     max_date=None,
                                     context=None):
        intervals = super(SaleOrder,
                          self).get_forbidden_time_intervals(cr,
                                                             uid,
                                                             order,
                                                             min_date=min_date,
                                                             max_date=max_date,
                                                             context=context)
        if min_date and max_date:
            #nothing to compute if the is not an interval to check
            #TODO: can use forbidden_days also
            #order = self.browse(cr, SUPERUSER_ID, order_id, context)
            delivery_carrier = order.carrier_id
            allowed_daytimes = {}
            if delivery_carrier and delivery_carrier.delivery_period_ids:
                for period in delivery_carrier.delivery_period_ids:
                    #for each day, a list of list of tuples
                    allowed_daytimes[period.day_of_week] = allowed_daytimes.get(period.day_of_week, []) + \
                        [[(period.start_hour, (0 if period.start_min == 1 else period.start_min)), (period.end_hour, (0 if period.end_min == 1 else period.end_min))]]
            if allowed_daytimes:
                _logger.debug("Allowed daytimes : %s", str(allowed_daytimes))
                tzone = timezone('Europe/Brussels')
                min_datetime = tzone.localize(datetime(*min_date))
                max_datetime = tzone.localize(datetime(*max_date))
                assert max_datetime >= min_datetime
                current_day = min_datetime
                one_day_delta = timedelta(days=1)
                _logger.debug("min date %s max date %s", str(min_datetime),
                              str(max_datetime))
                while (current_day < max_datetime):
                    _logger.debug("current_day %s", str(current_day))
                    if current_day.isoweekday() in allowed_daytimes.keys():
                        #TODO : end of interval allowed : ok or not ?
                        start_of_interval = [
                            current_day.year, current_day.month,
                            current_day.day, 0, 0
                        ]

                        for daily_interval in allowed_daytimes[
                                current_day.isoweekday()]:
                            #supposed ordered and no overlap

                            end_of_interval = [
                                current_day.year, current_day.month,
                                current_day.day, daily_interval[0][0],
                                daily_interval[0][1]
                            ]
                            _logger.debug(
                                "current_day %s, min_datetime %s, tomorrow %s",
                                str(current_day.date()),
                                str(min_datetime.date()),
                                str((date.today() + timedelta(days=1))))
                            if current_day.date() == date.today() \
                                    or (current_day.date() == min_datetime.date() \
                                    and current_day.date() == (date.today() + timedelta(days=1))) :
                                end_of_interval[
                                    3] += 1  #disable first hour of opening if min_date is today or tomorrow, because order will not be ready
                                _logger.debug("end of interval : %s",
                                              str(end_of_interval))
                            intervals.append(
                                [start_of_interval, end_of_interval])
                            start_of_interval = end_of_interval[0:3] + [
                                daily_interval[1][0], daily_interval[1][1]
                            ]
                        intervals.append([
                            start_of_interval,
                            [
                                current_day.year, current_day.month,
                                current_day.day, 23, 59
                            ]
                        ])

                    else:
                        #all day should be forbidden
                        intervals.append([[
                            current_day.year, current_day.month,
                            current_day.day, 0, 0
                        ],
                                          [
                                              current_day.year,
                                              current_day.month,
                                              current_day.day, 23, 59
                                          ]])
                    current_day += one_day_delta
        return intervals
Example #51
0
def AddQuestionDetails(qlma, jsondatavalues):
    retval = 'Begin 111 AddQuestionDetails:'
    qId, pId, qText, qOptions, qSelOptionId, qCorrectStatus, qTitle, qtype = "", "", "", "", "", "", "", ""
    qAdditionalInfo, q_mqAdditionalInfo = {}, {}
    qTimespent = 0.0
    qScore = 0.0
    qPoints = 0.0
    qTotal = 0.0
    QDetails = {}

    if "QDetails" in jsondatavalues:
        QDetails = jsondatavalues["QDetails"]
    else:
        return retval + "-Not a Question"

    if "QId" in QDetails:
        qId = QDetails["QId"]

    if "PId" in QDetails:
        pId = QDetails["PId"]

    if "QText" in QDetails:
        qText = QDetails["QText"]

    if "QOptions" in QDetails:
        qOptions = QDetails["QOptions"]

    if "QSelOptionId" in QDetails:
        qSelOptionId = QDetails["QSelOptionId"]

    if "QCorrectStatus" in QDetails:
        qCorrectStatus = QDetails["QCorrectStatus"]

    if "QTimeSpent" in QDetails:
        qTimespent = Decimal(str(QDetails["QTimeSpent"]))

    if "QScore" in QDetails:
        qScore = Decimal(str(QDetails["QScore"]))

    if "QPoints" in QDetails:
        qPoints = Decimal(str(QDetails["QPoints"]))

    if "QTotal" in QDetails:
        qTotal = Decimal(str(QDetails["QTotal"]))

    if "AdditionalInfo" in QDetails:
        qAdditionalInfo = QDetails["AdditionalInfo"]

    if "MQAdditionalInfo" in QDetails:
        q_mqAdditionalInfo = QDetails["MQAdditionalInfo"]

    if "QTitle" in QDetails:
        qTitle = QDetails["QTitle"]

    if "Type" in QDetails:
        qtype = QDetails["Type"]

    if qId is not None and qId != "" and qlma is not None:
        try:
            filterQMQ = {"QL_Id": qlma.QL_Id, "QuestionId": qId, "PageId": pId}

            qlmq = None
            try:
                qlmq = m.ql_masterquestions.objects.get(**filterQMQ)
            except Exception as e:
                qlmq = None
                retval = retval + " Error:" + str(e)

            if qlmq is not None:
                qlmq.QuestionText = qText
                qlmq.Options = str(qOptions)
                qlmq.QuestionTitle = qTitle
                qlmq.TotalPoints = qTotal
                qlmq.AdditionalInfo = str(q_mqAdditionalInfo)
                qlmq.save()
            else:
                qlmq = m.ql_masterquestions.objects.create(
                    QL_Id=qlma.QL_Id,
                    PageId=pId,
                    QuestionId=qId,
                    QuestionText=qText,
                    TotalPoints=qTotal,
                    Options=qOptions,
                    QuestionTitle=qTitle,
                    Type=qtype,
                    AdditionalInfo=str(q_mqAdditionalInfo))
            '''Create User's question attempt entry.
            '''
            filterQAtmpt = {
                "MstAttemptId": qlma.Id,
                "PageId": pId,
                "QuestionId": qId
            }

            qlqad = None
            try:
                qlqad = m.ql_questionattemptdetails.objects.get(**filterQAtmpt)
            except Exception as e:
                qlqad = None
                retval = retval + " Error:" + str(e)

            if qlqad is not None:
                retval = retval + "update question details:"
                qlqad.CorrectStatus = qCorrectStatus
                qlqad.TimeSpent = qTimespent
                qlqad.Score = qScore
                qlqad.Points = qPoints
                qlqad.SelOptionId = qSelOptionId
                qlqad.AdditionalInfo = str(qAdditionalInfo)
                qlqad.save()
                retval = retval + "update question details complete:"
            else:
                retval = retval + "Create question details:"
                qlqad = m.ql_questionattemptdetails.objects.create(
                    MstAttemptId=qlma.Id,
                    PageId=pId,
                    QuestionId=qId,
                    CorrectStatus=qCorrectStatus,
                    TimeSpent=qTimespent,
                    Score=qScore,
                    Points=qPoints,
                    SelOptionId=qSelOptionId,
                    AdditionalInfo=str(qAdditionalInfo))
                retval = retval + "Create question details complete:"
        except Exception as ine:
            retval = retval + \
                "ql_questionattemptdetails create_update Error:" + str(ine)

    return retval
Example #52
0
            {
                'city': city,
                'type': bus_type
            }, {'business_id': 1}))
]
print(len(business))

query = {'business_id': {'$in': business}}
raw = list(
    db.yelp_reviews.find(query, {
        'business_id': 1,
        'text': 1,
        'stars': 1,
        'review_id': 1
    }))
print("[Info] Total elements " + str(len(raw)))

print("Step", global_count)
global_count += 1

reviews_df = pd.DataFrame(raw)
reviews_df['sentiment'] = reviews_df.stars.apply(lambda x: _get_sentiment(x))
reviews_df = reviews_df.drop('_id', axis=1)
print(reviews_df.head())

# In[46]:

reviews_df['tokens'] = reviews_df.text.apply(lambda x: token_ze(x))
print(list(reviews_df.columns))
print("Step", global_count)
global_count += 1
Example #53
0
def save_html(outObj, uiObj, dictBeamData, dictColData, reportsummary,
              filename, folder, base, base_front, base_top, base_side):
    fileName = (filename)
    #     self.folder = folder
    myfile = open(fileName, "w")
    myfile.write(t('! DOCTYPE html'))
    myfile.write(t('html'))
    myfile.write(t('head'))
    myfile.write(t('link type="text/css" rel="stylesheet" '))

    ############################   mystyle.css is written here  ##############################################################################
    myfile.write(t('style'))
    myfile.write(
        'table{width= 100%; border-collapse:collapse; border:1px solid black collapse}'
    )
    myfile.write('th,td {padding:3px}')
    myfile.write(
        'td.detail{background-color:#D5DF93; font-size:20; font-family:Helvetica, Arial, Sans Serif; font-weight:bold}'
    )
    myfile.write(
        'td.detail1{font-size:20; font-family:Helvetica, Arial, Sans Serif; font-weight:bold}'
    )
    myfile.write(
        'td.detail2{font-size:20; font-family:Helvetica, Arial, Sans Serif}')
    myfile.write(
        'td.header0{background-color:#8fac3a; font-size:20; font-family:Helvetica, Arial, Sans Serif; font-weight:bold}'
    )
    myfile.write(
        'td.header1{background-color:#E6E6E6; font-size:20; font-family:Helvetica, Arial, Sans Serif; font-weight:bold}'
    )
    myfile.write('td.header2{font-size:20; width:50%}')
    myfile.write(t('/style'))
    ##############################################################################################################################################

    myfile.write(t('/head'))
    myfile.write(t('body'))
    #     Connections/Shear/Finplate/
    #&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
    # DATA PARAMS
    #&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
    #Project summary data
    companyname = str(reportsummary["ProfileSummary"]['CompanyName'])
    companylogo = str(reportsummary["ProfileSummary"]['CompanyLogo'])

    groupteamname = str(reportsummary["ProfileSummary"]['Group/TeamName'])
    designer = str(reportsummary["ProfileSummary"]['Designer'])
    projecttitle = str(reportsummary['ProjectTitle'])
    subtitle = str(reportsummary['Subtitle'])
    jobnumber = str(reportsummary['JobNumber'])
    method = str(reportsummary['Method'])
    addtionalcomments = str(reportsummary['AdditionalComments'])

    #&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
    #FinPlate Main Data
    connectivity = str(uiObj['Member']['Connectivity'])
    shear_load = str(uiObj['Load']['ShearForce (kN)'])
    column_sec = str(uiObj['Member']['ColumSection'])
    beam_sec = str(uiObj['Member']['BeamSection'])
    plateThick = str(uiObj['Plate']['Thickness (mm)'])
    boltType = str(uiObj['Bolt']['Type'])
    boltGrade = str(uiObj['Bolt']['Grade'])
    boltDia = str(uiObj['Bolt']['Diameter (mm)'])
    #'Size (mm)'
    weld_Thick = str(uiObj['Weld']['Size (mm)'])

    beamdepth = str(int(round(outObj['Plate']['beamdepth'], 1)))
    beamflangethk = str(int(round(outObj['Plate']['beamflangethk'], 1)))
    beamrootradius = str(int(round(outObj['Plate']['beamrootradius'], 1)))
    platethk = str(int(round(outObj['Plate']['platethk'], 1)))
    blockshear = str(int(round(outObj['Plate']['blockshear'], 1)))
    colflangethk = str(int(round(outObj['Plate']["colflangethk"], 1)))
    colrootradius = str(int(round(outObj['Plate']['colrootradius'])))

    plateWidth = str(int(round(outObj['Plate']['width'], 1)))
    plateLength = str(int(round(outObj['Plate']['height'], 1)))
    weldSize = str(int(round(outObj['Weld']['thickness'], 1)))

    plateDimension = plateLength + 'X' + plateWidth + 'X' + plateThick
    noOfBolts = str(outObj['Bolt']['numofbolts'])
    noOfRows = str(outObj['Bolt']['numofrow'])
    noOfCol = str(outObj['Bolt']['numofcol'])
    edge = str(int(round(outObj['Bolt']['edge'], 1)))
    gauge = str(int(round(outObj['Bolt']['gauge'], 1)))
    pitch = str(int(round(outObj['Bolt']['pitch'], 1)))
    end = str(int(round(outObj['Bolt']['enddist'], 1)))
    weld_strength = str(round(float(outObj['Weld']['weldstrength'] / 1000), 3))
    moment_demand = str(outObj['Plate']['externalmoment'])
    gap = '20'
    beam_tw = str(float(dictBeamData[QString("tw")]))

    bolt_fu = str(outObj['Bolt']['bolt_fu'])
    bolt_dia = str(outObj['Bolt']['bolt_dia'])
    kb = str(outObj['Bolt']['k_b'])
    beam_w_t = str(outObj['Bolt']['beam_w_t'])
    web_plate_t = str(outObj['Bolt']['web_plate_t'])
    beam_fu = str(outObj['Bolt']['beam_fu'])
    dia_hole = str(outObj['Bolt']['dia_hole'])
    web_plate_fy = str(outObj['Plate']['web_plate_fy'])
    weld_fu = str(outObj['Weld']['weld_fu'])
    weld_l = str(outObj['Weld']['effectiveWeldlength'])
    shearCapacity = str(round(outObj['Bolt']['shearcapacity'], 3))
    bearingcapacity = str(round(outObj['Bolt']['bearingcapacity'], 4))
    momentDemand = str(outObj['Plate']['externalmoment'])

    #&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
    # Header of the pdf fetched from dialogbox
    rstr = t(
        'table border-collapse= "collapse" border="1px solid black" width=100%'
    )
    rstr += t('tr')
    row = [
        0,
        '<object type= "image/PNG" data= "css/cmpylogoFin.png" height=60 ></object>',
        '<font face="Helvetica, Arial, Sans Serif" size="3">Created with</font>'
        ' &nbsp'
        '<object type= "image/PNG" data= "css/Osdag_header.png" height=60 '
        '&nbsp></object>'
    ]
    rstr += t('td colspan="2" align= "center"') + space(
        row[0]) + row[1] + t('/td')
    rstr += t('td colspan="2" align= "right"') + row[2] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    row = [0, 'Company Name']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    #     rstr += t('td style= "font:bold 20px Helvetica, Arial, Sans Serif;background-color:#D5DF93"') + space(row[0]) + row[1] + t('/td')
    row = [0, companyname]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')

    row = [0, 'Project Title']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, projecttitle]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    row = [0, 'Group/Team Name']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, groupteamname]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, 'Subtitle']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, subtitle]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    row = [0, 'Designer']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, designer]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, 'Job Number']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, jobnumber]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    row = [0, 'Date']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, time.strftime("%d /%m /%Y")]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, 'Method']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, method]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    rstr += t('/tr')
    rstr += t('/table')

    rstr += t('hr')
    #     rstr += t('p> &nbsp</p')
    rstr += t('/hr')

    #&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
    #Design Conclusion
    #     rstr += t('table width = 100% border-collapse= "collapse" border="1px solid black"')
    rstr += t(
        'table border-collapse= "collapse" border="1px solid black" width= 100% '
    )

    row = [0, 'Design Conclusion', "IS800:2007/Limit state design"]
    rstr += t('tr')
    rstr += t('td colspan="2" class="header0"') + space(
        row[0]) + row[1] + t('/td')
    rstr += t('/tr')

    row = [1, "Finplate", "<p align=left style=color:green><b>Pass</b></p>"]
    rstr += t('tr')
    rstr += t('td class="detail1 "') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail1"') + row[2] + t('/td')
    #rstr += t('td class="header1 safe"') + row[3] + t('/td')
    rstr += t('/tr')

    row = [0, "Finplate", " "]
    rstr += t('tr')
    rstr += t('td colspan="2" class="header0"') + space(
        row[0]) + row[1] + t('/td')
    rstr += t('/tr')

    row = [0, "Connection Properties", " "]
    rstr += t('tr')
    rstr += t('td colspan="2" class="detail"') + space(
        row[0]) + row[1] + t('/td')
    rstr += t('/tr')

    row = [0, "Connection ", " "]
    rstr += t('tr')
    rstr += t('td colspan="2" class="detail1"') + space(
        row[0]) + row[1] + t('/td')
    rstr += t('/tr')

    row = [1, "Connection Title", " Single Finplate"]
    rstr += t('tr')
    rstr += t('td class="detail2"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2 "') + row[2] + t('/td')
    rstr += t('/tr')

    row = [1, "Connection Type", "Shear Connection"]
    rstr += t('tr')
    rstr += t('td class="detail2"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2 "') + row[2] + t('/td')
    rstr += t('/tr')

    row = [0, "Connection Category ", " "]
    rstr += t('tr')
    rstr += t('td colspan="2" class="detail1"') + space(
        row[0]) + row[1] + t('/td')
    rstr += t('/tr')

    #row = [1, "Connectivity", "Column Web Beam Web"]
    row = [1, "Connectivity", connectivity]
    rstr += t('tr')
    rstr += t('td class="detail2"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2 "') + row[2] + t('/td')
    rstr += t('/tr')

    row = [1, "Beam Connection", "Bolted"]
    rstr += t('tr')
    rstr += t('td class="detail2"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2 "') + row[2] + t('/td')
    rstr += t('/tr')

    #
    row = [1, "Column Connection", "Welded"]
    rstr += t('tr')
    rstr += t('td class="detail2"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2 "') + row[2] + t('/td')
    rstr += t('/tr')

    row = [0, "Loading (Factored Load) ", " "]
    rstr += t('tr')
    rstr += t('td colspan="2" class="detail1"') + space(
        row[0]) + row[1] + t('/td')
    rstr += t('/tr')

    #row = [1, "Shear Force (kN)", "140"]
    row = [1, "Shear Force (kN)", shear_load]
    rstr += t('tr')
    rstr += t('td class="detail2"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2 "') + row[2] + t('/td')
    rstr += t('/tr')

    row = [0, "Components ", " "]
    rstr += t('tr')
    rstr += t('td colspan="2" class="detail1"') + space(
        row[0]) + row[1] + t('/td')
    rstr += t('/tr')

    #row = [1, "Column Section", "ISSC 200"]
    row = [1, "Column Section", column_sec]

    rstr += t('tr')
    rstr += t('td class="detail1"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2 "') + row[2] + t('/td')
    rstr += t('/tr')

    row = [2, "Material", "Fe " + beam_fu]
    rstr += t('tr')
    rstr += t('td class="detail2"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2 "') + row[2] + t('/td')
    rstr += t('/tr')

    #row = [1, "Beam Section", "ISMB 400"]
    row = [1, "Beam Section", beam_sec]
    rstr += t('tr')
    rstr += t('td class="detail1"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2 "') + row[2] + t('/td')
    rstr += t('/tr')

    row = [2, "Material", "Fe " + beam_fu]
    rstr += t('tr')
    rstr += t('td class="detail2"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2 "') + row[2] + t('/td')
    rstr += t('/tr')

    row = [2, "Hole", "STD"]
    rstr += t('tr')
    rstr += t('td class="detail2"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2 "') + row[2] + t('/td')
    rstr += t('/tr')

    #row = [1, "Plate Section ", "PLT 300X10X100 "]
    row = [1, "Plate Section", plateDimension]
    rstr += t('tr')
    rstr += t('td class="detail1"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2 "') + row[2] + t('/td')
    rstr += t('/tr')

    #row = [2, "Thickness (mm)", "10"]
    row = [2, "Thickness (mm)", plateThick]
    rstr += t('tr')
    rstr += t('td class="detail2"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2 "') + row[2] + t('/td')
    rstr += t('/tr')

    #row = [2, "Width (mm)", "10"]
    row = [2, "Width (mm)", plateWidth]
    rstr += t('tr')
    rstr += t('td class="detail2"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2 "') + row[2] + t('/td')
    rstr += t('/tr')

    #row = [2, "Depth (mm)", "300"]
    row = [2, "Depth (mm)", plateLength]
    rstr += t('tr')
    rstr += t('td class="detail2"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2 "') + row[2] + t('/td')
    rstr += t('/tr')

    row = [2, "Hole", "STD"]
    rstr += t('tr')
    rstr += t('td class="detail2"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2 "') + row[2] + t('/td')
    rstr += t('/tr')

    row = [1, "Weld ", " "]
    rstr += t('tr')
    rstr += t('td colspan="2" class="detail1"') + space(
        row[0]) + row[1] + t('/td')
    rstr += t('/tr')

    row = [2, "Type", "Double Fillet"]
    rstr += t('tr')
    rstr += t('td class="detail2"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2 "') + row[2] + t('/td')
    rstr += t('/tr')

    #row = [2, "Size (mm)", "6"]
    row = [2, "Size (mm)", weldSize]
    rstr += t('tr')
    rstr += t('td class="detail2"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2 "') + row[2] + t('/td')
    rstr += t('/tr')

    row = [1, "Bolts ", " "]
    rstr += t('tr')
    rstr += t('td colspan="2" class="detail1"') + space(
        row[0]) + row[1] + t('/td')
    rstr += t('/tr')

    #row = [2, "Type", "HSFG"]
    row = [2, "Type", boltType]
    rstr += t('tr')
    rstr += t('td class="detail2"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2 "') + row[2] + t('/td')
    rstr += t('/tr')

    #row = [2, "Grade", "8.8"]
    row = [2, "Grade", boltGrade]
    rstr += t('tr')
    rstr += t('td class="detail2"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2 "') + row[2] + t('/td')
    rstr += t('/tr')

    #row = [2, "Diameter (mm)", "20"]
    row = [2, "Diameter (mm)", boltDia]
    rstr += t('tr')
    rstr += t('td class="detail2"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2 "') + row[2] + t('/td')
    rstr += t('/tr')

    #row = [2, "Bolt Numbers", "3"]
    row = [2, "Bolt Numbers", noOfBolts]
    rstr += t('tr')
    rstr += t('td class="detail2"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2 "') + row[2] + t('/td')
    rstr += t('/tr')

    #row = [2, "Columns (Vertical Lines)", "1 "]
    row = [2, "Columns (Vertical Lines)", noOfCol]
    rstr += t('tr')
    rstr += t('td class="detail2"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2 "') + row[2] + t('/td')
    rstr += t('/tr')

    #row = [2, "Bolts Per Column", "3"]
    row = [2, "Bolts Per Column", noOfRows]
    rstr += t('tr')
    rstr += t('td class="detail2"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2 "') + row[2] + t('/td')
    rstr += t('/tr')

    #row = [2, "Gauge (mm)", "0"]
    row = [2, "Gauge (mm)", gauge]
    rstr += t('tr')
    rstr += t('td class="detail2"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2 "') + row[2] + t('/td')
    rstr += t('/tr')

    #row = [2, "Pitch (mm)", "100"]
    row = [2, "Pitch (mm)", pitch]
    rstr += t('tr')
    rstr += t('td class="detail2"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2 "') + row[2] + t('/td')
    rstr += t('/tr')

    #row = [2, "End Distance (mm)", "50"]
    row = [2, "End Distance (mm)", end]
    rstr += t('tr')
    rstr += t('td class="detail2"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2"') + row[2] + t('/td')
    rstr += t('/tr')

    #row = [2, "Edge Distance (mm)", "50"]
    row = [2, "Edge Distance (mm)", edge]
    rstr += t('tr')
    rstr += t('td class="detail2"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2 "') + row[2] + t('/td')
    rstr += t('/tr')

    row = [0, "Assembly ", " "]
    rstr += t('tr')
    rstr += t('td colspan="2" class="detail1"') + space(
        row[0]) + row[1] + t('/td')
    rstr += t('/tr')

    #row = [1, "Column-Beam Clearance (mm)", "20"]
    row = [1, "Column-Beam Clearance (mm)", gap]
    rstr += t('tr')
    rstr += t('td class="detail1"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2 "') + row[2] + t('/td')
    rstr += t('/tr')

    rstr += t('/table')
    rstr += t('h1 style="page-break-before:always"')  # page break
    rstr += t('/h1')

    #*************************************************************************************************************************
    #&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
    # Header of the pdf fetched from dialogbox
    rstr += t(
        'table width= 100% border-collapse= "collapse" border="1px solid black collapse"'
    )
    rstr += t('tr')
    row = [
        0,
        '<object type= "image/PNG" data= "css/cmpylogoFin.png" height=60 ></object>',
        '<font face="Helvetica, Arial, Sans Serif" size="3">Created with</font>'
        ' &nbsp'
        '<object type= "image/PNG" data= "css/Osdag_header.png" height=60></object>'
    ]
    rstr += t('td colspan="2" align= "center"') + space(
        row[0]) + row[1] + t('/td')
    rstr += t('td colspan="2" align= "right"') + row[2] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    row = [0, 'Company Name']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    #     rstr += t('td style= "font:bold 20px Helvetica, Arial, Sans Serif;background-color:#D5DF93"') + space(row[0]) + row[1] + t('/td')
    row = [0, companyname]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')

    row = [0, 'Project Title']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, projecttitle]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    row = [0, 'Group/Team Name']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, groupteamname]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, 'Subtitle']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, subtitle]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    row = [0, 'Designer']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, designer]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, 'Job Number']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, jobnumber]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    row = [0, 'Date']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, time.strftime("%d /%m /%Y")]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, 'Method']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, method]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    rstr += t('/tr')
    rstr += t('/table')

    rstr += t('hr')
    #     rstr += t('p> &nbsp</p')
    #     rstr += t('hr')
    #     rstr += t('/hr')
    rstr += t('/hr')

    #*************************************************************************************************************************
    #&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
    #Design Check

    rstr += t(
        'table width = 100% border-collapse= "collapse" border="1px solid black"'
    )
    row = [0, "Design Check", " "]
    rstr += t('tr')
    rstr += t('td colspan="4" class="detail"') + space(
        row[0]) + row[1] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    row = [0, "Check", "Required", "Provided", "Remark"]
    rstr += t('td class="header1"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="header1"') + space(row[0]) + row[2] + t('/td')
    rstr += t('td class="header1"') + space(row[0]) + row[3] + t('/td')
    rstr += t('td class="header1"') + space(row[0]) + row[4] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    const = str(round(math.pi / 4 * 0.78, 4))
    #row =[0,"Bolt shear capacity (kN)"," ","<i>V</i><sub>dsb</sub> = ((800*0.6123*20*20)/(&#8730;3*1.25*1000) = 90.53 <br> [cl. 10.3.3]"]
    row = [
        0, "Bolt shear capacity (kN)", " ", "<i>V</i><sub>dsb</sub> = (" +
        bolt_fu + "*" + const + "*" + bolt_dia + "*" + bolt_dia +
        ")/(&#8730;3*1.25*1000) = " + shearCapacity + "<br> [cl. 10.3.3]", ""
    ]
    rstr += t('td class="detail1"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[2] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[3] + t('/td')
    rstr += t('td class="detail1"') + space(row[0]) + row[4] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    #row =[0,"Bolt bearing capacity (kN)",""," <i>V</i><sub>dsb</sub> = (2.5*0.5*20*8.9*410)  = 72.98<br> [cl. 10.3.4]"]
    row = [
        0, "Bolt bearing capacity (kN)", "",
        " <i>V</i><sub>dpb</sub> = (2.5*" + kb + "*" + bolt_dia + "*" +
        beam_tw + "*" + beam_fu + ")/(1.25*1000)  = " + bearingcapacity +
        "<br> [cl. 10.3.4]", ""
    ]
    rstr += t('td class="detail1"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[2] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[3] + t('/td')
    rstr += t('td class="detail1"') + space(row[0]) + row[4] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    #row =[0,"Bolt capacity (kN)","","Min (90.53,72.98) = 72.98","<p align=right style=color:green><b>Pass</b></p>"]
    boltCapacity = bearingcapacity if bearingcapacity < shearCapacity else shearCapacity
    row = [
        0, "Bolt capacity (kN)", "", "Min (" + shearCapacity + ", " +
        bearingcapacity + ") = " + boltCapacity, ""
    ]
    rstr += t('td class="detail1"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[2] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[3] + t('/td')
    rstr += t('td class="detail1"') + space(row[0]) + row[4] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    #row =[0,"No. of bolts","140/72.98 = 1.9","3","<p align=right style=color:green><b>Pass</b></p>"]
    bolts = str(round(float(shear_load) / float(boltCapacity), 1))
    row = [
        0, "No. of bolts", shear_load + "/" + boltCapacity + " = " + bolts,
        noOfBolts, " <p align=left style=color:green><b>Pass</b></p>"
    ]
    rstr += t('td class="detail1"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[2] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[3] + t('/td')
    rstr += t('td class="detail1"') + space(row[0]) + row[4] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    #row =[0,"No.of column(s)","&#8804;2","1"]
    row = [0, "No.of column(s)", " &#8804; 2", noOfCol, ""]
    rstr += t('td class="detail1"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[2] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[3] + t('/td')
    rstr += t('td class="detail1"') + space(row[0]) + row[4] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    #row =[0,"No. of bolts per column"," ","3"]
    row = [0, "No. of bolts per column", " ", noOfRows, ""]
    rstr += t('td class="detail1"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[2] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[3] + t('/td')
    rstr += t('td class="detail1"') + space(row[0]) + row[4] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    #row =[0,"Bolt pitch (mm)","&#8805;2.5*20 = 50, &#8804; Min(32*8.9, 300) = 300 <br> [cl. 10.2.2]","100"]
    minPitch = str(int(2.5 * float(bolt_dia)))
    maxPitch = str(300) if 32 * float(beam_tw) > 300 else str(
        int(math.ceil(32 * float(beam_tw))))
    row = [
        0, "Bolt pitch (mm)",
        " &#8805; 2.5* " + bolt_dia + " = " + minPitch + ",  &#8804; Min(32*" +
        beam_tw + ", 300) = " + maxPitch + "<br> [cl. 10.2.2]", pitch,
        "  <p align=left style=color:green><b>Pass</b></p>"
    ]
    rstr += t('td class="detail1"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[2] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[3] + t('/td')
    rstr += t('td class="detail1"') + space(row[0]) + row[4] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    #row =[0,"Bolt gauge (mm)","&#8805;2.5*20 = 50,&#8804; Min(32*8.9, 300) = 300 <br> [cl. 10.2.2]","0"]
    minGauge = str(int(2.5 * float(bolt_dia)))
    maxGauge = str(300) if 32 * float(beam_tw) > 300 else str(
        int(math.ceil(32 * float(beam_tw))))
    row = [
        0, "Bolt gauge (mm)",
        " &#8805; 2.5*" + bolt_dia + " = " + minGauge + ", &#8804; Min(32*" +
        beam_tw + ", 300) = " + maxGauge + " <br> [cl. 10.2.2]", gauge, ""
    ]
    rstr += t('td class="detail1"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[2] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[3] + t('/td')
    rstr += t('td class="detail1"') + space(row[0]) + row[4] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    #row =[0,"End distance (mm)","&#8805;1.7* 22 = 37.4,&#8804;12*8.9 = 106.9 <br> [cl. 10.2.4]","50"]
    minEnd = str(1.7 * float(dia_hole))
    maxEnd = str(12 * float(beam_tw))
    row = [
        0, "End distance (mm)", " &#8805; 1.7*" + dia_hole + " = " + minEnd +
        ", &#8804; 12*" + beam_tw + " = " + maxEnd + " <br> [cl. 10.2.4]", end,
        "  <p align=left style=color:green><b>Pass</b></p>"
    ]
    rstr += t('td class="detail1"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[2] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[3] + t('/td')
    rstr += t('td class="detail1"') + space(row[0]) + row[4] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    #row =[0,"Edge distance (mm)","&#8805; 1.7* 22 = 37.4,&#8804;12*8.9 = 106.9<br> [cl. 10.2.4]","50"," <p align=right style=color:green><b>Pass</b></p>"]
    minEdge = str(1.7 * float(dia_hole))
    maxEdge = str(12 * float(beam_tw))
    row = [
        0, "Edge distance (mm)", " &#8805; 1.7*" + dia_hole + " = " + minEdge +
        ", &#8804; 12*" + beam_tw + " = " + maxEdge + "<br> [cl. 10.2.4]",
        edge, " <p align=left style=color:green><b>Pass</b></p>"
    ]
    rstr += t('td class="detail1"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[2] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[3] + t('/td')
    rstr += t('td class="detail1"') + space(row[0]) + row[4] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    row = [
        0, "Block shear capacity (kN)", " &#8805; " + shear_load,
        "<i>V</i><sub>db</sub> = " + blockshear + "<br>",
        "  <p align=left style=color:green><b>Pass</b></p>"
    ]
    rstr += t('td class="detail1"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[2] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[3] + t('/td')
    rstr += t('td class="detail1"') + space(row[0]) + row[4] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    #row =[0,"Plate thickness (mm)","(5*140*1000)/(300*250)= 9.33","10"]
    minPlateThick = str(
        round(
            5 * float(shear_load) * 1000 /
            (float(plateLength) * float(web_plate_fy)), 2))
    row = [
        0, "Plate thickness (mm)",
        "(5*" + shear_load + "*1000)/(" + plateLength + "*" + web_plate_fy +
        ") = " + minPlateThick + "<br> [Owens and Cheal, 1989]", plateThick,
        "  <p align=left style=color:green><b>Pass</b></p>"
    ]
    rstr += t('td class="detail1"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[2] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[3] + t('/td')
    rstr += t('td class="detail1"') + space(row[0]) + row[4] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    #     if
    minEdge = str(0.6 * float(beamdepth))
    if connectivity == "Beam-Beam":
        maxEdge = str(
            float(beamdepth) - float(beamflangethk) - float(beamrootradius) -
            float(colflangethk) - float(colrootradius) - 5)
        maxedgestring = beamdepth + "-" + beamflangethk + "-" + beamrootradius + "-" + colflangethk + "-" + colrootradius + "- 5"
    else:
        maxEdge = str(
            float(beamdepth) - 2 * float(beamflangethk) -
            2 * float(beamrootradius) - 10)
        maxedgestring = beamdepth + "-" + beamflangethk + "-" + beamrootradius + "-" + "10"

    row = [
        0, "Plate height (mm)", "&#8805; 0.6*" + beamdepth + "=" + minEdge +
        ", &#8804; " + maxedgestring + "=" + maxEdge +
        "<br> [cl. 10.2.4, Insdag Detailing Manual, 2002]", plateLength,
        " <p align=left style=color:green><b>Pass</b></p>", "300", ""
    ]
    #        #row =[0,"Plate height (mm)","",plateLength]
    rstr += t('td class="detail1"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[2] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[3] + t('/td')
    rstr += t('td class="detail1"') + space(row[0]) + row[4] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    row = [0, "Plate width (mm)", "", "100", ""]
    #row =[0,"Plate width (mm)","",plateWidth]
    rstr += t('td class="detail1"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[2] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[3] + t('/td')
    rstr += t('td class="detail1"') + space(row[0]) + row[4] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    #row =[0,"Plate moment capacity (kNm)","(2*90.5*100<sup>2</sup>)/100 = 18.1","<i>M</i><sub>d</sub> =1.2*250*<i>Z</i> = 40.9 <br>[cl. 8.2.1.2]","<p align=right style=color:green><b>Pass</b></p>"]
    z = math.pow(float(plateLength), 2) * (float(plateThick) /
                                           (6 * 1.1 * 1000000))
    momentCapacity = str(round(1.2 * float(web_plate_fy) * z, 2))
    row = [
        0, "Plate moment capacity (kNm)", "(2*" + shearCapacity + "*" + pitch +
        "<sup>2</sup>)/(" + pitch + "*1000) = " + moment_demand,
        "<i>M</i><sub>d</sub> = (1.2*" + web_plate_fy +
        "*<i>Z</i>)/(1000*1.1) = " + momentCapacity + "<br>[cl. 8.2.1.2]",
        "<p align=left style=color:green><b>Pass</b></p>"
    ]
    rstr += t('td class="detail1"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[2] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[3] + t('/td')
    rstr += t('td class="detail1"') + space(row[0]) + row[4] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    #row =[0,"Effective weld length (mm)","","300 - 2*6 = 288"]
    effWeldLen = str(int(float(plateLength) - (2 * float(weld_Thick))))
    row = [
        0, "Effective weld length (mm)", "",
        plateLength + "-2*" + weld_Thick + " = " + effWeldLen, ""
    ]
    rstr += t('td class="detail1"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[2] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[3] + t('/td')
    rstr += t('td class="detail1"') + space(row[0]) + row[4] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    #row =[0,"Weld strength (kN/mm)","&#8730;[(18100*6)/(2*288)<sup>2</sup>]<sup>2</sup> + [140/(2*288)]<sup>2</sup> <br>=0.699","<i>f</i><sub>v</sub>=(0.7*6*410)/(&#8730;3*1.25)<br>= 0.795<br>[cl. 10.5.7]"," <p align=right style=color:green><b>Pass</b></p>"]
    a = float(2 * float(effWeldLen))
    b = 2 * math.pow((float(effWeldLen)), 2)
    x = (float(momentDemand) * 1000 * 6)
    resultant_shear = str(
        round(
            math.sqrt(
                math.pow((x / b), 2) + math.pow((float(shear_load) / a), 2)),
            3))
    momentDemand_knmm = str(int(float(momentDemand) * 1000))
    row = [
        0, "Weld strength (kN/mm)",
        " &#8730;[(" + momentDemand_knmm + "*6)/(2*" + effWeldLen +
        "<sup>2</sup>)]<sup>2</sup> + [" + shear_load + "/(2*" + effWeldLen +
        ")]<sup>2</sup> <br>= " + resultant_shear,
        "<i>f</i><sub>v</sub>= (0.7*" + weldSize + "*" + weld_fu +
        ")/(&#8730;3*1.25)<br>= " + weld_strength + "<br>[cl. 10.5.7]",
        " <p align=left style=color:green><b>Pass</b></p>"
    ]
    rstr += t('td class="detail1"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[2] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[3] + t('/td')
    rstr += t('td class="detail1"') + space(row[0]) + row[4] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    #row =[0,"Weld thickness (mm)","(0.699*&#8730;3*1.25)/(0.7*410)=5.27<br>[cl. 10.5.7]","6","<p align=right style=color:green><b>Pass</b></p>"]

    weld_thickness = str(
        round((float(resultant_shear) * 1000 * (math.sqrt(3) * 1.25)) /
              (0.7 * float(weld_fu)), 2))
    x = str((float(platethk) * 0.8))
    maxweld = str(max(float(weld_thickness), float(x)))
    #     maxweld = str(9) if str((float( platethk)*0.8)) > str(9) else str(round((float(resultant_shear) * 1000*(math.sqrt(3) * 1.25))/(0.7 * float(weld_fu)),2))
    #     maxWeld = str(9) if str(round((float(resultant_shear) * 1000*(math.sqrt(3) * 1.25))/(0.7 * float(weld_fu)),2)) == 9 else str((float( platethk)*0.8))
    #     row =[0,"Weld thickness (mm)","Max(("+resultant_shear+"*&#8730;3*1.25)/(0.7*"+weld_fu+")"+", 0.8*"+platethk+") = "+ maxWeld + "<br>[cl. 10.5.7, Insdag Detailing Manual, 2002]",weldSize,"<p align=right style=color:green><b>Pass</b></p>"]
    row = [
        0, "Weld thickness (mm)",
        "Max((" + resultant_shear + "*1000*&#8730;3* 1.25)/(0.7 * " + weld_fu +
        ")" + "," + platethk + "* 0.8" + ") = " + maxweld +
        "<br>[cl. 10.5.7, Insdag Detailing Manual, 2002]", weldSize,
        "<p align=left style=color:green><b>Pass</b></p>"
    ]

    rstr += t('td class="detail1"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[2] + t('/td')
    rstr += t('td class="detail2"') + space(row[0]) + row[3] + t('/td')
    rstr += t('td class="detail1"') + space(row[0]) + row[4] + t('/td')

    rstr += t('/table')
    rstr += t('h1 style="page-break-before:always"')  # page break
    rstr += t('/h1')

    #*************************************************************************************************************************
    #&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
    # Header of the pdf fetched from dialogbox
    rstr += t(
        'table width= 100% border-collapse= "collapse" border="1px solid black collapse"'
    )
    rstr += t('tr')
    row = [
        0,
        '<object type= "image/PNG" data= "css/cmpylogoFin.png" height=60 ></object>',
        '<font face="Helvetica, Arial, Sans Serif" size="3">Created with</font>'
        ' &nbsp'
        '<object type= "image/PNG" data= "css/Osdag_header.png" height=60></object>'
    ]
    rstr += t('td colspan="2" align= "center"') + space(
        row[0]) + row[1] + t('/td')
    rstr += t('td colspan="2" align= "right"') + row[2] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    row = [0, 'Company Name']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    #     rstr += t('td style= "font:bold 20px Helvetica, Arial, Sans Serif;background-color:#D5DF93"') + space(row[0]) + row[1] + t('/td')
    row = [0, companyname]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')

    row = [0, 'Project Title']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, projecttitle]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    row = [0, 'Group/Team Name']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, groupteamname]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, 'Subtitle']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, subtitle]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    row = [0, 'Designer']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, designer]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, 'Job Number']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, jobnumber]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    row = [0, 'Date']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, time.strftime("%d /%m /%Y")]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, 'Method']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, method]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    rstr += t('/tr')
    rstr += t('/table')

    rstr += t('hr')
    #     rstr += t('p> &nbsp</p')
    #     rstr += t('hr')
    #     rstr += t('/hr')
    rstr += t('/hr')

    #*************************************************************************************************************************
    #&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

    #&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
    #Digram

    rstr += t(
        'table width = 100% border-collapse= "collapse" border="1px solid black"'
    )

    row = [0, "Views", " "]
    rstr += t('tr')
    rstr += t('td colspan="2" class=" detail"') + space(
        row[0]) + row[1] + t('/td')
    #rstr += t('td class=" viewtbl "') + row[2] + t('/td')
    rstr += t('/tr')
    #     import os, os.path, time
    #     date_string = time.strftime("%Y-%m-%d %H:%M")
    if connectivity == "Column flange-Beam web":
        png = folder + "/css/" + base
        datapng = '<object type="image/PNG" data= %s width ="450"></object>' % png

        side = folder + "/css/" + base_side
        dataside = '<object type="image/svg+xml" data= %s width ="400"></object>' % side

        top = folder + "/css/" + base_top
        datatop = '<object type="image/svg+xml" data= %s width ="400"></object>' % top

        front = folder + "/css/" + base_front
        datafront = '<object type="image/svg+xml" data= %s width ="450"></object>' % front

    elif connectivity == "Column web-Beam web":
        png = folder + "/css/" + base
        datapng = '<object type="image/PNG" data= %s width ="450"></object">' % png

        side = folder + "/css/" + base_side
        dataside = '<object type="image/svg+xml" data= %s width ="400"></object>' % side

        top = folder + "/css/" + base_top
        datatop = '<object type="image/svg+xml" data= %s width ="400"></object>' % top

        front = folder + "/css/" + base_front
        datafront = '<object type="image/svg+xml" data= %s width ="450"></object>' % front


#

    else:
        png = folder + "/css/" + base
        datapng = '<object type="image/PNG" data= %s width ="450"></object">' % png

        side = folder + "/css/" + base_side
        dataside = '<object type="image/svg+xml" data= %s width ="400"></object>' % side

        top = folder + "/css/" + base_top
        datatop = '<object type="image/svg+xml" data= %s width ="400"></object>' % top

        front = folder + "/css/" + base_front
        datafront = '<object type="image/svg+xml" data= %s width ="450"></object>' % front

    row = [0, datapng, datatop]
    rstr += t('tr')
    rstr += t('td  align="center" class=" header2"') + space(
        row[0]) + row[1] + t('/td')
    rstr += t('td  align="center" class=" header2"') + row[2] + t('/td')
    rstr += t('/tr')

    row = [0, dataside, datafront]
    #img src="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0...">
    rstr += t('tr')
    rstr += t('td align="center" class=" header2"') + space(
        row[0]) + row[1] + t('/td')
    rstr += t('td align="center" class=" header2 "') + row[2] + t('/td')
    rstr += t('/tr')

    rstr += t('/table')
    rstr += t('h1 style="page-break-before:always"')  # page break
    rstr += t('/h1')

    #*************************************************************************************************************************
    #&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
    # Header of the pdf fetched from dialogbox
    rstr += t(
        'table width= 100% border-collapse= "collapse" border="1px solid black collapse"'
    )
    rstr += t('tr')
    row = [
        0,
        '<object type= "image/PNG" data= "css/cmpylogoFin.png" height=60 ></object>',
        '<font face="Helvetica, Arial, Sans Serif" size="3">Created with</font>'
        ' &nbsp'
        '<object type= "image/PNG" data= "css/Osdag_header.png" height=60></object>'
    ]
    rstr += t('td colspan="2" align= "center"') + space(
        row[0]) + row[1] + t('/td')
    rstr += t('td colspan="2" align= "right"') + row[2] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    row = [0, 'Company Name']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    #     rstr += t('td style= "font:bold 20px Helvetica, Arial, Sans Serif;background-color:#D5DF93"') + space(row[0]) + row[1] + t('/td')
    row = [0, companyname]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')

    row = [0, 'Project Title']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, projecttitle]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    row = [0, 'Group/Team Name']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, groupteamname]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, 'Subtitle']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, subtitle]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    row = [0, 'Designer']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, designer]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, 'Job Number']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, jobnumber]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    rstr += t('/tr')

    rstr += t('tr')
    row = [0, 'Date']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, time.strftime("%d /%m /%Y")]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, 'Method']
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    row = [0, method]
    rstr += t('td class="detail" ') + space(row[0]) + row[1] + t('/td')
    rstr += t('/tr')
    rstr += t('/table')

    rstr += t('hr')
    #     rstr += t('p> &nbsp</p')
    #     rstr += t('hr')
    #     rstr += t('/hr')
    rstr += t('/hr')

    #*************************************************************************************************************************
    #&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

    #&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
    #Additional comments

    rstr += t(
        'table width = 100% border-collapse= "collapse" border="1px solid black"'
    )
    rstr += t('''col width=30%''')
    rstr += t('''col width=70%''')

    rstr += t('tr')
    row = [0, "Additional Comments", addtionalcomments]
    rstr += t('td class= "detail1"') + space(row[0]) + row[1] + t('/td')
    rstr += t('td class= "detail2" align="justified"') + row[2] + t('/td')
    rstr += t('/tr')

    rstr += t('/table')

    myfile.write(rstr)
    myfile.write(t('/body'))
    myfile.write(t('/html'))
    myfile.close()
Example #54
0
    def GLBUCB(self, users, numActions, rank):

        # Set the environment and initialize

        self.MAX = 99999.0
        self.MIN = -99999.0
        self.numActions = numActions
        self.users = users

        self.rank = rank

        self.payoffSums = [[0.0 for i in range(0, self.numActions)] for j in range (0,self.users)]
        self.numPlays = [[1 for i in range(0, self.numActions)] for j in range (0,self.users)]
        #self.ucbs = [[self.MAX for i in range(0, self.numActions)] for j in range (0,self.users)]

        self.estR = [[self.MIN for i in range(0, self.numActions)] for j in range (0,self.users)]
        self.B = [0 for i in range(0,self.numActions)]
        self.max_take = [[self.MIN for i in range(0, self.numActions)] for j in range (0,self.users)]
        
        self.numRounds = 2000
        
        self.arm_reward = [[0.0 for i in range(0, self.numActions)] for j in range (0,self.users)]
        self.bestAction = [0 for i in range(0,self.users)]

        self.Col = [0 for i in range(0,self.numActions)]


        self.means = [[0.0 for i in range(0, self.numActions)] for j in range (0,self.users)]
        
        # Read the environment
        self.readenv(6)
        
        self.explore = int(1.0*math.ceil(math.sqrt(self.users)))
        print "Explore Factor: " + str(self.explore)
        
        
        cumulativeReward = 0
        bestActionCumulativeReward = 0

        self.actionRegret = []
        self.t = 0

        self.countCol = 0
        self.countRow = 0
        self.colDone = 0
        self.count = 0
        self.best = 0
        
        self.expl = [0 for i in range(0,self.numActions)]
        #select random d-columns
        
        #self.bestColumns = [0 for i in range(0,self.rank)]
        
        
        self.equiValence = []
        sum1 = 0
        for i in range(0,int(self.users/self.explore)+1):
            
            self.equiValence.append(sum1)
            sum1 = sum1 + int(self.users/self.explore)
        
        
        print "Equivalence class: " + str(self.equiValence)
        
        
        self.countCol = 0
        
        
        #print self.estR
        #self.write_file(self.t)
        
        
        
        #initialize phase
        self.m = 0
        self.nm = int(1.0)
        self.Nm = self.explore*self.nm*self.remArms()
        print self.Nm
        self.action = 0
        self.countRow = 0
        
        while True:

            #User gives row
            user = self.User_Nature()
            
            if self.remArms() > self.rank:
                #Explore
                if self.t <= self.Nm:
                #Explore the column if not explored
                    #if self.remExplore() > 0:
                        
                        #print self.expl, self.countRow
                    if self.countRow < self.explore:
                            
                        self.countRow = self.countRow + 1
        
                    else:
        
                        
                        self.expl[self.action] = -1 
                        self.action = self.choose_Col_RR(user)
                        self.countRow = 1
                        
                    
                else:
                    #self.write_file(self.t,self.estR,'_R_')
                    print "\n\nPhase: " + str(self.m) + " explored " + str(self.remArms()) + " columns " + str(self.explore) + " times"
                    self.colElim()    
                    self.expl = [0 for i in range(0,self.numActions)]
                    for i in range(0,self.numActions):
                        if self.B[i] == -1:
                            self.expl[i] = -1
                    self.Nm = self.t + self.explore*self.nm*self.remArms()
                    self.m = self.m + 1
            else:
                
                #Explore best d columns fully
                self.bestCol = []
                
                for col in range(0,self.numActions):
                    
                    if self.B[col] != -1:
                        
                        self.bestCol.append(col)
                
                
                if self.remExplore() > 0:
                    
                    for col in range(0,self.numActions):
                        if self.expl[col] != -1 and self.estR[user][col]== self.MIN:
                            self.action = col
                    
                else:
                    #print "Fully explored " + str(self.remArms()) + " best columns " + str(self.bestCol)
                    #Exploit
                    self.action = max(range(0,self.numActions), key=lambda col: self.estR[user][col])
                    
            
            #Calculate Regret
            theReward = self.rewards(user, self.action)
            self.arm_reward[user][self.action] = self.arm_reward[user][self.action] + theReward
            self.numPlays[user][self.action] += 1
            self.payoffSums[user][self.action] += theReward

            self.estR[user][self.action] = theReward

            cumulativeReward += theReward
            bestActionCumulativeReward += theReward if self.action == self.bestAction[user] else self.rewards(user,self.bestAction[user])
            #print self.bestAction[user],self.action
            regret = bestActionCumulativeReward - cumulativeReward

            self.actionRegret.append(regret)
            self.t = self.t + 1

            #print t

            if self.t % 100 == 0:
                print "At time: " + str(self.t), ", action: " +str(self.action), ", regret:", str(regret)

            if self.t >= self.numRounds:
                break

        #write regret to file
        f = open('NewExpt/expt5/testRegretGLBUCB0RR1.txt', 'a')
        for r in range(len(self.actionRegret)):
            f.write(str(self.actionRegret[r]) + "\n")
        f.close()

        return cumulativeReward, bestActionCumulativeReward, regret, self.action, self.t
Example #55
0
 def setDirection(self, direction):
     f = open(self.path + 'direction', 'w')
     f.write(str(direction))
     f.close()
Example #56
0
 def write_file(self,t,mat,name):
     
     f = open('Test/test' + str(name) + 'GLB.txt_'+str(t), 'w')
     for r in range(len(mat)):
         f.writelines("%s\n" % (', '.join(["%.3f" % i for i in mat[r]])))
     f.close()
Example #57
0
    def _clean_doc(self, doc, namespace, timestamp):
        """Reformats the given document before insertion into Solr.

        This method reformats the document in the following ways:
          - removes extraneous fields that aren't defined in schema.xml
          - unwinds arrays in order to find and later flatten sub-documents
          - flattens the document so that there are no sub-documents, and every
            value is associated with its dot-separated path of keys
          - inserts namespace and timestamp metadata into the document in order
            to handle rollbacks

        An example:
          {"a": 2,
           "b": {
             "c": {
               "d": 5
             }
           },
           "e": [6, 7, 8]
          }

        becomes:
          {"a": 2, "b.c.d": 5, "e.0": 6, "e.1": 7, "e.2": 8}

        """

        # Translate the _id field to whatever unique key we're using.
        # _id may not exist in the doc, if we retrieved it from Solr
        # as part of update.
        if '_id' in doc:
            doc[self.unique_key] = u(doc.pop("_id"))

        # Update namespace and timestamp metadata
        if 'ns' in doc or '_ts' in doc:
            raise errors.OperationFailed(
                'Need to set "ns" and "_ts" fields, but these fields already '
                'exist in the document %r!' % doc)
        doc['ns'] = namespace
        doc['_ts'] = timestamp

        #doc 提前进行扁平化
        doc = self._formatter.format_document(doc)
        #对doc中tag*变量长度进行限制
        for k, v in doc.items():
            if (k[0:3] == "tag" and v and isinstance(v, basestring)):
                doc[k] = v[0:9000]

        # 获取mongo表名称
        collecion_name = self._get_collection_name(namespace)
        # 处理用户行为表数据
        if ("b_dynamic" == collecion_name):

            logging.info("to process doc from b_dynamic ,the doc is %s" %
                         str(doc[self.unique_key]))
            return self._parse_user_dynamic_collection(doc)

        #处理用户表
        if ("T_USER" == collecion_name):
            logging.info("to process doc from T_USER ,the doc is %s" %
                         str(doc[self.unique_key]))
            return self._parse_t_user_collection(doc)

        #to process the content data
        logging.info("begin to process b_content ,the doc is %s" %
                     str(doc[self.unique_key]))
        doctemp = self._parse_content_doc(doc)

        if doctemp is None:
            logging.info("don't send doc to solr ,the doc is %s" % str(doc))
            return None

        if (isinstance(doctemp, list) and len(doctemp) == 0):
            logging.info("don't send doc to solr ,the doc is %s" % str(doc))
            return None

        if (isinstance(doctemp, list) and len(doctemp) > 1):
            logging.info(
                "to process doc from b_content after it is a list,the doc is %s"
                % str(doc[self.unique_key]))
            flat_doc = []
            for docvalue in doctemp:
                flat_doc.append(self._parse_doc_to_solr_doc(docvalue))

            return flat_doc

        if (isinstance(doctemp, list)):
            logging.info(
                "to process doc from b_content after it is a one-value list,the doc is %s"
                % str(doc[self.unique_key]))
            return self._parse_doc_to_solr_doc(doctemp[0])
        logging.info(
            "to process doc from b_content after it is a object,the doc is %s"
            % str(doc[self.unique_key]))
        return self._parse_doc_to_solr_doc(doctemp)
Example #58
0
 def str(object, unused=None):
     return __builtin__.str(object)
Example #59
0

if __name__ == "__main__":
    rcmd, ipath, opath, data_elm, max_procs, time_out = getpath(sys.argv[1:])

    tempcmd = "./" + rcmd

    timestr = time.strftime("%Y%m%d-%H%M%S")

    log_path1 = opath + "/Test_array_lock_log_" + timestr

    os.mkdir(log_path1)

    result_list_weak = []
    for j in range(1, ((int(max_procs)) + 1)):
        iterative_logpath1 = log_path1 + "/Data_" + str(
            int(data_elm)) + "_Proc_" + str(j)
        os.mkdir(iterative_logpath1)
        for k in range(1, 101):
            r1cmd = tempcmd + " " + str(
                int(data_elm)) + " " + str(100) + " " + str(j)
            temp_tname = "Data_" + str(int(data_elm)) + "_Proc_" + str(j)
            log_file = iterative_logpath1 + "/Iteration_" + str(k) + ".txt"
            runprocess = run(temp_tname, r1cmd, ipath, log_file)
            runwasok = runprocess.runprocess(int(time_out))

        if runwasok == True:
            avg_time_list = []
            for k in range(1, 101):
                read_log = iterative_logpath1 + "/Iteration_" + str(k) + ".txt"
                fp = open(read_log)
                lines = fp.readlines()
Example #60
0
 def _add_list_with_not_empty_string(self, v_list, value):
     if value:
         v_list.append(str(value))