def get_prices_from_google(item_name):
    # Search for
    MAGIC_WORD = "price"

    # Connect to Google
    browser = mechanicalsoup.StatefulBrowser()
    browser.open("https://www.google.com/")

    # Fill-in the form
    browser.select_form('form[action="/search"]')
    browser["q"] = item_name + " " + MAGIC_WORD

    WEB_AGENT_NAME = "btnG"
    resp = browser.submit_selected(btnName=WEB_AGENT_NAME)

    item = resp.soup.find_all("div")

    print("Searcing for:", item_name)
    price_list = []

    # sleep in order to prevent Google bot detection
    time.sleep(1)

    for it in item:
        res = find_price_of_item(it.text)
        print(it.text)
        if res:
            price_list.append(res)
    print(price_list)
    if price_list:
        price = structure(mean(price_list), max(price_list), min(price_list))
        return price
    else:
        return status.FAILURE
예제 #2
0
 def report_opt_results(self):
     mf = structure(self.hf_model, self.n, self.mf_opt.x, self.EI_req)
     self.results['mf score'] = mf.score
     self.results['mf mass'] = mf.mass
     self.results['mf EI'] = mf.EI
     self.results['mf equiv score'] = mf.equiv_score
     self.results['mf equiv EI'] = mf.equiv_EI
     hf = structure(self.hf_model, self.n, self.hf_opt.x_opt, self.EI_req)
     self.results['hf score'] = hf.score
     self.results['hf mass'] = hf.mass
     self.results['hf EI'] = hf.EI
     self.results['hf equiv score'] = hf.equiv_score
     self.results['hf equiv EI'] = hf.equiv_EI
     lf = structure(self.hf_model, self.n, self.lf_opt.x_opt, self.EI_req)
     self.results['lf score'] = lf.score
     self.results['lf mass'] = lf.mass
     self.results['lf EI'] = lf.EI
     self.results['lf equiv score'] = lf.equiv_score
     self.results['lf equiv EI'] = lf.equiv_EI
예제 #3
0
파일: clplot.py 프로젝트: JohnFNovak/clplot
def init(data=[], files=globe.dic['files'], replot=globe.dic['replots']):
    dic = globe.dic

    for i, filename in enumerate(files):
        if dic['Verbose'] > 0:
            print "loading", filename
        sys_err = dic['sys_err_default']
        if len(filename.split('#')) == 2:
            sys_err = float(filename.split('#')[1].strip())
            filename = filename.split('#')[0].strip()
        if dic['outputs']:
            output = dic['outputs'].pop()
        else:
            output = '.'.join(filename.split('.')[:-1])
        dic['numbered'] = 0

        # Now read data file
        blocks = make_blocks(read_data(filename))

        if blocks:
            for j, b in enumerate(blocks):
                if dic['GroupBy'] == 'files':
                    data.append([[i, j], filename, output, b, sys_err])
                elif dic['GroupBy'] == 'blocks':
                    data.append([[j, i], filename, output, b, sys_err])

    data.sort(key=lambda x: x[0])
    data = structure(data)

    for i, filename in enumerate(replot):
        if dic['Verbose'] > 0:
            print "reloading data from", filename
        if len(filename.split('#')) == 2:
            filename = filename.split('#')[0].strip()
        data = data + reload_plot(filename)

    return data
	def __init__(self, string_representation):
		self.structure = structure( string_representation )
예제 #5
0
from sklearn.model_selection import train_test_split
from structure import structure
from preprocess import create_dataset
from model import Model

if __name__ == "__main__":
    print("Downloading files")
    structure()
    print("Creating dataset")
    X, y = create_dataset()
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.05)

    model = Model()
    model.fit(
        X_train, y_train,
        X_test, y_test,
        early=4,
        epoches=50
    )
예제 #6
0
def main():
    recipe_file = "recipes/earth.json"

    params.get_params('params/params.ini', recipe_file)

    structure.structure(6371000.0)
예제 #7
0
from funcoesTermosol import importa, plota, geraSaida
from knot import knot
from element import element
from structure import structure
import numpy as np

[knot_numbers, knot_coordinates, element_numbers, incidence, load_numbers, forces, restriction_numbers, restriction] = importa('entry.xlsx')

knot_list = []
element_list = []

