Ejemplo n.º 1
0
def main():
    """Запрашивает комманду и вызывает функции из модуля functions"""
    querry = input(">>>: ")

    if querry == "index":
        os.system("clear")
        func.index(arrayName)
        main()
    elif querry == "count":
        os.system("clear")
        func.count(arrayName)
        main()
    elif querry == "pop":
        os.system("clear")
        func.pop(arrayName)
        main()
    elif querry == "clear":
        os.system("clear")
        func.clear(arrayName)
        main()
    elif querry == "list":
        os.system("clear")
        func.list(arrayName)
        main()
    elif querry == "tuple":
        os.system("clear")
        func.tup(arrayName)
        main()
    elif querry == "info":
        os.system("clear")
        func.info()
        main()
    elif querry == "create":
        os.system("clear")
        createArray()
    elif querry == "write":
        os.system("clear")
        func.writeFile(arrayName)
        main()
    elif querry == "read":
        os.system("clear")
        func.readFile()
        main()
    elif querry == "exit":
        os.system("clear")
        exit(0)
    else:
        print("Такой функции нет")
        main()
Ejemplo n.º 2
0
def removeNoAbstractFiles(
        fileList):  #the fileList contains all the files needs to be examined
    newFileList = []
    noAbstractFilesList = []

    for i in range(len(fileList)):
        content = readFile(fileList[i])
        #print(fileList[i])
        root = ET.fromstring(content)
        abstract = root.find(
            './/{http://purl.org/dc/elements/1.1/}description')

        #don't remove those files don't have descriptions
        if abstract is None:
            noAbstractFilesList.append(
                fileList[i])  #a list of xml files that don't have abstracts
            #os.remove(fileList[i])
        elif abstract.text is None:
            noAbstractFilesList.append(fileList[i])
        elif abstract.text == "Unknown":
            noAbstractFilesList.append(fileList[i])
        else:
            newFileList.append(fileList[i])

        #remove those files don't have descriptions


#        if abstract is None:
#            noAbstractFilesList.append(fileList[i])
#            os.remove(fileList[i])
#        newFileList.append(fileList[i])

    return newFileList
Ejemplo n.º 3
0
#!/usr/bin/env python
import functions
import config as config
import math


def massCalculate(moduleMass):
    moduleMass = float(moduleMass)
    fuelMass = math.trunc(moduleMass / 3) - 2
    if fuelMass > 0.0000000001:
        fuelMass += massCalculate(fuelMass)
        print(fuelMass)
    else:
        fuelMass = 0

    return fuelMass


massList = functions.readFile(config.dataPath + "day1Data", massCalculate)
#massTest = functions.readFile(config.dataPath + "day1-2Test", massCalculate)
massTotal = sum(massList)
print(massTotal)
#print(massTest)
# -*- coding: utf-8 -*-
from __future__ import print_function
import os
import sys
import importlib
from re import compile as _Re

_unicode_chr_splitter = _Re( '(?s)((?:[\ud800-\udbff][\udc00-\udfff])|.)').split

def split_unicode_char(text):
    return [ chr for chr in _unicode_chr_splitter(text) if chr ]


import functions as mod6

fin = mod6.readFile("menuList.txt")
# Noinclude = mod6.readFile("notincluein.txt")
# pinyin = pinyininLines1 = mod6.readFile("LineByLInePyShmYum.txt")
# similar = outPutForLoop2 = mod6.readFile("secondLoop.txt")
all = mod6.createSmallList(fin)
# firstForPinyin = mod6.createSmallList(pinyin)
# secondLoop = mod6.createSmallList(similar)

# wordInline = mod6.readFile("short.txt")
# forexample = mod6.readFile("long.txt")

# mod6.GettingWordsNone(forexample, wordInline)

pinyin_unified = mod6.chineseToPinyin(all)
shengm_unified = mod6.chineseToPinyinShengm(all)
yunm_unified = mod6.chineseToPinyinYunm(all)
Ejemplo n.º 5
0

def intCodeRun(opCodeList):
    for i in range(0, len(opCodeList), 4):

        if opCodeList[i] == 1:
            first_int = opCodeList[opCodeList[i + 1]]
            second_int = opCodeList[opCodeList[i + 2]]
            pos = opCodeList[i + 3]

            opCodeList[pos] = first_int + second_int

        elif opCodeList[i] == 2:
            first_int = opCodeList[opCodeList[i + 1]]
            second_int = opCodeList[opCodeList[i + 2]]
            pos = opCodeList[i + 3]

            opCodeList[pos] = first_int * second_int

        elif opCodeList[i] == 99:
            print("99 detected, exiting now.")
            break

    return opCodeList[0]


