コード例 #1
0
ファイル: views.py プロジェクト: bertramr/wgapp
def perform_task(request):
    context = {
        'today': date.today().strftime('%Y-%m-%d'),
        'room_list': Room.objects.all(),
        'flatmate_list': Flatmate.objects.all()
    }
    try:
        flatmate_id = request.POST['flatmate']
    except (KeyError, Flatmate.DoesNotExist):
        return render(request, 'wgapp/task_perform.html', context)

    try:
        task_id = request.POST.getlist('task')

    except (KeyError, Task.DoesNotExist):
        return render(request, 'wgapp/task_perform.html', context)

    else:
        date_input = request.POST['date']
        flatmate = Flatmate.objects.get(pk=flatmate_id)

        for t in task_id:
            task = Task.objects.get(pk=t)

            tj = Journal()
            tj.task = task
            tj.done_by = flatmate
            tj.done_on = datetime.strptime(date_input, '%Y-%m-%d')
            tj.save()
        # Always return an HttpResponseRedirect after successfully dealing
        # with POST data. This prevents data from being posted twice if a
        # user hits the Back button.
        return HttpResponseRedirect(reverse('wgapp:journal_list', ))
コード例 #2
0
    def post(self):
        text = fileToText(self.request.get("data"))
        if text == None:
            self.redirect('/ramble')
            return
        text = unicodedata.normalize('NFKD', text).encode('ascii', 'ignore')
        wordList = filterFillers(text)
        emotions = find_emotions(wordList)
        topemotions = top_emotions(emotions)  #returns a list of top emotions
        rgb_1 = topemotions["first"]
        rgb_2 = topemotions["second"]
        full_text = " "
        full_text = full_text.join(wordList)

        user = users.get_current_user()
        email_address = user.nickname()

        if user:  #not tested yet
            now = datetime.utcnow()
            newJournal = Journal(
                user=email_address,
                text=full_text,
                rgb1=rgb_1,
                rgb2=rgb_2,
                year=int(now.year),
                month=int(now.month),
                sumSeconds=(int((now.day * 60 * 24 * 60) +
                                (now.hour * 60 * 60) + (now.minute * 60) +
                                (now.second))))

            newJournal.put()
            time.sleep(LATENCY_TIME)
            self.redirect("/slider?key=" + str(newJournal.year) + " " +
                          str(newJournal.month) + " " +
                          str(newJournal.sumSeconds))
コード例 #3
0
def add_journal(title, filename, tags, file_location):
    result = os.popen(f'ipfs add {file_location}')
    hash = result.read().split()[1]
    new_journal = Journal(hash=hash,
                          url=file_location,
                          filename=filename,
                          keywords=tags,
                          title=title)
    db.session.add(new_journal)
    db.session.commit()
    send_for_approval(f'j{new_journal.id}')
コード例 #4
0
ファイル: subs.py プロジェクト: okulov/trade_bot
async def main(broker_account_id=None):
    balance = 10000
    amount = 20

    journal = Journal(mode='debug')
    traider = Traider(balance, journal, amount)
    analysis = Analysis(journal)
    stock = Stock(traider, journal)
    client = ti.AsyncClient(TOKEN, use_sandbox=True)
    data = await get_data(client, figi)
    print('Amount of data:', len(data))
    df = pd.DataFrame(data)
    df.set_index('date', inplace=True)
    traider.trade(df,
                  strategy=StrategyMACD_Day(loss_level=loss,
                                            profit_level=profit,
                                            macd_level=macd_level,
                                            target_stability=target_stability))
    stock.interval_trade(df[-1:])
    analysis.score()
    no_update = True
    async with ti.Streaming(TOKEN,
                            receive_timeout=20,
                            reconnect_timeout=10,
                            heartbeat=20) as streaming:
        await streaming.candle.subscribe(figi, ti.CandleResolution.min5)
        async for event in streaming:

            if event.event == 'candle':
                pass
                # print(event.payload.figi, event.payload.c, event.payload.interval, event.payload.h, event.payload.time)

            if not (event.payload.time.strftime('%e-%m-%Y %H:%M')
                    == data[-1]['date']) and no_update:
                no_update = False
                data = await get_data(client, figi)
                df = pd.DataFrame(data)
                df.set_index('date', inplace=True)
                traider.trade(df,
                              strategy=StrategyMACD_Day(
                                  loss_level=loss,
                                  profit_level=profit,
                                  macd_level=macd_level,
                                  target_stability=target_stability))
                stock.interval_trade(df[-1:])
                analysis.score()
            elif event.payload.time.strftime(
                    '%e-%m-%Y %H:%M') == data[-1]['date']:
                no_update = True