for i in range(knot_numbers):

    # melhor codigo do mundo
    knot_list.append(knot(knot_coordinates[0][i], knot_coordinates[1][i], [forces[2 * i], forces[2*i + 1]]))

for i in range(element_numbers):

    incidence0 = (int(incidence[i][0]) - 1)*2
    incidence1 = (int(incidence[i][1]) - 1)*2
    element_list.append(element(incidence[i][2], incidence[i][3], [knot_list[int(incidence[i][0]) - 1], knot_list[int(incidence[i][1]) - 1]], [[incidence0, incidence0 + 1], [incidence1, incidence1 + 1]]))

object_structure = structure(element_list, knot_numbers, restriction, element_numbers)

geraSaida(object_structure.reaction, object_structure.u_vector, object_structure.deformation, object_structure.internal_force, object_structure.tension)

예제 #8
0
파일: clplot.py 프로젝트: JohnFNovak/clplot
def interactive_plot(data=None, load=None):
    """Interactive Mode!"""
    dic = globe.dic

    command = True
    history = []

    if not load:
        files = dic['files']
        mode = choose_from('load all data to plots?',
                           ['n', 'y'],
                           default='y',
                           info=['the initial plots list will be empty and the user will create plots individually from loaded data',
                                 'all of the data loaded will be grouped into plots as they would be in the non-interactive mode'])
        if mode == 'n':
            mode = 's'
            plots = [[]]
        elif mode == 'y':
            mode = 'a'
            if not dic['MULTIP']:
                # multiplot flag not give, group plots by file, then block
                l = lambda x: '-'.join(map(str, x))
                groups = [[d for d in data if l(d[0][:2]) == f]
                          for f in set([l(x[0][:2]) for x in data])]
            else:
                groups = [data[(i * dic['MULTIP']):((i + 1) * dic['MULTIP'])]
                          for i in range((len(data) / dic['MULTIP']) + 1)]

            plots = groups
            # interact(**{'dic': dic, 'data': data, 'plots': plots})
    else:
        data, plots, history, mode = load

    if mode == 's':
        default = 'a'
    if mode == 'a':
        default = 'g'

    blocks = list(set([x[1] + '_' + str(x[0][1]) for x in data]))
    while command:
        print '#=====================#'
        print ['%d: %s cols by %d rows' % (i + 1, len(p), len(p[0][6]))
               for i, p in enumerate(plots) if p and p[0]]
        command = choose_from('?',
                              ['!', 'g', 'G', 'f', 'a', 'd', 's', 'q'],
                              default=default,
                              info=['drops user into an interactive python shell',
                                    'generates plots without writing them to file',
                                    'generates plots, writes them to file, then exits',
                                    'load new data from file',
                                    'add data to current plots, or add data to new plot',
                                    'delete data from plots, or delete entire plots',
                                    'enter plot point/line style',
                                    'exit'])
        history.append(command)
        if command == '!':
            interact(**{'dic': dic, 'data': data, 'plots': plots})
        elif command == 'g':
            if mode == 'a':
                for p in plots:
                    clplot(p)
            elif mode == 's':
                if len([p for p in plots if p]) > 1:
                    for p in plots:
                        c = choose_from('Plot %d: %s cols by %d rows ?' % (i + 1, len(p), len(p[0][6])),
                                        ['y', 'n'],
                                        default='y')
                        if c == 'y':
                            clplot(p)
                elif len([p for p in plots if p]) == 1:
                    clplot(plots[0])
        elif command == 'G':
            dic['interactive'] = False
            if mode == 'a':
                clplot(data)
            elif mode == 's':
                if len([p for p in plots if p]) > 1:
                    for p in plots:
                        c = choose_from('Plot %d: %s cols by %d rows ?' % (i + 1, len(p), len(p[0][6])),
                                        ['y', 'n'],
                                        default='y')
                        if c == 'y':
                            clplot(p)
                elif len([p for p in plots if p]) == 1:
                    clplot(plots[0])
            sys.exit(1)
        elif command == 'f':
            new_file = raw_input('file to load: ').strip()
            if os.path.isfile(new_file):
                files.append(new_file)
            data += structure(init(files=[new_file]))
            blocks = list(set([x[1] + '_' + str(x[0][1]) for x in data]))
        elif command == 'a':
            print 'adding data to plot'
            print 'select file:'
            for i, f in enumerate(files):
                n_b = len(set([' '.join(map(str, x[0][:2]))
                               for x in data if x[1] == f]))
                print '%d- file: %s [# blocks = %d]' % (i + 1, f, n_b)
            f_choice = int(choose_from("selection",
                                       map(str,
                                           range(1, 1 + len(files))),
                                       default='1')) - 1
            blocks = list(set([' '.join([x[1], 'block:', str(x[0][1] + 1)]) for
                               x in data if x[1] == files[int(f_choice)]]))
            blocks.sort(key=lambda x: x.split(' ')[-1])
            print '-------------'
            print 'file %s' % (files[int(f_choice)])
            print 'select block:'
            for i, b in enumerate(blocks):
                n_c = len(set([' '.join(map(str, x[0])) for x in data if
                               ' '.join([x[1], 'block:', str(x[0][1] + 1)]) == b]))
                n_r = len([x for x in data if ' '.join([x[1], 'block:', str(x[0][1] + 1)]) == b][0][6])
                print '%d- [# cols = %d, # rows = %d]' % (i + 1, n_c, n_r)
            choice = int(choose_from("selection",
                                     map(str,
                                         range(1, 1 + len(blocks))),
                                     default='1')) - 1
            cols = [d for d in data
                    if ' '.join([d[1], 'block:', str(d[0][1] + 1)]) ==
                    blocks[choice]]
            print '-------------'
            print 'file %s' % (files[int(f_choice)])
            print 'block %d- [# cols = %d, # rows = %d]' % (choice + 1, len(cols), len(cols[0][6]))
            print 'select columns:'
            for i, d in enumerate(cols):
                print '%d- col: %d [len %d title: %s]' % (i + 1, d[0][1] + 1, len(d[6]), d[4])
            choices = choose_multiple("selections",
                                      range(1, 1 + len(cols)),
                                      default='1')
            print '-------------'
            if choices == map(str, range(1, 1 + len(cols))):
                print 'adding all columns as plot'
                if not plots[-1]:
                    plots[-1] = cols
                else:
                    plots.append(cols)
                choices = []
            for choice in choices:
                print choice
                good = False
                if check_type(choice) == 'num':
                    size = len(cols[int(choice) - 1][6])
                    choice = int(choice) - 1
                if not plots[0]:
                    print 'No plots, starting new plot'
                    plots[0].append(cols[choice])
                    good = True
                elif len([p for p in plots if p and len(p[0]) > 6
                          and len(p[0][6]) == size]) > 1:
                    # print size, [len(p[0][6]) for p in plots]
                    print 'Multiple plots of an appropriate dimension have',
                    print 'been found'
                    opts = [p for p in plots if p[6] == size]
                    for i, o in enumerate(opts):
                        print i, ':', o
                    c = choose_from("select one ('n' for new)",
                                    map(str, range(1, 1 + len(opts))) + ['n'],
                                    default='1')
                    if check_type(c) == 'num':
                        plots[plots.index(opts[int(c) - 1])].append(cols[choice])
                    good = True
                elif len([p for p in plots if p and len(p[0]) > 6
                          and len(p[0][6]) == size]) == 1:
                    # print size, [len(p[0][6]) for p in plots]
                    print 'One plot has been found with the appropriate',
                    print 'dimension.'
                    new = choose_from('start new plot? (y/n)',
                                      ['y', 'n'],
                                      default='n')
                    if new == 'n':
                        plots[plots.index([p for p in plots if p
                                           and len(p[0]) > 6
                                           and len(p[0][6]) == size][0]
                                          )].append(cols[int(choice)])
                        good = True
                else:
                    print 'no plot of appropriate dimension has been found.'
                if not good:
                    print 'starting new plot'
                    plots.append([cols[int(choice)]])
            blocks = list(set([x[1] + '_' + str(x[0][1]) for x in data]))
        elif command == 'd':
            if len(plots) > 1:
                print 'select plots:'
                for i, p in enumerate(plots):
                    # print p
                    print '%d- %s cols by %d rows' % (i + 1, len(p), len(p[0][6]))
                choices = choose_multiple("selection",
                                          range(1, 1 + len(plots)),
                                          default='1')
            else:
                choices = ['0']
            done = choose_from("delete plots:[%s] ('n' to select columns)?" % ', '.join(choices),
                               ['y', 'n'],
                               default='n')
            choices = map(int, choices)
            if done == 'y':
                for c in choices:
                    del(plots[c])
            else:
                for c in choices:
                    print 'plot %s' % (c)
                    print 'columns:'
                    for i, d in enumerate(plots[choice]):
                        print '%d- file: %s block: %d col: %d [len %d title: %s]' % (i + 1, d[1], d[0][0] + 1, d[0][1] + 1, len(d[6]), d[4])
                    choice2 = int(choose_from("selection",
                                              map(str,
                                                  range(1, 1 + len(plots[choice]))),
                                              default='1')) - 1
                    s = choose_from('delete?', ['y', 'n'], default='n')
                    if s == 'y':
                        del(plots[choice][choice2])
        elif command == 's':
            dic['Ustyle'] = [raw_input('style: ')] + dic['Ustyle']
        elif command == 'q':
            if dic['SavePrompt']:
                save = choose_from('save?', ['y', 'n'], default='y')
                if save == 'y':
                    default = dic['DefaultSave']
                    fname = raw_input('filename? [%s]: ' % (default)) or default
                    pickle.dump((data, plots, history, mode), open(fname, 'w'))
            sys.exit(1)


