示例#1
0
def today():
    open(CSV_FILE, "w").write(requests.get(FED_USD_URL).text)
    log.info('Downloaded USD data to {}'.format(CSV_FILE))

    multiplier = 1.0
    date = None
    supply = None
    supply_m2 = None
    supply_base = None
    with open(CSV_FILE) as f:
        reader = csv.reader(f)
        for i, row in enumerate(reader):
            if not row:
                continue

            if i == 4:
                multiplier = float(row[1])

            if i > 10:
                date = datetime.strptime(row[0], "%Y-%m")
                supply = float(row[1]) * multiplier
                supply_m2 = float(row[2]) * multiplier
                supply_base = float(row[3]) * multiplier
                #log.info("{} M1:{} M2:{} Base:{}".format(date, supply, supply_m2, supply_base))

    if date > db.Db('_usd_').get_series('supply')[-1][0]:
        res = db.Db('_usd_').write_data({'day': date, 'supply': supply})
        log.info('M1 [{}] {} {}'.format(res, date, supply))
        res = db.Db('_usd_m2_').write_data({'day': date, 'supply': supply_m2})
        log.info('M2 [{}] {} {}'.format(res, date, supply_m2))
    else:
        log.info("No new USD supply data at this time.")
示例#2
0
文件: gui.py 项目: flowluap/open-pay
    def __init__(self, master,id):
        self.id = id
        self.betrag=""
        self.users = db.Db().command("Select * From users Order by name;")
        master.attributes('-fullscreen', True)
        self.master = master

        if db.Db().command("Select * From users Where tagid='{}';".format(id)) == []:
            #Tag not assigned
            tk.Label(self.master, text="Karte nicht in DB registriert. Karte mit Nutzer verknüpfen?").pack(anchor='center',pady=5)

            self.scrollbar = Scrollbar(self.master)
            self.scrollbar.pack( side = RIGHT, fill = Y )

            self.userlist = Listbox(self.master, yscrollcommand = self.scrollbar.set, width=60, height=13)
            self.userlist.insert(END, "TagID, Vorname, Nachname, Kontostand")
            for ID, tagid, name, nachname, kontostand, changes in self.users:
               self.userlist.insert(END, "{} {} {} {}".format(tagid, name, nachname, kontostand))

            self.userlist.pack()
            self.scrollbar.config( command = self.userlist.yview )

            tk.Button(self.master, text = 'Schließen', width = 10, command = self.master.destroy).pack(side = LEFT)
            tk.Button(self.master, text = 'Weiter', width = 10, command = self.select).pack(side = LEFT)

        else:
            self.userinfo = tk.Label(self.master, text = "Bitte Ausweis überprüfen: \n "+str(db.Db().command("Select * From users Where tagid='{}';".format(id))[0][2:6]).replace("'","").replace(",",""))
            self.userinfo.pack(anchor='center',pady=5)
            tk.Button(self.master, text = 'Einzahlen', width = 35, height=5, command=self.ein).pack(anchor='center',pady=5)
            tk.Button(self.master, text = 'Auszahlen', width = 35, height=5, command=self.aus).pack(anchor='center',pady=5)
            tk.Button(self.master, text = 'Schließen', width = 8, command = self.master.destroy).pack(anchor='center',pady=5)
示例#3
0
def historical():
    data = [
        ("2000-01-01", 4000000000000.0, 1.00),
        ("2009-01-01", 8000000000000.0, 1.30),
        ("2017-01-01", 10750000000000.0, 1.06),
        ("2019-12-01", 12380000000000.0, 1.10),
        ("2020-09-01", 13460000000000.0, 1.18),
    ]
    for day, supply, usd in data:
        res = db.Db('_eur_m2_').write_data({
            'day': day,
            'supply': supply,
            'usd': usd
        })
        log.info('M2 [{}] {} {} {}'.format(res, day, supply, usd))

    data = [
        ("2000-01-01", 4723291000000.0, 1.00),
        ("2009-01-01", 9400007000000.0, 1.30),
        ("2017-01-01", 11431525000000.0, 1.06),
        ("2019-12-01", 13000000000000.0, 1.10),
    ]
    for day, supply, usd in data:
        res = db.Db('_eur_m3_').write_data({
            'day': day,
            'supply': supply,
            'usd': usd
        })
        log.info('M3 [{}] {} {} {}'.format(res, day, supply, usd))
