def get_config(): conf = os.path.join(etcdir, 'datasets.json') conf = json.load(open(conf)) localconf = os.path.join(etcdir, 'datasets.local.json') if os.path.exists(localconf): localconf = json.load(open(localconf)) merge(conf, localconf) # => Resolve paths params = conf.get('params',{}) for d in conf['datasets']: context = params.copy() context.update({ 'dataset': d }) for var in ['root', 'remote']: if var in conf['datasets'][d]: #=> Update the datasets value = conf['datasets'][d][var] value = os.path.expandvars(value) value = value % context conf['datasets'][d][var] = value return conf
def test_merge(self): for fixture in ordered_fixtures: self.assertEqual( merge.merge(fixture[0].copy(), fixture[1], position='last'), fixture[2]) self.assertEqual( merge.merge(fixture[0].copy(), fixture[1], position='first'), fixture[3])
def test_merge_value_conflit(): """ Merge dicts with value conflict. """ a = {"A": 0, "B": 1} b = {"A": 1, "C": 2} with pytest.raises(ValueError): lib.merge(a, b)
def test_merge_type_conflit(): """ Merge dicts with type conflict. """ a = {"A": 0, "B": 1} b = {"A": 0, "B": {"C": 2}} c = {"A": 0, "B": ["C"]} with pytest.raises(TypeError): lib.merge(a, b) with pytest.raises(TypeError): lib.merge(a, c)
def main() -> None: # logger logger = logging.getLogger('lib') logger.setLevel(logging.INFO) handler = logging.StreamHandler() handler.formatter = logging.Formatter( fmt='%(asctime)s %(name)s:%(levelname)s:%(message)s') logger.addHandler(handler) # arg parser parser = argparse.ArgumentParser(description='Fate/Grand Order scrayping') parser.add_argument('mode', choices=['dict', 'item', 'servant', 'sound', 'merge'], help='scraping target') parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', help='set log level to debug') parser.add_argument('-f', '--force', dest='force', action='store_true', help='force update') parser.add_argument('--request-interval', dest='request_interval', type=float, default=_REQUEST_INTERVAL, help='request intarval seconds (default: %(default)s)', metavar='SECONDS') # option option = parser.parse_args() if option.verbose: logger.setLevel(logging.DEBUG) logger.debug('option: %s', option) # dict if option.mode in ['dict', 'merge']: logger.info('run: dict') dictionary = load_dict(pathlib.Path('data/dictionary/'), force_update=option.force or option.mode == 'dict') # item if option.mode in ['item', 'merge']: logger.info('run: item') items = load_items(pathlib.Path('data/items.json'), force_update=option.force or option.mode == 'item') # servant if option.mode in ['servant', 'merge']: logger.info('run: servant') servants = load_servants(pathlib.Path('data/servant/'), force_update=option.force) # sound if option.mode in ['sound', 'merge']: logger.info('run: sound') sounds = load_sounds(pathlib.Path('data/sound.json'), force_update=option.force) # master data if option.mode == 'merge': logger.info('run: merge') data = lib.merge(items, servants, sounds, dictionary) lib.save_json(pathlib.Path('data/master_data.json'), data)
def example_merging_strategies(): """illustrate differences between mapping merge strategies""" m_1 = {('A', 'a'), ('B', 'b'), ('B', 'c'), ('D', 'e'), ('G', 'g')} m_2 = {('a', 'A'), ('b', 'B'), ('c', 'B'), ('f', 'D')} print(f'{m_1} U {m_2}') for strict, strategy in product([True, False], [cr_prune, cr_ignore]): m = merge(m_1, m_2, strict, strategy) print(f'strict: {strict}, strategy: {strategy.__name__}\t=> {m}')
def test_merge_recursive(): """ Merge dicts recursively. """ a = {"A": 0, "B": {"C": 1}} b = {"B": {"D": 2}} c = {"A": 0, "B": {"C": 1, "D": 2}} assert lib.merge(a, b) == c
def test_merge(): """ Merge dicts. """ a = {"A": 0} b = {"B": 1} c = {"A": 0, "B": 1} assert lib.merge(a, b) == c
def _simulate(alpha, beta, gap_penalty=.25): similarities = BetaDistributedSimilarity(alpha, beta, LTS_P.labels, LTS_Q.labels, REFERENCE_MAPPING, .3) s_def = LPSimulator(similarities, gap_penalty) s_min = LPSimulator(similarities, gap_penalty, strategy=min) s_max = LPSimulator(similarities, gap_penalty, strategy=max) s_avg = LPSimulator(similarities, gap_penalty, strategy=s_average) m_pq = trace(LTS_P, LTS_Q, s_def) m_qp = trace(LTS_Q, LTS_P, s_def) return [ greedy_mapper(similarities, .3), m_pq, {(b, a) for a, b in m_qp}, merge(m_pq, m_qp, resolution=cr_prune), merge(m_pq, m_qp, resolution=cr_ignore), merge(m_pq, m_qp, strict=True, resolution=cr_prune), merge(m_pq, m_qp, strict=True, resolution=cr_ignore), trace(LTS_P, LTS_Q, s_min, bisimulation=True), trace(LTS_P, LTS_Q, s_max, bisimulation=True), trace(LTS_P, LTS_Q, s_avg, bisimulation=True), ]
def test_merge_bad_types(): """ Merge non dicts. """ with pytest.raises(TypeError): lib.merge({}, []) with pytest.raises(TypeError): lib.merge([], {}) with pytest.raises(TypeError): lib.merge([], []) with pytest.raises(TypeError): lib.merge({}, "Test") with pytest.raises(TypeError): lib.merge("Test", {}) with pytest.raises(TypeError): lib.merge("Test", "Test")
def test_merge(self): for fixture in fixtures: self.assertEqual(merge.merge(fixture[0], fixture[1]), fixture[2])
def test_merge(self): for fixture in ordered_fixtures: self.assertEqual(merge.merge(fixture[0].copy(), fixture[1], position='last'), fixture[2]) self.assertEqual(merge.merge(fixture[0].copy(), fixture[1], position='first'), fixture[3])
import lib main_title = 'To udvalgte prognoser for antal indlagte per dag fra ekspertrapport af 21. Februar 2021' days = 122 # [8 Feb; 1 June[ title1 = ' Aktivitet som 8. februar uden genåbning og med flere tests (Rref 0.75)' data = lib.Prediction('reports/20210221/page19-000-fixed.png', x_size=days, y_size=250) img1 = [data.process(158, 445)] title2 = 'Samme scenarie men med 6-7% mere smittespredning (Rref 0.80)' data = lib.Prediction('reports/20210221/page20-000-fixed.png', x_size=days, y_size=250) img2 = [data.process(158, 445)] left_explainer = ['Antal indlagte per dag'] final = lib.merge(left_explainer, [(title1, img1), (title2, img2)]) lib.save(lib.add_header(final, main_title), 'result.png')