def main():
    """A Python program that takes a file or list of filesand creates plots of
    the data."""
    dic = globe.dic
    read_flags()
    if dic['interactive']:
        if dic['LoadFromSavePrompt']:
            load = choose_from('load saved state?',
                               ['y', 'n'],
                               default='n',
                               info=['user can load options, data, and plots from previous session',
                                     'data will be loaded from scratch'])
            if load == 'y':
                default = dic['DefaultSave']
                fname = raw_input('filename? [%s]: ' % (default)) or default
                print 'loading from saved state, not loading files from',
                print 'command line arguments'
                interactive_plot(load=pickle.load(open(fname, 'r')))
                return
        data = init()
        interactive_plot(data=data)
    else:
        data = init()
        clplot(data)

if __name__ == '__main__':
    main()
예제 #9
0
 def f_lf(X):
     return(structure(self.lf_model, self.n, X[0], self.EI_req).score)
예제 #10
0
    def parseatom(self, line, hetatm=None):
        """
        #
        # Parse a single ATOM line
        #"""
        import typecheck, string, structure
        G = structure.structure()
        #
        # This routine parses every atom line and stores it in self.atomlinedefs
        #
        self.linenumber = self.linenumber + 1
        #
        # Check the atomnumber
        #
        atomnumber = line[6:11]
        if typecheck.isint(atomnumber):
            atomnumber = string.atoi(atomnumber)
        else:
            print '\nAtom number:', atomnumber
            raise ParseAtomError, 'Non-int in atonnumber'
        #
        # All we now about the atomname is that it must contain a nondigit character
        #
        atomname = string.strip(line[12:16])
        if not typecheck.containsletter(atomname):
            raise ParseAtomError, 'Atom name does not contain a character: %s,\nLINE: %s' % (
                atomname, line)
        #
        # Also the residuename must contain a letter
        #
        residuename = string.strip(line[17:21])
        if not typecheck.containsletter(residuename):
            print '\nResidue name:', residuename
            raise ParseAtomError, 'Residuename does not contain a character'
        # ---------------------/------------------------------------------
        #
        # The ChainID must be a letter, a blank or a digit
        #
        if self.NMRmodel is False or self.readmodels == 1 or self.ignore_NMRmodel:
            chainid = line[21]
        else:
            chainid = '%d_%s' % (self.NMRmodel, line[21])
        #
        # Check the chainID
        #
        if not typecheck.containsletter(
                chainid) and chainid != ' ' and not typecheck.isint(chainid):
            print '\nChainID', chainid
            raise ParseAtomError, 'Chain ID must be a letter,blank or digit'
        else:
            chainid = string.strip(chainid)
            #print 'Chainid: %s' %chainid
        newchainid = chainid
        #
        # Check that we are still building the same chain
        #
        if not self.chains.has_key(chainid):
            for cid in self.chains.keys():
                if self.chains[cid] == 'building' or (
                        self.oldchainid != newchainid
                        and self.chains[cid] == 'building - dummy'):
                    self.chains[cid] = 'terminated'
            self.chains[chainid] = 'building'
        else:
            if self.chains[chainid] != 'building':
                fail = 1
                if chainid == '':
                    #
                    # Find a new chainid
                    #
                    for cid in self.chains.keys():
                        if self.chains[cid] == 'building - dummy':
                            chainid = cid
                            fail = None
                            break
                    if chainid == '':
                        for cid in self.useids:
                            if not self.chains.has_key(cid):
                                self.chains[cid] = 'building - dummy'
                                chainid = cid
                                fail = None
                                break
                if fail:
                    for cid in self.chains.keys():
                        if self.chains[
                                cid] == 'building - dummy' and self.oldchainid == newchainid:
                            chainid = cid
                            fail = None
                            break
                    if fail:
                        for cid in self.useids:
                            if not self.chains.has_key(cid):
                                self.chains[cid] = 'building - dummy'
                                chainid = cid
                                fail = None
                                break
                    if fail:
                        print self.chains.keys()
                        raise ProtoolError, 'I ran out of alternative chain ID names'
        self.oldchainid = newchainid
        # -------------------------------------------------------------------------------------
        #
        # Check the residuenumber
        #
        residuenumber = line[22:27]
        done = False
        suffix = ''
        while not done:
            if typecheck.isint(residuenumber):
                residuenumber = string.zfill(string.atoi(residuenumber),
                                             G.length_of_residue_numbers)
                residuenumber = residuenumber + suffix
                done = True
            else:
                suffix = residuenumber[-1] + suffix
                residuenumber = residuenumber[:-1]
        #
        # Get and check the coordinates
        #
        if len(line) < 54:
            xcoord = None
            ycoord = None
            zcoord = None
        else:
            xcoord = line[30:38]
            ycoord = line[38:46]
            zcoord = line[46:54]
            if not typecheck.isnumber(xcoord) or not typecheck.isnumber(
                    ycoord) or not typecheck.isnumber(zcoord):
                print '\nX,Y,Z', xcoord, ycoord, zcoord
                raise ParseAtomError, 'All coordinates must be numbers'
            else:
                xcoord = string.atof(xcoord)
                ycoord = string.atof(ycoord)
                zcoord = string.atof(zcoord)
        #
        # Get the occupancy
        #
        if len(line) < 60:
            print '\nNo occupancy for this line'
            occupancy = None
        else:
            occupancy = line[55:60]
            if not typecheck.isnumber(occupancy):
                print '\nOccupancy:', occupancy
                raise ParseAtomError, 'Occupancy is not a number'
            else:
                occupancy = string.atof(occupancy)
        #
        # Get the B-factor
        #
        if len(line) < 66:
            print '\nNo B-factor for this atom', line
            bfactor = None
        else:
            bfactor = line[60:66]
            if not typecheck.isnumber(bfactor):
                print 'B-factor:', bfactor
                bfactor = None
            else:
                bfactor = string.atof(bfactor)
        #
        # Put the rest of the line in a junk array
        #
        if len(line) > 66:
            junk = line[66:]
        else:
            junk = None
        #
        # Finally put everything in self.atomlinedefs
        #
        self.atomlinedefs[self.linenumber] = {'NUMBER': atomnumber}
        self.atomlinedefs[self.linenumber]['ATNAME'] = atomname
        self.atomlinedefs[self.linenumber]['CHAINID'] = chainid
        self.atomlinedefs[self.linenumber]['RESNAME'] = residuename
        self.atomlinedefs[self.linenumber]['RESNUM'] = residuenumber
        if xcoord != None:
            self.atomlinedefs[self.linenumber]['X'] = xcoord
            self.atomlinedefs[self.linenumber]['Y'] = ycoord
            self.atomlinedefs[self.linenumber]['Z'] = zcoord
        if occupancy or occupancy == 0.0:
            self.atomlinedefs[self.linenumber]['OCCUPANCY'] = occupancy
        if bfactor or bfactor == 0.0:
            self.atomlinedefs[self.linenumber]['B-FACTOR'] = bfactor
        if hetatm:
            self.atomlinedefs[self.linenumber]['HETATM'] = 1
        if junk:
            #
            # This is a tag
            #
            import string
            self.atomlinedefs[self.linenumber]['tag'] = string.strip(junk)

        #
        # What is this atom bound to?
        #
        self.atomlinedefs[self.linenumber]['BOUND_TO'] = []
        return