示例#4
0
文件: gui.py 项目: flowluap/open-pay
    def go(self):
        user = db.Db().command("Select * From users Where tagid='{}';".format(self.id))[0]
        db.Db().new_betrag(self.id,float(self.betrag))
        db.Db().insert_entry("{} {} hat {} Taler übertragen bekommen ".format(user[2],user[3],self.betrag))

        MsgBox = tk.messagebox.showinfo('Zahlung hinterlegt','Betrag wurde verrechnet!',parent=self.master)
        if MsgBox == 'ok':
            self.app.destroy()
            self.master.destroy()
示例#5
0
 def __init__(self):
     self.config = ConfigParser.ConfigParser()
     self.logger = logMaster.Logger("CouchWatcher", "/Services/CouchWatcher/config/config.cfg")
     self.error_msgger = errorMessageTemplate.Message()
     self.db = db.Db()
     self.config.read("/Services/CouchWatcher/config/config.cfg")
     self.timeout = int(self.config.get("env", "timeout"))
示例#6
0
文件: gui.py 项目: flowluap/open-pay
    def select(self):
        if len(self.userlist.curselection()) == 0 or 0 in self.userlist.curselection():
            messagebox.showwarning("Auswahl", "Leider keine oder ungültige Auswahl!")

        userid_selection = self.users[self.userlist.curselection()[0]-1][0]
        db.Db().add_tag(self.id,userid_selection)
        self.master.destroy()
示例#7
0
    def __init__(self):

        QtCore.QObject.__init__(self)
        self.config = config.Config()
        self.login = False
        self.loginTime = None

        print('_______strp1_________')
        self.processEvents()
        self.queryCore = queryCore.Core(self)
        self.processEvents()
        print('_______strp2_________')
        self.db = db.Db()
        storage = readStorage.Storage()
        self.storageData = storage.readCommentSetting()
        self.config.updateSequenceDateFromStorage(self.storageData)
        self.config.set('stations', station.getStations())
        self.onBooking = False
        print('_______strp3_________')

        app = QtGui.QApplication(sys.argv)

        print('_______strp4_________')
        #login
        autoLogin = False
        try:
            self.processEvents()
            print('_______strp5_________')
            if self.getLoginData()['username'] == self.getPersonalDetail(
            )['username']:
                self.processEvents()
                autoLogin = True
        except Exception:
            pass
        print('_______strp6_________')

        if not autoLogin:
            print('_______strp7_________')
            self.processEvents()
            lg = login.Login(self)
            self.processEvents()
        print('_______strp8_________')
        if autoLogin or lg.exec_():
            if not autoLogin:
                self.processEvents()
                if not lg.getLogin():
                    return
            print('_______strp9_________')
            self.processEvents()
            self.getPersonalContacts()
            self.processEvents()
            print('_______strp10_________')
            main = mainWindow.MainWindow(self)
            main.setWindowIcon(QtGui.QIcon("images/favorite.ico"))
            main.show()

            self.keepAlive = KeepAlive(self, self.config.get('keepAliveTime'))
            self.keepAlive.setDaemon(True)
            self.keepAlive.start()
        sys.exit(app.exec_())
示例#8
0
def init_db(args):
    if args.dburl:
        if args.nn:
            dbase = db.Db(loop, args.dburl, 'n' + str(args.nn))
        else:
            dbase = db.Db(loop, args.dburl)
    else:
        if args.nn:
            dbase = db.Db(loop, "sqlite:///data/morphis-{}.sqlite"\
                .format(args.nn))
        else:
            dbase = db.Db(loop, "sqlite:///data/morphis.sqlite")

    dbase.init_engine()

    return dbase
示例#9
0
 def __init__(self):
     """ Gerekli kaynaklarin hesaplanmasi icin kullanilmaktadir. """
     self.config = ConfigParser.ConfigParser()
     self.config.read("/Services/RabbitMqWatcher/config/config.cfg")
     self.logger = logMaster.Logger("RabbitMqWatcher", "/Services/RabbitMqWatcher/config/config.cfg")
     self.db = db.Db()
     self.timeout = int(self.config.get("env", "timeout"))
 def __init__(self):
     config = ConfigParser.ConfigParser()
     config.read('/Services/RestServices/class/config/config.cfg')
     self.restuser = config.get('auth', 'username')
     self.restpass = config.get('auth', 'password')
     self.db = db.Db()
     self.logger = logMaster.Logger()
