Esempio n. 1
0
class Calculator:
    """
    Get the total benefit
    @param: INT adults - number of adults
    @param: INT children - number of children
    @param: FLOAT income
    @param: STRING city
    """

    DB = "asumislisa.db"

    def __init__(self, adults, chilren, income, city, discard_electricity):

        self.api = DbHandler(Calculator.DB)
        self.adults = adults
        self.children = chilren
        self.income = income
        self.city_group = self.get_city_group(city)
        self.discard_electricity

    def get_city_group(self, city):
        city = city.strip().upper()
        return self.api.find_city(city)

    def discard_electricity(self, rent):
        """
        The constant is estimated from the data of an existing
        KELA calculator. No official method for discarding the electricity
        was publicly available.
        """
        return rent - 22.2

    def get_excess(self):
        """
        Calculates the excess. Constants are determined by KELA

        """
        return max(
            0, 0.42 * (self.income -
                       (597 + 99 * self.adults + 221 * self.children)))

    def get_acceptable_expenses(self, rent):
        """
        Get the amount of expenses counted as acceptable
        TODO - count more parameters:
            heating included/not included
            water included/not included
        """
        acceptable = self.discard_electricity(
            rent) if self.discard_electricity else rent
        return acceptable

    def get_total_benefit(self, rent):

        household = self.adults + self.children
        max_benefit = self.api.get_benefit(household, self.city_group)
        acceptable_expenses = self.get_acceptable_expenses(rent)
        acceptable_expenses = min(max_benefit, acceptable_expenses)
        excess = self.get_excess()
        return max(0, 0.8 * (acceptable_expenses - excess))
class ProcessorWorker(Process):
    def __init__(self, task_queue, callback, count=None):
        super(ProcessorWorker, self).__init__()
        self.task_queue = task_queue
        self.callback = callback

        self.storage = DbHandler()
        self.callback = partial(callback, self.storage)
        self.count = count
        log.info("process worker %s inited with count: %s" % (self.name, self.count))

    def run(self):
        count = 1
        c_t = 0
        s_t = 0
        while True:
            to_process = self.task_queue.get()
            message = to_process.get("message")
            task = to_process.get("task")
            start = time()
            result = self.callback(message)
            cbc = time()
            self.storage.save_timeline_element(result, task, deferred_save=True)
            end = time()
            count += 1
            c_t += cbc - start
            s_t += end - cbc

            if count % (self.count / 10 if self.count else 10) == 0:
                log.info("was process and save %s tweets\n pa: %s, sa: %s" % (count, c_t / count, s_t / count))
            if self.count and count > self.count:
                log.info("will end my work, i was create %s iterations \n pa: %s, sa: %s" % (
                    count, c_t / count, s_t / count))
                break
Esempio n. 3
0
    def __init__(self, adults, chilren, income, city, discard_electricity):

        self.api = DbHandler(Calculator.DB)
        self.adults = adults
        self.children = chilren
        self.income = income
        self.city_group = self.get_city_group(city)
        self.discard_electricity
    def __init__(self, task_queue, callback, count=None):
        super(ProcessorWorker, self).__init__()
        self.task_queue = task_queue
        self.callback = callback

        self.storage = DbHandler()
        self.callback = partial(callback, self.storage)
        self.count = count
        log.info("process worker %s inited with count: %s" % (self.name, self.count))
Esempio n. 5
0
 def __init__(self):
     db_handler = DbHandler(db_config)
     handlers = generate_sitemap() + [
         ("/news", NewsHandler, {"db":db_handler}),
         ("/admin", AdminHandler, {"db":db_handler}),
         ("/login", LoginHandler, {"db":db_handler})
     ]        
     Application.__init__(self, handlers, default_handler_class=Handler404, **aplication_config)
     print('[+] Server started at http://{}:{}'.format(options.host, options.port))
Esempio n. 6
0
 def __init__(self, bot, config):
     super().__init__(bot, config)
     self.db = DbHandler().getDb()
     self.denyReasonQueryResponseManager = QueryResponseManager(
         deny_reason_callback)
     self.queueEditQueryResponseManager = QueryResponseManager(
         query_edit_callback)
     start_servers_healthcheck_loop(self)
     start_discordindex_refresh_loop(self)
     self.cached_queue_message = None
 def initialize(self, flag):
     self.db = DbHandler.get_db()
     self.flag = flag
def to_timestamp(dt):
    return (dt - datetime.datetime(1970, 1, 1)).total_seconds()


if __name__ == '__main__':
    cred = load_credentials()
    cred_data = cred.get_credentials()
    if not cred_data:
        print "not credentials data"
        sys.exit(-1)

    _, cred_info = cred_data

    api = TTR_API(cred_info)
    context = DbHandler()

    properties.url_statistic_time = 10

    for message in api.search_past("#битваэкстрасенсов", 10):

        result = processing.process_message_hash(context, message)
        result = processing.process_message_unshort_urls(context, result)
        result = processing.process_implying_entities(None, result)


    for stat in context.get_statistic(
            to_timestamp(datetime.datetime.now() - timedelta(days=1)),
            to_timestamp(datetime.datetime.now())):

        print stat
Esempio n. 9
0
from flask import Flask, render_template, redirect

from db import DbHandler
import os

app = Flask(__name__)
app.secret_key = os.urandom(24)

APP_ROOT = os.path.dirname(os.path.abspath(__file__))


@app.route('/', methods=['GET'])
def redirecttohome():
    return redirect("/home/", code=302)


@app.route('/home/', methods=['GET'])
def homepage():
    jsonstuff = d.get_stuff('poc_vienna_selection_fixed')
    return render_template('base.html', jsonstuff=jsonstuff)


if __name__ == '__main__':
    d = DbHandler()
    app.run(debug=True)
def prepare_fast_db_handler():
    db = DbHandler()
    collection_mapping = {TTR_APIMessage: db.messages,
                          TTR_APIUser: db.users}
    worker = db.get_saver_worker(collection_mapping)
    worker.start()
Esempio n. 11
0
from flask import Flask, escape, request,jsonify, json
from db import DbHandler,IndexedMeasure
from recorder import fetch_data

dbh=DbHandler()

app = Flask(__name__)
playback=[]
realtime=False
playback_it=0
@app.route('/be/playback',methods=['GET'])
def get_playback():
        global playback_it
        global playback
        if not realtime and len(playback)>0:
            if playback_it>=len(playback):
                    playback_it=0
            else:
                    playback_it+=1
            return  playback[playback_it]
        else:
            return dict()

@app.route('/be/playback/<p_id>',methods=['GET'])
def get_playback_id(p_id):
    return fetch_data(p_id)


@app.route('/be/patient/<p_id>',methods=['POST'])
def add_patient(p_id):
    #Add patient to database
Esempio n. 12
0
 def initialize(self):
     self.db = DbHandler.get_db()