opCodeRawList = functions.readFile(config.dataPath + "day2-1Data", str)
opCodeList = intCodeProcess(opCodeRawList)
result = intCodeRun(opCodeList)
print(result)
Ejemplo n.º 6
0
        args = _p.parse_args()

	#preprocessing the input file:
	# saving every args.stride value of args.IN_file and saving to tmp.dat
	ss="'"
	ss+='0~'
	ss+=`args.S`
	ss+='p'
	ss+="'"

	cmd='sed -n '
	cmd+=ss
	cmd+=' '
	cmd+=args.fileName
	cmd+=' > tmp.dat'
	os.system(cmd)
	##########################################
	#get Number of rows and number of columns from the file and read from the file into a matrix 'vecT'
	nCol = file_cols('tmp.dat')
	vecT = readFile('tmp.dat',nCol)


	#print len(vecT[0])

	#calculate the max likelihood estimators
	results = estValB(vecT,args.K,args.N)
	#print results[0]
	#format the results to 6 decimal points before printing
	myList=formatRes(results,6)
	print ' '.join(str(p) for p in myList)
Ejemplo n.º 7
0
import functions

for i in range(0, 1000000):
    functions.readFile('input.txt')
Ejemplo n.º 8
0
def main():
        
    # change working directory to that with the data files
    oldFolder = os.getcwd()
    dataFilesFolder = oldFolder + '\dataFiles'
    os.chdir(dataFilesFolder)
    
    filters = [2710, 3060, 3220, 4270, 4740, 5756] # filters used in measurement
    controlData = []
    sampleData = []
    
    # read data files and save data to containers
    for filter in filters :
        FileName = 'saatomittaus-' + str( filter ) + '.txt'
        data = fn.readFile(FileName)
        data = np.mean(fn.cutData( data, 180 ))
        controlData.append(data)
        
        FileName = 'nayteputki-' + str( filter ) + '.txt'
        data = fn.readFile(FileName)
        data = np.mean(fn.cutData( data, 180 ))
        
        # sample data should never be a higher value than control data, because
        # the filters will absorb some of the incident light
        if controlData[-1] < data:
            sampleData.append(controlData[-1])
        else:        
            sampleData.append(data)
        
    os.chdir(oldFolder)
    
    # load the absorption vectors of the gases and filters from .mat files,
    # squeeze_me squeezes unit matrix dimensions 
    gases = sio.loadmat('gases.mat', squeeze_me=True)
    absorptions = sio.loadmat('filterAbsorbtion.mat', squeeze_me=True)
    wavelen = sio.loadmat('lambda.mat', squeeze_me=True)
    
    p=1.013e5       # Pa, pressure of gas
    k=1.38e-23      # J/K, Boltzmann constant
    T=298           # K, temperature of gas
    L=0.2           # m, length of sample tube
    
    # the wavelength vector at which the gas is scanned, and the changes in 
    # wavelength
    wavelen = wavelen['lambda']
    dwavelen = np.abs(np.diff(wavelen)) 
    dwavelen = np.append(dwavelen, dwavelen[-1])
    
    # set the absorption vectors of the gases and filters
    gasnames = ['H2O', 'CO', 'C2H2', 'CO2', 'CH4']
    gases = [gases[gasname] for gasname in gasnames]
    absorptions = [absorptions['NB'+str(filter)] for filter in filters]
    
    # the concentrations are solved by multivariable calculus
    # for this we define the matrix coefficients
    A = np.zeros([len(absorptions), len(gases)])
    for i in range(len(absorptions)):
        for j in range(len(gases)):
            alpha = np.sum( np.multiply( np.multiply(gases[j], absorptions[i]),
                                        dwavelen)*1e-2 )
            A[i,j] = alpha
    
    
    A = A*p/(k*T)/1e4*L
    
    I0 = controlData
    I = sampleData
    
    Y = np.zeros([len(absorptions),1])
    for i in range(len(absorptions)):
        y = ( 1-I[i]/I0[i] )*np.sum( np.multiply(absorptions[i], dwavelen*1e-2))
        Y[i,0] = y
        
    # solving the concentrations from the matrix equation    
    C = lin.solve(A.T.dot(A), A.T.dot(Y))
    C = np.squeeze(C)
    
    # print results
    print('Concentration of gases in sample tube:')
    for i in range(len(C)):
        c = C[i]*1e6
        print(gasnames[i], ': ', '%.2f' % c, ' ppm', sep='')
    
    # bar plot of results
    x = np.arange(5)
    plt.bar(x,C*1e6)
    plt.xticks(x, gasnames)
    plt.xlabel('Gas')
    plt.ylabel('Concentration (ppm)')