Пример #1
0
def set_time_interval(from_day: float, to_day: float):
    """
    Sets start time and stop time to param.in file.
    :param from_day:
    :param to_day:
    :return:
    """
    def _edit_file(filepath: str, callback: Callable[[Iterable[str], TextIO],
                                                     None]):
        with open(filepath) as f:
            out_fname = filepath + ".tmp"
            out = open(out_fname, "w")
            callback(f, out)
            out.close()
            os.rename(out_fname, filepath)

    def _update_params(infile: Iterable[str], outfile: TextIO):
        startday_pattern = ' start time (days)= '
        stopday_pattern = ' stop time (days) = '
        for line in infile:
            if line.startswith(startday_pattern):
                line = '%s%f\n' % (startday_pattern, from_day)
            if line.startswith(stopday_pattern):
                line = '%s%f\n' % (stopday_pattern, to_day)
            outfile.write(line)

    integrator_path = opjoin(Config.get_project_dir(),
                             CONFIG['integrator']['dir'])
    param_in_filepath = opjoin(integrator_path,
                               CONFIG.INTEGRATOR_PARAM_FILENAME)

    _edit_file(param_in_filepath, _update_params)
Пример #2
0
import glob
import logging
import os
import shutil
import subprocess
from os.path import join as opjoin

from resonances.integrator import element6
from resonances.integrator import simple_clean
from resonances.settings import Config

CONFIG = Config.get_params()
PROJECT_DIR = Config.get_project_dir()
BODIES_COUNTER = int(CONFIG['integrator']['number_of_bodies'])
EXPORT_BASE_DIR = opjoin(PROJECT_DIR, CONFIG['export']['base_dir'])


class ExtractError(Exception):
    pass


def extract(start: int, elements: bool = False, do_copy_aei: bool = False) -> bool:
    """Extract resonance file from archive to directory in export folder
    start — first object number for extracting (start + number of bodies)
    elements — should mercury6 create aei files for all objects?

    :param int start:
    :param bool elements:
    :param bool do_copy_aei:
    :rtype bool:
    :raises FileNotFoundError: if archive not found.
Пример #3
0
from http.client import HTTPResponse
from urllib.request import URLError
from resonances.shortcuts import FAIL, ENDC
from bs4 import BeautifulSoup
from bs4.element import Tag
import traceback
import sys
from typing import Iterable
from typing import Tuple
from typing import List
from typing import Dict
import logging
import texttable
from resonances.settings import Config

CONFIG = Config.get_params()
URL_BASE = CONFIG['online']['neodys']['variation_base_url']


def _variations_gen(from_cells: List[Tag]):
    """
    Filters td elements with variations from all.
    """
    for i, x in enumerate(from_cells):
        if (i - 2) % 3 != 0:
            continue
        yield x.get_text()


def _parse_asteroid_variations(from_html_data: str) -> Dict[str, float]:
    bs = BeautifulSoup(from_html_data, 'html.parser')
Пример #4
0
from alembic.config import Config as AlembicConfig
from sqlalchemy.sql.expression import Executable
from sqlalchemy import create_engine, Integer, Column
from sqlalchemy import event
from sqlalchemy.engine import Engine
from sqlalchemy.ext.declarative import as_declarative
from sqlalchemy.orm import Session
from sqlalchemy.orm import sessionmaker
from sqlalchemy.sql import ClauseElement
from sqlalchemy.sql import Insert
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.dialects.postgresql.psycopg2 import PGCompiler_psycopg2

from resonances.settings import Config

CONFIG = Config.get_params()
_HOST = CONFIG['postgres']['host']
_USER = CONFIG['postgres']['user']
_PASSWORD = CONFIG['postgres']['password']
_DB = CONFIG['postgres']['db']
T = TypeVar('T')

if CONFIG['debug']:
    logging.basicConfig()
    logger = logging.getLogger("myapp.sqltime")
    logger.setLevel(logging.DEBUG)

    @event.listens_for(Engine, "before_cursor_execute")
    def before_cursor_execute(conn, cursor, statement, parameters, context,
                              executemany):
        conn.info.setdefault('query_start_time', []).append(time.time())
Пример #5
0
import os
from os.path import join as opjoin
from shutil import copyfile

from resonances.settings import Config

PROJECT_DIR = Config.get_project_dir()
INTEGRATOR_PATH = opjoin(PROJECT_DIR, Config.get_params()['integrator']['dir'])
PARAMS = Config.get_params()


def test_set_time_interval():
    from resonances.integrator import set_time_interval

    def _copyfile(name: str):
        path = opjoin(INTEGRATOR_PATH, name)
        target = opjoin(INTEGRATOR_PATH, name + '.backup')
        copyfile(path, target)
        return path

    param_in_filepath = _copyfile(PARAMS.INTEGRATOR_PARAM_FILENAME)

    set_time_interval(1, 2)

    startday_assert_flag = False
    stopday_assert_flag = False
    with open(param_in_filepath) as f:
        for line in f:
            startday_assert_flag = startday_assert_flag or (' start time (days)= 1' in line)
            stopday_assert_flag = stopday_assert_flag or (' stop time (days) = 2' in line)