示例#11
0
def maintenanceAccurals():
    result = []
    mydb = db.Db()
    mydb.transaction()
    try:
        mydb.execute(SQL_accural_doubles_drop_tmp)
        result.append({'action': 'drop temp table'})
    except (Exception):
        pass
    try:
        mydb.execute(SQL_accural_doubles)
        result.append({'action': 'create temp table with doubles'})
        mydb.execute(SQL_accural_doubles_erase)
        result.append({'action': 'delete accruel doubles'})
        mydb.execute(SQL_accural_doubles_drop_tmp)
        result.append({'action': 'drop temp table'})
        mydb.execute(SQL_add_lost_coupons)
    except (Exception):
        pass
    result.append({'action': 'add lost coupons'})
    lands = mydb.fetch(SQL_lands)
    balances = {'action': 'fix balances', 'lands': []}
    for land in lands:
        balances['lands'].append(update_accrual_balance(mydb, land))
    result.append(balances)
    mydb.commit()
    return (result)
示例#12
0
def compare_cluster_epochs_nationality(
        clusters=[0],
        countries=['Germany', 'France', 'Britain'],
        epochs=[1789, 1848, 1875, 1914]):
    my_db = db.Db()
    #combined = pd.merge(my_db.metadata_long_19, my_db.clusters_long_19)
    combined = my_db.final_cluster_nation
    epochs_window = [epochs[i:i + 2] for i in xrange(len(epochs) - 1)]

    results = []
    for nationality in countries:
        tmp = [nationality]
        for (beginning, end) in epochs_window:
            # This has to be renormalized later!
            art_per_nation_and_epoch = combined.query(
                'metadata_country == "{0}" & mid_year >= {1} & mid_year < {2}'.
                format(nationality, beginning, end))
            #count = art_per_nation_and_epoch.groupby('cluster_id').count()
            #print count['metadata_surname']
            art_per_nation_epoch_and_cluster = art_per_nation_and_epoch[
                art_per_nation_and_epoch['cluster_id'].isin(clusters)].groupby(
                    'picture_id').count()

            #!!!!important step!!!!
            tmp.append(
                len(art_per_nation_epoch_and_cluster) /
                float(len(art_per_nation_and_epoch)))
        results.append(tmp)
    return results
示例#13
0
    def test_get_documents_by_docid(self):
        repo = db.Db()

        docids = [1, 2, 3, 4]
        results = repo.get_documentnames_by_docid(docids)

        self.assertTrue(len(results) == 4)
示例#14
0
def get_social_interactions(id_ensemble): 
    # Generate how many times each student communicated with another student for a given group. 
    import db
    names = {
        "cnt":None,     
        "id": None
        }
    #for one-way a1 initiates and a2 replies. 
    from_clause = """
     (select count(id) as cnt, a2||'_'||a1 as id  from (select c1.id, c1.author_id as a1, c2.author_id as a2 from base_v_comment c1, base_v_comment c2 where c2.parent_id=c1.id and c1.ensemble_id=?) as v1 group by a1, a2) as v2"""
    output = {}
    output["oneway"] = db.Db().getIndexedObjects(names, "id", from_clause, "true" , (id_ensemble,))
    #for two-way, a1 initiates, a2 replies, and a1 re-replies. 
    from_clause = """
     (select count(id) as cnt, a2||'_'||a1 as id  from (select c1.id, c1.author_id as a1, c2.author_id as a2 from base_v_comment c1, base_v_comment c2, base_v_comment c3 where c3.parent_id=c2.id and c3.author_id=c1.author_id and c2.parent_id=c1.id and c1.ensemble_id=?) as v1 group by a1, a2) as v2"""
    output["twoway"] = db.Db().getIndexedObjects(names, "id", from_clause, "true" , (id_ensemble,))
    return output