コード例 #5
0
ファイル: app.py プロジェクト: jake202020/goutdoors
def new_journal_from_search(username, park_code):
    """Show form for adding a new journal with park already chosen (GET) or add journal to db and go to user page (POST)"""
    # Check if logged in user is this user
    if is_correct_user(username):
        form = NewJournalForm()

        # Get park_code and name from db table for select field in form
        park = Park.query.get_or_404(park_code)
        form.park_name.choices = [(park_code, park.park_name)]

        if form.validate_on_submit():
            date_added = datetime.now()
            date_of_visit = form.date_of_visit.data
            user_id = user_id
            title = form.title.data
            text = form.text.data
            park_code = form.park_name.data
            title_img_url = form.title_img_url.data

            journal = Journal(date_added=date_added,
                              date_of_visit=date_of_visit,
                              user_id=user_id,
                              title=title,
                              text=text,
                              park_code=park_code,
                              title_img_url=title_img_url)

            db.session.add(journal)
            db.session.commit()

            visit = Visit(date_of_visit=date_of_visit,
                          user_id=user_id,
                          park_code=park_code,
                          journal_id=journal.id)
            db.session.add(visit)
            db.session.commit()

            flash("Journal successfully created")
            # on successful creation, redirect to users page
            return redirect(f"/users/{ user.username }")

        return render_template("new_journal.html", form=form)

    flash("Not your dashboard")
    return redirect("/")
コード例 #6
0
ファイル: tasks.py プロジェクト: harajuku-tech/paloma
def bounce(sender, recipient, text, is_jailed=False, *args, **kwawrs):
    """ main bounce worker
    """
    from models import Journal
    log = bounce.get_logger()

    log.debug('From=%s To %s (jailed=%s)' % (sender, recipient, is_jailed))

    #: First of all, save messa to the Journal
    journal = None
    try:
        journal = Journal(sender=sender,
                          recipient=recipient,
                          is_jailed=is_jailed,
                          text=text)
        journal.save()
    except Exception, e:
        log.debug(str(e))
コード例 #7
0
def get_journal_id(record, created_by, date_created):
    journal_abbr = record.get('journal_abbrev', '')
    journal_full_name = record.get('journal_title', '')
    issn_print = record.get('issn_print')
    issn_electronic = record.get('issn_electronic')

    if issn_print:
        journals = DBSession.query(Journal).filter_by(
            issn_print=issn_print).all()
        if len(journals) > 0:
            return journals[0].journal_id, journals[
                0].med_abbr, journal_full_name, issn_print
    if journal_abbr:
        journals = DBSession.query(Journal).filter_by(
            med_abbr=journal_abbr).all()
        if len(journals) > 0:
            return journals[0].journal_id, journals[
                0].med_abbr, journal_full_name, issn_print

    source_id = 824  # 'PubMed'

    # format_name = journal_full_name.replace(' ', '_') + journal_abbr.replace(' ', '_')
    journal_full_name = journal_full_name.split(" : ")[0]
    format_name = journal_full_name.replace(' ', '_')

    j = Journal(issn_print=issn_print,
                issn_electronic=issn_electronic,
                display_name=journal_full_name,
                format_name=format_name,
                title=journal_full_name,
                med_abbr=journal_abbr,
                source_id=source_id,
                obj_url='/journal/' + format_name,
                date_created=date_created,
                created_by=created_by)
    DBSession.add(j)
    DBSession.flush()
    DBSession.refresh(j)

    return j.journal_id, j.med_abbr, journal_full_name, issn_print
コード例 #8
0
    def add_journal(self, created, from_wallet_id, to_wallet_id,
                    type_operation):
        """
        Добавление записи в журнал
        :param created: Время записи
        :param from_wallet_id: От кого
        :param to_wallet_id: Кому
        :param type_operation: Тип события
        :return: Результат выполнения функции (Строка)
        """
        try:
            journal = Journal(created=created,
                              from_wallet_id=from_wallet_id,
                              to_wallet_id=to_wallet_id,
                              type_operation=type_operation)

            self.session.add(journal)
            self.session.flush()
            self.session.commit()
            return 'ОК.'
        except:
            return 'ERROR.'
コード例 #9
0
import os
import time
from random import choice

from models import Journal

LEVEL_CHOICE = [10, 20, 30, 40, 50]
count = int(os.environ.get('ITERATIONS', '1000'))

start = now = time.time()
for i in range(count):
    Journal(level=choice(LEVEL_CHOICE), text=f'Insert from A, item {i}').save()
now = time.time()

print(f'peewee, A: Rows/sec: {count / (now - start): 10.2f}')
コード例 #10
0
def fetch_journals_info_from_nlmcatalog(broad_subject_term_name='',
                                        issn='',
                                        verbosity='full'):
    """
    Fetch journal and publisher info for all the journals 
    on nlmcatalog and add them/it to database

    Parameters
    ----------
    broad_subject_term: (str) BroadSubjectTerm names based on NLM Catalog for MEDLINE
    issn: (str)
    verbosity: (str or None) 'full' will print all dois, 'summary' prints the counter every 5 articles, None prints nothing

    Returns
    ---------
    None
    """
    if broad_subject_term_name:
        term = f'{broad_subject_term_name}%5Bst%5D'
    elif issn:
        term = f'"{issn}"%5BISSN%5D'
    else:  #> get all
        term = 'currentlyindexed'
    search_res_root = search_nlmcatalog(term=term)
    #> Get the NLM Catalogy IDs
    nlmcatalog_ids = [
        element.text
        for element in search_res_root.findall('IdList')[0].getchildren()
    ]
    if broad_subject_term_name:
        broad_subject_term = BroadSubjectTerm.objects.get(
            name=broad_subject_term_name)
    else:
        broad_subject_term = None
    for idx, nlmcatalog_id in enumerate(nlmcatalog_ids):
        if verbosity == 'full':
            print(f'{idx+1} of {len(nlmcatalog_ids)}: {nlmcatalog_id}')
        elif verbosity == 'summary' and ((idx + 1) % 5 == 0):
            print(f'{idx+1} of {len(nlmcatalog_ids)}')
        #> Check if journal already exist and avoid adding it
        #  but add the current subject term to the journal if it's new
        journal_Q = Journal.objects.allow_disk_use(True).filter(
            nlmcatalog_id=nlmcatalog_id)
        if journal_Q.count() > 0:
            if broad_subject_term:
                journal = journal_Q[0]
                if broad_subject_term not in journal.broad_subject_terms:
                    broad_subject_term.update(push__journals=journal)
            print('Already exists in db')
            continue
        journal_url = f'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=nlmcatalog&rettype=xml&id={nlmcatalog_id}'
        fetch_succeeded = False
        retries = 0
        while (retries < 10) and (not fetch_succeeded):
            try:
                journal_res_xml = requests.get(
                    journal_url, headers=scraper.REQUESTS_AGENT_HEADERS).text
                journal_res_root = ET.fromstring(journal_res_xml)
            except:
                time.sleep(.2)
                retries += 1
            else:
                fetch_succeeded = True
        #>> full_name from TitleMain
        if len(journal_res_root.find('NLMCatalogRecord').findall(
                'TitleMain')) > 0:
            full_name = journal_res_root.find('NLMCatalogRecord').find(
                'TitleMain').find('Title').text
            full_name = full_name.rstrip(
                '.')  # Remove the trailing "." from the name of some journals
        else:
            if verbosity == 'full':
                print(f"No TitleMain")
            continue
        #>> abbr_name from MedlineTA
        if len(journal_res_root.find('NLMCatalogRecord').findall(
                'MedlineTA')) > 0:
            abbr_name = journal_res_root.find('NLMCatalogRecord').find(
                'MedlineTA').text
        else:
            if verbosity == 'full':
                print(f"No MedlineTA")
            continue
        #> get ISSNs
        if len(journal_res_root.find('NLMCatalogRecord').findall('ISSN')) > 0:
            issns = [
                node.text for node in journal_res_root.find(
                    'NLMCatalogRecord').findall('ISSN')
            ]
        else:
            if verbosity == 'full':
                print(f"No ISSN")
            continue
        #> Get the journal and pmc url (if exists)
        pmc_url = journal_url = ''
        if len(
                journal_res_root.find('NLMCatalogRecord').findall(
                    'ELocationList')) > 0:
            for ELocation in journal_res_root.find('NLMCatalogRecord').find(
                    'ELocationList').findall('ELocation'):
                if len(ELocation.findall('ELocationID')) > 0:
                    ELocation_url = ELocation.find('ELocationID').text
                    if ELocation_url.startswith(
                            'https://www.ncbi.nlm.nih.gov/pmc/journals'):
                        pmc_url = ELocation_url
                    else:
                        journal_url = ELocation_url
        if (pmc_url == '') and (journal_url == ''):
            print(f"No pmc/journal url")
            continue
        #> Add the journal
        journal = Journal(full_name=full_name,
                          abbr_name=abbr_name,
                          issns=issns,
                          nlmcatalog_id=nlmcatalog_id,
                          pmc_url=pmc_url).save()
        #> Get the publisher url and domain from journal url
        if journal_url:
            journal_url_extract = tldextract.extract(journal_url)
            publisher_url = journal_url_extract.fqdn
            publisher_domain = journal_url_extract.domain
            #> Check if publisher is supported
            publisher_supported = publisher_domain in scraper.SUPPORTED_DOMAINS
            #> Create Publisher (if does not exist) and Journal database instances
            publisher_Q = Publisher.objects.filter(domain=publisher_domain)
            if publisher_Q.count() == 0:
                publisher = Publisher(domain=publisher_domain,
                                      url=publisher_url,
                                      supported=publisher_supported).save()
            else:
                publisher = publisher_Q[0]
            publisher.update(push__journals=journal)