示例#15
0
    def __init__(self, con, addr, savedir):
        threading.Thread.__init__(self)
        self.con = con
        self.addr = addr
        self._savedir = savedir

        # Set up db connection
        self._db = db.Db()
示例#16
0
 def __init__(self):
     self.config = ConfigParser.ConfigParser()
     self.config.read("/Services/ElasticsearchWatcher/config/config.cfg")
     self.logger = logMaster.Logger()
     #self.mailler = sendMail.Mail()
     self.sender = "ElasticSearch System"
     self.to = self.config.get("contact", "tech")
     self.service = "Source Calculator"
     self.db = db.Db()
示例#17
0
 def __init__(self, pathname = PathManager.source_dir):
     PathManager.__init__(self, pathname)
     self.db = db.Db()
     self.file = files.File(pathname[self.source_dir_len:])
     self.file.lastSynced = self.db_get_last_synced()
     self.file.md5 = self._generate_md5()
     self.file_info = {'filename':self.file.filename, 'md5':self.file.md5, 
                       'last_modified':self.file.lastModified, 'size':self.file.fileSize, 
                       'last_accessed':self.file.lastAccessed, 'last_synced':self.file.lastSynced}
	def __init__(self):
		""" Gerekli kaynaklarin hesaplanmasi icin kullanilmaktadir. """
		self.config = ConfigParser.ConfigParser()
		self.config.read("/Services/RabbitMqWatcher/config/config.cfg")
		self.logger = logMaster.Logger()
		#self.mailler = sendMail.Mail()
		self.sender = "RabbitMqWatcher System"
		self.to = self.config.get("contact","tech")
		self.db = db.Db()
示例#19
0
    def test_project_db(self):

        try:
            with proj.Db(self.uri, self.userName, self.password) as db_inst:
                db_inst._run_cmd('MATCH (n) RETURN n')
        except neo4j.exceptions.ServiceUnavailable:
            #normally except ConnectionRefusedError: is raised but is jumpred now i catch this for some reason
            assert False, self.get_exc_msg("DATABASE NOT ACTIVE")
        except neo4j.exceptions.AuthError:
            assert False, self.get_exc_msg("WRONG CREDENTIALS")
        except Exception:
            assert False, self.get_exc_msg()
        #finally: #is always called exc raised or not, its why i add a flag
        #    if self.exc_raised:
        #        self.fail('db test failed')

        self.db_inst = proj.Db(self.uri, self.userName, self.password)
        self.uni_print(self.db_inst)
示例#20
0
    def test_1_db_connection(self):
        test_nickname = 'test_db_connection'  #no way to get name of fun in fun

        self.db_inst = db.Db(self.uri, self.userName, self.password)

        if len(self.db_inst.err_msgs) > 0:  #failed
            self.error_msgs[test_nickname] = self.db_inst.err_msgs
            return False
        return True
示例#21
0
文件: node.py 项目: sahabi/morphis
    def __init__(self, loop, instance_id=None, dburl=None):
        self.chord_engine = None
        self.loop = loop

        self.instance = instance_id
        if instance_id:
            self.instance_postfix = "-{}".format(instance_id)
        else:
            self.instance_postfix = ""

        self.node_key = None

        self.data_block_path = "data/store-{}"
        self.data_block_file_path =\
            self.data_block_path + "/{}.blk"

        self.datastore_max_size = 0  # In bytes.
        self.datastore_size = 0  # In bytes.

        if dburl:
            self.db = db.Db(loop, dburl, 'n' + str(instance_id))
        else:
            self.db = db.Db(\
                loop,\
                "sqlite:///data/morphis{}.sqlite".format(self.instance_postfix))
        self._db_initialized = False

        self.bind_address = None
        self.unsecured_transport = None

        self.shell_enabled = True
        self.eval_enabled = False

        self.web_devel = False

        self.seed_node_enabled = True

        self.morphis_version = None

        self.ready = asyncio.Event(loop=loop)

        self.tormode = False
        self.offline_mode = False
示例#22
0
def get_total_times(sid):
	attr = {
		"page": None,
		"total_time": None
	}
	from_clause = """
	(SELECT page, sum(tcorrected) as total_time from tpage2
	WHERE source_id = ?
	GROUP BY page) as v1
	"""
	return db.Db().getIndexedObjects(attr, "page", from_clause, "true", [sid])