コード例 #11
0
ファイル: test_b.py プロジェクト: tortoise/orm-benchmarks
import os
import time
from random import choice

from models import Journal
from pony.orm import commit, db_session

LEVEL_CHOICE = [10, 20, 30, 40, 50]
count = int(os.environ.get("ITERATIONS", "1000"))


start = now = time.time()
with db_session():
    for i in range(count):
        Journal(level=choice(LEVEL_CHOICE), text=f"Insert from B, item {i}")
    commit()
now = time.time()

print(f"Pony ORM, B: Rows/sec: {count / (now - start): 10.2f}")
コード例 #12
0
def main():
    if flask.request.method == 'GET':
        return flask.render_template('main.html')
    try:
        prompt = flask.request.form['message'][-MAX_PROMPT_LENGTH:]
        #cfg = botocore.config.Config(retries={'max_attempts': 0}, read_timeout=360, connect_timeout=360, region_name="eu-central-1" )
        if flask.request.form['requestid']:
            submitted = flask.request.form['submitted']
            requestid = flask.request.form['requestid']
            sqs = boto3.resource('sqs',
                                 region_name='eu-central-1',
                                 aws_access_key_id=aws_key,
                                 aws_secret_access_key=aws_secret_key)
            queue = sqs.get_queue_by_name(QueueName='TabaquiQueue')
            for message in queue.receive_messages(
                    MessageAttributeNames=['RequestId']):
                if message.message_attributes is not None:
                    mrequestid = message.message_attributes.get(
                        'RequestId').get('StringValue')
                    print(mrequestid + " " + requestid)
                    if mrequestid == requestid:
                        res = message.body
                        message.delete()
                        return flask.render_template('main.html',
                                                     result=submitted +
                                                     message.body)
            return flask.render_template('main.html',
                                         result=prompt + '... ',
                                         submitted=submitted,
                                         requestid=requestid)
        db.session.query(Journal).filter(
            func.date(Journal.request) <= datetime.date.today() -
            datetime.timedelta(days=1)).delete(synchronize_session='fetch')
        db.session.commit()
        q = db.session.query(Journal.id)  #.filter(...).order_by(...)
        if get_count(q) > MAX_REQUESTS_TO_AWS:
            return flask.render_template('main.html',
                                         result='Please try tomorrow')
        journal = Journal()
        db.session.add(journal)
        db.session.commit()
        db.session.refresh(journal)
        requestid = str(journal.id)
        print('Request id: ' + requestid)
        #boto3.setup_default_session(region_name='us-east-1')
        client = boto3.client(
            'lambda',
            region_name='eu-central-1',
            aws_access_key_id=aws_key,
            aws_secret_access_key=aws_secret_key)  #config = cfg
        prompt = ''.join([
            (s.strip() if s.find(':') > 0 and s.find('"') > 0 else
             names[random.randrange(0, len(names))] + ': "' + s.strip() + ' "')
            + '\n' for s in prompt.split('\n') if s.strip()
        ])
        if prompt.endswith(': "\n'):
            prompt = prompt[:-1]
        else:
            prompt = prompt + names[random.randrange(0, len(names))] + ': "'
        payload = {
            "RequestId": requestid,
            "Prompt": prompt,
            "Temperature": 0.9
        }  #, "NQuotes": 1}
        response = client.invoke(FunctionName='tabaqui_response',
                                 InvocationType='Event',
                                 LogType='Tail',
                                 Payload=json.dumps(payload))
        #dictj = json.loads(response['Payload'].read().decode())
        return flask.render_template('main.html',
                                     result=prompt + "\n" +
                                     str(response['StatusCode']) +
                                     "\nHave to wait for request " + requestid,
                                     submitted=prompt,
                                     requestid=requestid)
    except:
        return flask.render_template('main.html',
                                     result=str(sys.exc_info()))  #[0]
コード例 #13
0
ファイル: test_a.py プロジェクト: titusjoyson/orm-benchmarks
import os
import time
from random import choice

from models import Journal, engine
from sqlalchemy.orm import sessionmaker

LEVEL_CHOICE = [10, 20, 30, 40, 50]
count = int(os.environ.get('ITERATIONS', '1000'))


Session = sessionmaker(bind=engine)
start = now = time.time()
session = Session()
for i in range(count):
    session.add(Journal(
        level=choice(LEVEL_CHOICE),
        text=f'Insert from A, item {i}'
    ))
    session.commit()
now = time.time()

print(f'SQLAlchemy ORM, A: Rows/sec: {count / (now - start): 10.2f}')
コード例 #14
0
import os
import time
from random import choice

from models import Journal, conn

LEVEL_CHOICE = [10, 20, 30, 40, 50]

count = int(os.environ.get('ITERATIONS', '1000'))
start = now = time.time()
trans = conn.transaction()
for i in range(count):
    Journal(level=choice(LEVEL_CHOICE),
            text=f'Insert from B, item {i}',
            connection=trans)
trans.commit(close=True)
now = time.time()

print(f'SQLObject, B: Rows/sec: {count / (now - start): 10.2f}')
コード例 #15
0
}

loss = params['loss_level']
profit = params['profit_level']
macd_level = params['macd_level']
target_stability = params['target_stability']

# client = ti.SyncClient(TOKEN, use_sandbox=True)
# figi = sync_lists(client)

for f in figi:
    print(f)
    data = data_all[data_all['figi'] == f]
    df = data[-700:]

    journal = Journal(mode='')
    traider = Traider(balance, journal, amount, figi=f)
    stock = Stock(traider, journal)
    analysis = Analysis(traider, journal)

    for i in range(data_limit_MACD, len(df)):
        data_ = df[:i + 1]
        # print(data_[-1:])
        # print(talib.MACD(data_['Close']))
        traider.trade(data_,
                      strategy=StrategyMACD_Day(
                          loss_level=loss,
                          profit_level=profit,
                          macd_level=macd_level,
                          target_stability=target_stability))
        # traider.trade(data_, strategy=StartegyBase())
コード例 #16
0
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from models import Base, Paper, Journal, Project

if os.path.isfile('my_papers.db'):
    os.remove('my_papers.db')

# echo true goes on engine
engine = create_engine('sqlite:///my_papers.db')
Session = sessionmaker(bind=engine)
session = Session()

Base.metadata.create_all(engine)

jchem_phys = Journal(name='J. Chem. Phys', publisher='AIP')
jcim = Journal(name='J. Chem. Inf. Model', publisher='ACS')

# Add a paper to the DB
molssi_paper = Paper(
    DOI='10.1063/1.5052551',
    paper_title=
    'Perspective: Computational chemistry software and its advancement as illustrated through three grand challenge cases for molecular science',
    journal=jchem_phys,
    publication_year=2018,
    authors=
    'Anna Krylov, Theresa L. Windus, Taylor Barnes, Eliseo Marin-Rimoldi, Jessica A. Nash, Benjamin Pritchard, Daniel G.A. Smith, Doaa Altarawy, Paul Saxe, Cecilia Clementi, T. Daniel Crawford, Robert J. Harrison, Shantenu Jha, Vijay S. Pande, Teresa Head-Gordon'
)

# Add another paper
bse_paper = Paper(
コード例 #17
0
async def _runtest(count):
    await Journal.bulk_create([
        Journal(level=choice(LEVEL_CHOICE), text=f'Insert from C, item {i}')
        for i in range(count)
    ])
コード例 #18
0
import os
import time
from random import choice

from models import Journal, engine
from sqlalchemy.orm import sessionmaker

LEVEL_CHOICE = [10, 20, 30, 40, 50]
count = int(os.environ.get('ITERATIONS', '1000'))


Session = sessionmaker(bind=engine)
start = now = time.time()
session = Session()
session.bulk_save_objects([
    Journal(
        level=choice(LEVEL_CHOICE),
        text=f'Insert from C, item {i}'
    ) for i in range(count)
])
session.commit()
now = time.time()

print(f'SQLAlchemy ORM, C: Rows/sec: {count / (now - start): 10.2f}')