示例#23
0
def historical():
    data = [
        ("2000-01-01",  12122040000000.0, 0.10),
        ("2009-01-01",  50000000000000.0, 0.15),
        ("2017-01-01", 157600000000000.0, 0.15),
        ("2019-12-01", 198650000000000.0, 0.14),
        ("2020-10-01", 214970000000000.0, 0.15),
    ]
    for day, supply, usd in data:
        res = db.Db('_cny_m2_').write_data({'day': day, 'supply': supply, 'usd': usd})    
        log.info('M2 [{}] {} {} {}'.format(res, day, supply, usd))
示例#24
0
    def setup_flask(self, uri, userName, password):
        with db.Db(uri, userName, password) as db_inst:

            if len(db_inst.err_msgs) > 0:
                print(*db_inst.err_msgs, sep='\n')
                return
            
            self.db_inst = db_inst
            self.endpoints_obj = endpoints.Endpoints(db_inst)

            self.app_obj = Flask(__name__)
            self.add_url_rules(self.app_obj, self.endpoints_obj)
示例#25
0
 def test_xmpp_users(self):
     tmp_db=USERS_TEST_DB+'.bak'
     copyfile(USERS_TEST_DB, tmp_db)
     database = db.Db(tmp_db)
     users=database.get_users()
     xmpp=gxmpp.Component('megagate.home.myhome', '123456', 'localhost', 5347)
     xmpp.register_plugin('xep_0030')  # Service Discovery
     xmpp.register_plugin('xep_0004')  # Data Forms
     xmpp.register_plugin('xep_0060')  # PubSub
     xmpp.register_plugin('xep_0199')  # XMPP Ping
     xmpp.add_users(users)
     self.assertEqual(users, xmpp.users)
示例#26
0
def historical():
    data = [
        ("2000-01-01",  600000000000000.0, 0.0095),
        ("2009-01-01",  748827000000000.0, 0.0110),
        ("2010-11-01",  779000000000000.0, 0.0120),
        ("2017-01-01",  962000000000000.0, 0.0087),
        ("2019-12-01", 1040000000000000.0, 0.0092),
        ("2020-10-01", 1120000000000000.0, 0.0095),
    ]
    for day, supply, usd in data:
        res = db.Db('_jpy_m2_').write_data({'day': day, 'supply': supply, 'usd': usd})    
        log.info('M2 [{}] {} {} {}'.format(res, day, supply, usd))
示例#27
0
def get_num_annotations_stats(sid):
	attr = {
		"page_num": "page",
		"num_annotations": None
	}
	from_clause = """
	(SELECT page, count(*) as num_annotations 
	FROM base_v_comment 
	WHERE source_id= ?
	AND type = 3 
	GROUP BY page) as v1
	"""
	return db.Db().getIndexedObjects(attr, "page_num", from_clause, "true", [sid])
示例#28
0
def get_num_participants_stats(sid):
	attr = {
		"page_num": "page",
		"num_participants": None
	}
	from_clause = """
	(SELECT page, count(distinct(author_id)) as num_participants 
	FROM base_v_comment
	WHERE source_id = ?
	AND type = 3
	GROUP BY page) as v1
	"""
	return db.Db().getIndexedObjects(attr, "page_num", from_clause, "true", [sid])
示例#29
0
def get_avgtime_peruser(sid):
	attr = {
		"page": None,
		"avgtime_per_user": "******"
	}
	from_clause = """
	(SELECT page, avg(timeperuser) as avg_time from
		(SELECT page, sum(tcorrected) as timeperuser from tpage2
		WHERE source_id = ?
		GROUP BY page, user_id) as v1
	GROUP BY page) as v2
	"""
	return db.Db().getIndexedObjects(attr, "page", from_clause, "true", [sid])
示例#30
0
 def setup_db(self):
     """Setup DB connections, get initial data from DB."""
     # setup db connections
     self.db = db.Db()
     self.db.setup()
     # update persons list
     self.db.set_persons()
     # get latest persons list
     self.persons = self.db.get_persons()
     # if nextPostId does not exist in db, set it
     key = 'nextPostId'
     if not self.db.exists(key):
         self.db.set(key, 0)