content
stringlengths 1
1.04M
| input_ids
sequencelengths 1
774k
| ratio_char_token
float64 0.38
22.9
| token_count
int64 1
774k
|
---|---|---|---|
#!/usr/bin/env python2
# -*- encoding: utf-8 -*-
# Gimp Markup Builder
# author: duangsuse
# date: Thu May 02 2019 CST
from os import linesep
from Util import stream_join
class MarkupBuilder:
''' Gimp Markup SGML builder '''
'''
Indent rules:
when starting new tag, write last spaces, last spaces += indent
if new tag is not text tag start (inner is just text), write newline
when leaving tag, last spaces -= indent
'''
indented = property(useindent)
def wnewline(self):
''' see use_indent'''
self.marks += self.nl
def windent(self):
''' see use_indent'''
wrote = 0
for _ in range(0, self.last_spaces):
self.marks += ' '
wrote += 1 # dummy?
return wrote
def cancel_indent(self):
''' cancel last indent '''
if self.indented: self.marks = self.marks[:-self.revert_last_indent_size]
def do_indent(self, entering = True):
''' Write indent, increase last_spaces, saving wrote spaces and newline to revert_last_indent_size '''
if self.indented: do()
def do_last_indent(self, *args, **kwargs):
''' write indenting for last block '''
self.last_spaces -= self.indent
self.do_indent(*args, **kwargs)
self.last_spaces += self.indent
def begin(self, tag, attrs = {}):
'''
Make a tag with name and attributes
Attribute name, value and tag name is escaped
'''
self.last_is_text = False
attrst = str()
tagscape = self.escape(tag)
ary = list(stream_join(attrs.keys(), attrs.values())) if attrs.__class__ is dict else list(attrs)
if len(attrs) != 0:
for n in range(0, len(ary), 2):
attrst += self.escape(str(ary[n]))
attrst += '='
#print(ary)
#print(n)
attrst += "\"%s\"" % self.escape(str(ary[n+1]))
self.marks += '<' + tagscape
if len(attrs) != 0: self.marks += ' '
self.marks += attrst + '>'
# always write indents for next line
# makes its possible to drop last indent (text tag)
self.do_indent()
self.tag_stack.append(tagscape)
return self
def tag(self, *args, **kwargs):
r'''
EDSL using __close__ with syntax
create nodes like:
with xml.tag('span', {color: '#66ccff'}):
xml % 'Q \w\ Q'
'''
self.last_is_text = False
return TagBuilder(self)
def text(self, content):
''' append text content '''
self.last_is_text = True
if self.indented: self.cancel_indent()
self.marks += self.escape(content)
return self
#@staticmethod
#def test():
# m = MarkupBuilder()
# m > 'html'
# m > 'head'
# m > 'title'
# m < 'Hello World'
# m <= 2
# m > 'body'
# m > 'text'
# with m.tag("b"):
# m < 'String'
# m >= ['a', {'id': 'str'}]
# m < '|sg.'
# m <= 4
# return m
def end(self):
''' delimites last tag '''
if not self.last_is_text: # cancel indentation
#print(self.indent, self.tag_stack)
self.cancel_indent()
self.do_indent(False)
self.marks += '</' + self.tag_stack.pop() + '>'
self.do_indent(False)
self.last_is_text = False
# Not cared by Markup indent emitter
def raw(self, raw):
''' write raw text (unescaped) '''
self.marks += raw
return self
def rawtag(self, rawtext):
''' append unescaped raw <> text '''
self.marks += '<'
self.marks += rawtext
self.marks += '>'
def _escape(self, xml):
'''
Escape XML string
' is replaced with '
" is replaced with "
& is replaced with &
< is replaced with <
> is replaced with >
'''
escapes = frozenset("'\"&<>")
replacement = { '\'': 'apos', '"': 'quot', '&': 'amp', '<': 'lt', '>': 'gt' }
if len(xml) < 1: return
output = str()
for i in range(0, len(xml)):
char = xml[i]
if (char in escapes):
output += '&'
output += replacement[char]
output += ';'
else: output += char
return output
escape = classmethod(_escape)
def __str__(self):
''' M(marks)..[tag stack] '''
return 'M(' + self.marks + ')..' + str(self.tag_stack)
__lt__ = text # chain
__gt__ = begin # chain
__add__ = raw # chain
def __contains__(self, tag):
''' is tag inside enclosing tags ? '''
return tag in self.tag_stack
def __ge__(self, tag_attr):
''' xml >= ['markup', {'name': 'abcs'}] '''
mark = tag_attr[0]
attr = tag_attr[1]
self.begin(mark, attr)
def __le__(self, n = 1):
''' Leave (close) N tags '''
while n > 0:
self.end()
n -= 1
| [
2,
48443,
14629,
14,
8800,
14,
24330,
21015,
17,
198,
2,
532,
9,
12,
21004,
25,
3384,
69,
12,
23,
532,
9,
12,
198,
198,
2,
402,
11011,
2940,
929,
35869,
198,
2,
1772,
25,
7043,
27725,
1904,
198,
2,
3128,
25,
26223,
1737,
7816,
13130,
46429,
198,
198,
6738,
28686,
1330,
3951,
538,
198,
198,
6738,
7273,
346,
1330,
4269,
62,
22179,
198,
198,
4871,
2940,
929,
32875,
25,
198,
220,
705,
7061,
402,
11011,
2940,
929,
26147,
5805,
27098,
705,
7061,
628,
220,
705,
7061,
198,
220,
1423,
298,
3173,
25,
628,
220,
618,
3599,
649,
7621,
11,
3551,
938,
9029,
11,
938,
9029,
15853,
33793,
198,
220,
611,
649,
7621,
318,
407,
2420,
7621,
923,
357,
5083,
318,
655,
2420,
828,
3551,
649,
1370,
198,
220,
618,
4305,
7621,
11,
938,
9029,
48185,
33793,
198,
220,
705,
7061,
198,
220,
773,
4714,
796,
3119,
7,
1904,
521,
298,
8,
198,
220,
825,
266,
3605,
1370,
7,
944,
2599,
198,
220,
220,
220,
705,
7061,
766,
779,
62,
521,
298,
7061,
6,
198,
220,
220,
220,
2116,
13,
14306,
15853,
2116,
13,
21283,
198,
220,
825,
2344,
298,
7,
944,
2599,
198,
220,
220,
220,
705,
7061,
766,
779,
62,
521,
298,
7061,
6,
198,
220,
220,
220,
2630,
796,
657,
198,
220,
220,
220,
329,
4808,
287,
2837,
7,
15,
11,
2116,
13,
12957,
62,
2777,
2114,
2599,
198,
220,
220,
220,
220,
220,
2116,
13,
14306,
15853,
705,
705,
198,
220,
220,
220,
220,
220,
2630,
15853,
352,
1303,
31548,
30,
198,
220,
220,
220,
1441,
2630,
198,
220,
825,
14241,
62,
521,
298,
7,
944,
2599,
198,
220,
220,
220,
705,
7061,
14241,
938,
33793,
705,
7061,
198,
220,
220,
220,
611,
2116,
13,
521,
4714,
25,
2116,
13,
14306,
796,
2116,
13,
14306,
58,
21912,
944,
13,
260,
1851,
62,
12957,
62,
521,
298,
62,
7857,
60,
198,
220,
825,
466,
62,
521,
298,
7,
944,
11,
8218,
796,
6407,
2599,
198,
220,
220,
220,
705,
7061,
19430,
33793,
11,
2620,
938,
62,
2777,
2114,
11,
8914,
2630,
9029,
290,
649,
1370,
284,
34052,
62,
12957,
62,
521,
298,
62,
7857,
705,
7061,
198,
220,
220,
220,
611,
2116,
13,
521,
4714,
25,
466,
3419,
628,
220,
825,
466,
62,
12957,
62,
521,
298,
7,
944,
11,
1635,
22046,
11,
12429,
46265,
22046,
2599,
198,
220,
220,
220,
705,
7061,
3551,
33793,
278,
329,
938,
2512,
705,
7061,
198,
220,
220,
220,
2116,
13,
12957,
62,
2777,
2114,
48185,
2116,
13,
521,
298,
198,
220,
220,
220,
2116,
13,
4598,
62,
521,
298,
46491,
22046,
11,
12429,
46265,
22046,
8,
198,
220,
220,
220,
2116,
13,
12957,
62,
2777,
2114,
15853,
2116,
13,
521,
298,
628,
220,
825,
2221,
7,
944,
11,
7621,
11,
708,
3808,
796,
23884,
2599,
198,
220,
220,
220,
705,
7061,
198,
220,
220,
220,
6889,
257,
7621,
351,
1438,
290,
12608,
628,
220,
220,
220,
3460,
4163,
1438,
11,
1988,
290,
7621,
1438,
318,
13537,
198,
220,
220,
220,
705,
7061,
198,
220,
220,
220,
2116,
13,
12957,
62,
271,
62,
5239,
796,
10352,
198,
220,
220,
220,
708,
81,
301,
796,
965,
3419,
198,
220,
220,
220,
7621,
6794,
796,
2116,
13,
41915,
7,
12985,
8,
628,
220,
220,
220,
257,
563,
796,
1351,
7,
5532,
62,
22179,
7,
1078,
3808,
13,
13083,
22784,
708,
3808,
13,
27160,
3419,
4008,
611,
708,
3808,
13,
834,
4871,
834,
318,
8633,
2073,
1351,
7,
1078,
3808,
8,
198,
220,
220,
220,
611,
18896,
7,
1078,
3808,
8,
14512,
657,
25,
198,
220,
220,
220,
220,
220,
329,
299,
287,
2837,
7,
15,
11,
18896,
7,
560,
828,
362,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
708,
81,
301,
15853,
2116,
13,
41915,
7,
2536,
7,
560,
58,
77,
60,
4008,
198,
220,
220,
220,
220,
220,
220,
220,
708,
81,
301,
15853,
705,
11639,
198,
220,
220,
220,
220,
220,
220,
220,
1303,
4798,
7,
560,
8,
198,
220,
220,
220,
220,
220,
220,
220,
1303,
4798,
7,
77,
8,
198,
220,
220,
220,
220,
220,
220,
220,
708,
81,
301,
15853,
366,
7879,
4,
82,
7879,
1,
4064,
2116,
13,
41915,
7,
2536,
7,
560,
58,
77,
10,
16,
60,
4008,
628,
220,
220,
220,
2116,
13,
14306,
15853,
705,
27,
6,
1343,
7621,
6794,
198,
220,
220,
220,
611,
18896,
7,
1078,
3808,
8,
14512,
657,
25,
2116,
13,
14306,
15853,
705,
705,
198,
220,
220,
220,
2116,
13,
14306,
15853,
708,
81,
301,
1343,
705,
29,
6,
628,
220,
220,
220,
1303,
1464,
3551,
773,
658,
329,
1306,
1627,
198,
220,
220,
220,
1303,
1838,
663,
1744,
284,
4268,
938,
33793,
357,
5239,
7621,
8,
198,
220,
220,
220,
2116,
13,
4598,
62,
521,
298,
3419,
628,
220,
220,
220,
2116,
13,
12985,
62,
25558,
13,
33295,
7,
12985,
6794,
8,
198,
220,
220,
220,
1441,
2116,
628,
220,
825,
7621,
7,
944,
11,
1635,
22046,
11,
12429,
46265,
22046,
2599,
198,
220,
220,
220,
374,
7061,
6,
198,
220,
220,
220,
412,
5258,
43,
1262,
11593,
19836,
834,
351,
15582,
628,
220,
220,
220,
2251,
13760,
588,
25,
198,
220,
220,
220,
351,
35555,
13,
12985,
10786,
12626,
3256,
1391,
8043,
25,
705,
2,
2791,
535,
487,
6,
92,
2599,
198,
220,
220,
220,
220,
220,
35555,
4064,
705,
48,
3467,
86,
59,
1195,
6,
198,
220,
220,
220,
705,
7061,
198,
220,
220,
220,
2116,
13,
12957,
62,
271,
62,
5239,
796,
10352,
198,
220,
220,
220,
1441,
17467,
32875,
7,
944,
8,
628,
220,
825,
2420,
7,
944,
11,
2695,
2599,
198,
220,
220,
220,
705,
7061,
24443,
2420,
2695,
705,
7061,
198,
220,
220,
220,
2116,
13,
12957,
62,
271,
62,
5239,
796,
6407,
198,
220,
220,
220,
611,
2116,
13,
521,
4714,
25,
2116,
13,
66,
21130,
62,
521,
298,
3419,
198,
220,
220,
220,
2116,
13,
14306,
15853,
2116,
13,
41915,
7,
11299,
8,
198,
220,
220,
220,
1441,
2116,
628,
220,
1303,
31,
12708,
24396,
198,
220,
1303,
4299,
1332,
33529,
198,
220,
1303,
220,
285,
796,
2940,
929,
32875,
3419,
198,
220,
1303,
220,
285,
1875,
705,
6494,
6,
198,
220,
1303,
220,
285,
1875,
705,
2256,
6,
198,
220,
1303,
220,
285,
1875,
705,
7839,
6,
198,
220,
1303,
220,
285,
1279,
705,
15496,
2159,
6,
198,
220,
1303,
220,
285,
19841,
362,
198,
220,
1303,
220,
285,
1875,
705,
2618,
6,
198,
220,
1303,
220,
285,
1875,
705,
5239,
6,
198,
220,
1303,
220,
351,
285,
13,
12985,
7203,
65,
1,
2599,
198,
220,
1303,
220,
220,
220,
285,
1279,
705,
10100,
6,
198,
220,
1303,
220,
285,
18189,
37250,
64,
3256,
1391,
6,
312,
10354,
705,
2536,
6,
92,
60,
198,
220,
1303,
220,
285,
1279,
705,
91,
45213,
2637,
198,
220,
1303,
220,
285,
19841,
604,
198,
220,
1303,
220,
1441,
285,
628,
220,
825,
886,
7,
944,
2599,
198,
220,
220,
220,
705,
7061,
46728,
2737,
938,
7621,
705,
7061,
198,
220,
220,
220,
611,
407,
2116,
13,
12957,
62,
271,
62,
5239,
25,
1303,
14241,
33793,
341,
198,
220,
220,
220,
220,
220,
1303,
4798,
7,
944,
13,
521,
298,
11,
2116,
13,
12985,
62,
25558,
8,
198,
220,
220,
220,
220,
220,
2116,
13,
66,
21130,
62,
521,
298,
3419,
198,
220,
220,
220,
220,
220,
2116,
13,
4598,
62,
521,
298,
7,
25101,
8,
628,
220,
220,
220,
2116,
13,
14306,
15853,
705,
3556,
6,
1343,
2116,
13,
12985,
62,
25558,
13,
12924,
3419,
1343,
705,
29,
6,
198,
220,
220,
220,
2116,
13,
4598,
62,
521,
298,
7,
25101,
8,
198,
220,
220,
220,
2116,
13,
12957,
62,
271,
62,
5239,
796,
10352,
628,
220,
1303,
1892,
19951,
416,
2940,
929,
33793,
795,
1967,
198,
220,
825,
8246,
7,
944,
11,
8246,
2599,
198,
220,
220,
220,
705,
7061,
3551,
8246,
2420,
357,
403,
3798,
5813,
8,
705,
7061,
198,
220,
220,
220,
2116,
13,
14306,
15853,
8246,
198,
220,
220,
220,
1441,
2116,
628,
220,
825,
8246,
12985,
7,
944,
11,
8246,
5239,
2599,
198,
220,
220,
220,
705,
7061,
24443,
555,
3798,
5813,
8246,
1279,
29,
2420,
705,
7061,
198,
220,
220,
220,
2116,
13,
14306,
15853,
705,
27,
6,
198,
220,
220,
220,
2116,
13,
14306,
15853,
8246,
5239,
198,
220,
220,
220,
2116,
13,
14306,
15853,
705,
29,
6,
628,
220,
825,
4808,
41915,
7,
944,
11,
35555,
2599,
198,
220,
220,
220,
705,
7061,
198,
220,
220,
220,
14473,
23735,
4731,
628,
220,
220,
220,
705,
318,
6928,
351,
1222,
499,
418,
26,
198,
220,
220,
220,
366,
318,
6928,
351,
1222,
421,
313,
26,
198,
220,
220,
220,
1222,
318,
6928,
351,
1222,
696,
26,
198,
220,
220,
220,
1279,
318,
6928,
351,
1222,
2528,
26,
198,
220,
220,
220,
1875,
318,
6928,
351,
1222,
13655,
26,
198,
220,
220,
220,
705,
7061,
198,
220,
220,
220,
32695,
796,
8400,
8247,
316,
7203,
6,
7879,
5,
27,
29,
4943,
198,
220,
220,
220,
9014,
796,
1391,
705,
59,
7061,
25,
705,
499,
418,
3256,
705,
1,
10354,
705,
421,
313,
3256,
705,
5,
10354,
705,
696,
3256,
705,
27,
10354,
705,
2528,
3256,
705,
29,
10354,
705,
13655,
6,
1782,
628,
220,
220,
220,
611,
18896,
7,
19875,
8,
1279,
352,
25,
1441,
198,
220,
220,
220,
5072,
796,
965,
3419,
198,
220,
220,
220,
329,
1312,
287,
2837,
7,
15,
11,
18896,
7,
19875,
8,
2599,
198,
220,
220,
220,
220,
220,
1149,
796,
35555,
58,
72,
60,
198,
220,
220,
220,
220,
220,
611,
357,
10641,
287,
32695,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
5072,
15853,
705,
5,
6,
198,
220,
220,
220,
220,
220,
220,
220,
5072,
15853,
9014,
58,
10641,
60,
198,
220,
220,
220,
220,
220,
220,
220,
5072,
15853,
705,
26,
6,
198,
220,
220,
220,
220,
220,
2073,
25,
5072,
15853,
1149,
198,
220,
220,
220,
1441,
5072,
628,
220,
6654,
796,
1398,
24396,
28264,
41915,
8,
628,
220,
825,
11593,
2536,
834,
7,
944,
2599,
198,
220,
220,
220,
705,
7061,
337,
7,
14306,
8,
492,
58,
12985,
8931,
60,
705,
7061,
198,
220,
220,
220,
1441,
705,
44,
10786,
1343,
2116,
13,
14306,
1343,
705,
8,
492,
6,
1343,
965,
7,
944,
13,
12985,
62,
25558,
8,
628,
220,
11593,
2528,
834,
796,
2420,
1303,
6333,
198,
220,
11593,
13655,
834,
796,
2221,
1303,
6333,
198,
220,
11593,
2860,
834,
796,
8246,
1303,
6333,
628,
220,
825,
11593,
3642,
1299,
834,
7,
944,
11,
7621,
2599,
198,
220,
220,
220,
705,
7061,
318,
7621,
2641,
13507,
2752,
15940,
5633,
705,
7061,
198,
220,
220,
220,
1441,
7621,
287,
2116,
13,
12985,
62,
25558,
628,
220,
825,
11593,
469,
834,
7,
944,
11,
7621,
62,
35226,
2599,
198,
220,
220,
220,
705,
7061,
35555,
18189,
37250,
4102,
929,
3256,
1391,
6,
3672,
10354,
705,
397,
6359,
6,
92,
60,
705,
7061,
198,
220,
220,
220,
1317,
796,
7621,
62,
35226,
58,
15,
60,
198,
220,
220,
220,
708,
81,
796,
7621,
62,
35226,
58,
16,
60,
198,
220,
220,
220,
2116,
13,
27471,
7,
4102,
11,
708,
81,
8,
628,
220,
825,
11593,
293,
834,
7,
944,
11,
299,
796,
352,
2599,
198,
220,
220,
220,
705,
7061,
17446,
357,
19836,
8,
399,
15940,
705,
7061,
198,
220,
220,
220,
981,
299,
1875,
657,
25,
198,
220,
220,
220,
220,
220,
2116,
13,
437,
3419,
198,
220,
220,
220,
220,
220,
299,
48185,
352,
628
] | 2.37605 | 1,904 |
from pkg_resources import DistributionNotFound, get_distribution, parse_version
try:
import psycopg2 # noqa: F401
except ImportError:
raise ImportError(
'No module named psycopg2. Please install either '
'psycopg2 or psycopg2-binary package for CPython '
'or psycopg2cffi for Pypy.'
)
for package in ['psycopg2', 'psycopg2-binary', 'psycopg2cffi']:
try:
if get_distribution(package).parsed_version < parse_version('2.5'):
raise ImportError('Minimum required version for psycopg2 is 2.5')
break
except DistributionNotFound:
pass
__version__ = get_distribution('hs-sqlalchemy-redshift').version
from sqlalchemy.dialects import registry
registry.register("redshift", "sqlalchemy_redshift.dialect", "RedshiftDialect")
registry.register(
"redshift.psycopg2", "sqlalchemy_redshift.dialect", "RedshiftDialect"
)
| [
6738,
279,
10025,
62,
37540,
1330,
27484,
3673,
21077,
11,
651,
62,
17080,
3890,
11,
21136,
62,
9641,
198,
198,
28311,
25,
198,
220,
220,
220,
1330,
17331,
22163,
70,
17,
220,
1303,
645,
20402,
25,
376,
21844,
198,
16341,
17267,
12331,
25,
198,
220,
220,
220,
5298,
17267,
12331,
7,
198,
220,
220,
220,
220,
220,
220,
220,
705,
2949,
8265,
3706,
17331,
22163,
70,
17,
13,
4222,
2721,
2035,
705,
198,
220,
220,
220,
220,
220,
220,
220,
705,
13764,
22163,
70,
17,
393,
17331,
22163,
70,
17,
12,
39491,
5301,
329,
16932,
7535,
705,
198,
220,
220,
220,
220,
220,
220,
220,
705,
273,
17331,
22163,
70,
17,
66,
487,
72,
329,
350,
4464,
88,
2637,
198,
220,
220,
220,
1267,
198,
198,
1640,
5301,
287,
37250,
13764,
22163,
70,
17,
3256,
705,
13764,
22163,
70,
17,
12,
39491,
3256,
705,
13764,
22163,
70,
17,
66,
487,
72,
6,
5974,
198,
220,
220,
220,
1949,
25,
198,
220,
220,
220,
220,
220,
220,
220,
611,
651,
62,
17080,
3890,
7,
26495,
737,
79,
945,
276,
62,
9641,
1279,
21136,
62,
9641,
10786,
17,
13,
20,
6,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
5298,
17267,
12331,
10786,
44046,
2672,
2196,
329,
17331,
22163,
70,
17,
318,
362,
13,
20,
11537,
198,
220,
220,
220,
220,
220,
220,
220,
2270,
198,
220,
220,
220,
2845,
27484,
3673,
21077,
25,
198,
220,
220,
220,
220,
220,
220,
220,
1208,
198,
198,
834,
9641,
834,
796,
651,
62,
17080,
3890,
10786,
11994,
12,
25410,
282,
26599,
12,
445,
30846,
27691,
9641,
198,
198,
6738,
44161,
282,
26599,
13,
38969,
478,
82,
1330,
20478,
198,
198,
2301,
4592,
13,
30238,
7203,
445,
30846,
1600,
366,
25410,
282,
26599,
62,
445,
30846,
13,
38969,
478,
1600,
366,
7738,
30846,
24400,
478,
4943,
198,
2301,
4592,
13,
30238,
7,
198,
220,
220,
220,
366,
445,
30846,
13,
13764,
22163,
70,
17,
1600,
366,
25410,
282,
26599,
62,
445,
30846,
13,
38969,
478,
1600,
366,
7738,
30846,
24400,
478,
1,
198,
8,
198
] | 2.594203 | 345 |
# -*- coding: utf-8 -*-
| [
2,
532,
9,
12,
19617,
25,
3384,
69,
12,
23,
532,
9,
12,
198
] | 1.714286 | 14 |
"""
This module contains the top level API for managing the project/file templates.
"""
import json
import logging
import os
import re
from binaryornot.check import is_binary
from hackedit.app import settings
def create(template, dest_dir, answers):
"""
Creates a file/project from the specified template, at the specified directory.
:param template: Template data.
:param dest_dir: Destination directory where to create the file/project
:param answers: Dict of answers for substitution variables
"""
ret_val = []
if not os.path.exists(dest_dir):
os.makedirs(dest_dir)
src_dir = template['path']
for root, dirs, files in os.walk(src_dir):
for file in files:
if file == 'template.json' or file.endswith('.pyc'):
continue
src, dst = get_paths(root, file, src_dir, dest_dir)
dst = subsitute_vars(dst)
encoding = get_file_encoding(src)
try:
content = open_file(src, encoding)
except OSError:
_logger().exception('failed to open file: %r', src)
if encoding != 'binary':
content = subsitute_vars(content)
if file == 'btpad_btn_img_0.png':
print(len(content), encoding)
try:
open_file(dst, encoding, to_write=content)
except PermissionError:
_logger().exception('failed to write file: %r', dst)
else:
ret_val.append(dst)
assert open_file(dst, encoding) == content
for directory in dirs:
src, dst = get_paths(root, directory, src_dir, dest_dir)
dst = subsitute_vars(dst)
try:
os.mkdir(dst)
except PermissionError:
_logger().exception('failed to create directory: %r', dst)
return ret_val
def get_sources():
"""
Returns the template sources (directory associated with a label).
"""
s = settings.load()
tmpl_sources = s.value('_templates/sources', '[]')
tmpl_sources = json.loads(tmpl_sources)
return sorted(tmpl_sources, key=lambda x: x['label'])
def add_source(label, path):
"""
Adds a template source
:param label: Name of the template source.
:param path: Path of the template source.
"""
tmpl_sources = get_sources()
tmpl_sources.append({'label': label, 'path': path})
s = settings.load()
s.setValue('_templates/sources', json.dumps(tmpl_sources))
def rm_source(label):
"""
Removes the specified template source.
:param label: Name of the template source to remove.
"""
tmpl_sources = get_sources()
for src in tmpl_sources:
if src['label'] == label:
tmpl_sources.remove(src)
s = settings.load()
s.setValue('_templates/sources', json.dumps(tmpl_sources))
def clear_sources():
"""
Clear template sources.
"""
s = settings.load()
s.setValue('_templates/sources', json.dumps([]))
def get_templates(category='', source_filter=''):
"""
Gets the list of templates.
:param category: Template category to retrieve.
- use "Project" to get project templates
- use "File" to get file templates
- use an empty string to retrieve them all (default).
:param source: Label of the source of the templates to retrieve. Use an empty string to retrieve
templates from all sources.
"""
def filtered_sources():
"""
Filter list of sources based on the ``source`` parameter.
"""
tmpl_sources = get_sources()
filtered = []
if source_filter:
# only keep the requested template source
for src in tmpl_sources:
if src['label'] == source_filter:
filtered.append(src)
break
else:
filtered = tmpl_sources
return filtered
def get_template(tdir):
"""
Returns template data for the given template directory.
Returns None if the template is invalid.
:param tdir: Template directory to get data from.
"""
tmpl = None
template_json = os.path.join(tdir, 'template.json')
if not os.path.exists(template_json):
# no template.json -> invalid template
_logger().warn('"template.json" not found in template directory: %r', tdir)
else:
try:
with open(template_json) as f:
tmpl = json.loads(f.read())
except (OSError, json.JSONDecodeError):
# unreadable template.json -> invalid template
_logger().exception('failed to read %r', template_json)
tmpl = None
else:
try:
tmpl_cat = tmpl['category']
except KeyError:
# no metadata or no category in template.json -> invalid template
_logger().exception('failed to read category from template metadata, '
'incomplete template.json?')
tmpl = None
else:
# valid template (finally).
tmpl['source'] = src
if category and category != tmpl_cat:
_logger().debug('rejecting template directory: %r, invalid category', tdir)
tmpl = None
return tmpl
def listdir(directory):
"""
Securely list subdirectories of ``directory``.
Returns an empty list of an OSError occurred.
"""
try:
return os.listdir(directory)
except OSError:
return []
for src in filtered_sources():
for tdir in listdir(src['path']):
tdir = os.path.join(src['path'], tdir)
if os.path.isfile(tdir):
continue
tmpl = get_template(tdir)
if tmpl:
tmpl['path'] = tdir
yield tmpl
def get_template(source, template):
"""
Returns the specified template data.
"""
for t in get_templates(source_filter=source):
if t['name'] == template:
return t
return None
if __name__ == '__main__':
clear_sources()
add_source('COBOL', '/home/colin/Documents/hackedit-cobol/hackedit_cobol/templates')
add_source('Python', '/home/colin/Documents/hackedit-python/hackedit_python/templates')
for tmpl in get_templates():
print(json.dumps(tmpl, indent=4, sort_keys=True))
| [
37811,
198,
1212,
8265,
4909,
262,
1353,
1241,
7824,
329,
11149,
262,
1628,
14,
7753,
24019,
13,
198,
37811,
198,
11748,
33918,
198,
11748,
18931,
198,
11748,
28686,
198,
11748,
302,
198,
198,
6738,
13934,
1211,
313,
13,
9122,
1330,
318,
62,
39491,
198,
198,
6738,
19957,
270,
13,
1324,
1330,
6460,
628,
198,
4299,
2251,
7,
28243,
11,
2244,
62,
15908,
11,
7429,
2599,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
7921,
274,
257,
2393,
14,
16302,
422,
262,
7368,
11055,
11,
379,
262,
7368,
8619,
13,
628,
220,
220,
220,
1058,
17143,
11055,
25,
37350,
1366,
13,
198,
220,
220,
220,
1058,
17143,
2244,
62,
15908,
25,
45657,
8619,
810,
284,
2251,
262,
2393,
14,
16302,
198,
220,
220,
220,
1058,
17143,
7429,
25,
360,
713,
286,
7429,
329,
32097,
9633,
198,
220,
220,
220,
37227,
628,
220,
220,
220,
1005,
62,
2100,
796,
17635,
628,
220,
220,
220,
611,
407,
28686,
13,
6978,
13,
1069,
1023,
7,
16520,
62,
15908,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
28686,
13,
76,
4335,
17062,
7,
16520,
62,
15908,
8,
198,
220,
220,
220,
12351,
62,
15908,
796,
11055,
17816,
6978,
20520,
198,
220,
220,
220,
329,
6808,
11,
288,
17062,
11,
3696,
287,
28686,
13,
11152,
7,
10677,
62,
15908,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
329,
2393,
287,
3696,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
611,
2393,
6624,
705,
28243,
13,
17752,
6,
393,
2393,
13,
437,
2032,
342,
7,
4458,
9078,
66,
6,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2555,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
12351,
11,
29636,
796,
651,
62,
6978,
82,
7,
15763,
11,
2393,
11,
12351,
62,
15908,
11,
2244,
62,
15908,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
29636,
796,
6352,
3678,
62,
85,
945,
7,
67,
301,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
21004,
796,
651,
62,
7753,
62,
12685,
7656,
7,
10677,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1949,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2695,
796,
1280,
62,
7753,
7,
10677,
11,
21004,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2845,
440,
5188,
81,
1472,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
4808,
6404,
1362,
22446,
1069,
4516,
10786,
47904,
284,
1280,
2393,
25,
4064,
81,
3256,
12351,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
611,
21004,
14512,
705,
39491,
10354,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2695,
796,
6352,
3678,
62,
85,
945,
7,
11299,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
611,
2393,
6624,
705,
18347,
15636,
62,
46118,
62,
9600,
62,
15,
13,
11134,
10354,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
3601,
7,
11925,
7,
11299,
828,
21004,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1949,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1280,
62,
7753,
7,
67,
301,
11,
21004,
11,
284,
62,
13564,
28,
11299,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2845,
2448,
3411,
12331,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
4808,
6404,
1362,
22446,
1069,
4516,
10786,
47904,
284,
3551,
2393,
25,
4064,
81,
3256,
29636,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2073,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1005,
62,
2100,
13,
33295,
7,
67,
301,
8,
628,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
6818,
1280,
62,
7753,
7,
67,
301,
11,
21004,
8,
6624,
2695,
628,
220,
220,
220,
220,
220,
220,
220,
329,
8619,
287,
288,
17062,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
12351,
11,
29636,
796,
651,
62,
6978,
82,
7,
15763,
11,
8619,
11,
12351,
62,
15908,
11,
2244,
62,
15908,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
29636,
796,
6352,
3678,
62,
85,
945,
7,
67,
301,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1949,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
28686,
13,
28015,
15908,
7,
67,
301,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2845,
2448,
3411,
12331,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
4808,
6404,
1362,
22446,
1069,
4516,
10786,
47904,
284,
2251,
8619,
25,
4064,
81,
3256,
29636,
8,
198,
220,
220,
220,
1441,
1005,
62,
2100,
628,
198,
4299,
651,
62,
82,
2203,
33529,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
16409,
262,
11055,
4237,
357,
34945,
3917,
351,
257,
6167,
737,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
264,
796,
6460,
13,
2220,
3419,
198,
220,
220,
220,
256,
76,
489,
62,
82,
2203,
796,
264,
13,
8367,
10786,
62,
11498,
17041,
14,
82,
2203,
3256,
705,
21737,
11537,
198,
220,
220,
220,
256,
76,
489,
62,
82,
2203,
796,
33918,
13,
46030,
7,
17209,
489,
62,
82,
2203,
8,
198,
220,
220,
220,
1441,
23243,
7,
17209,
489,
62,
82,
2203,
11,
1994,
28,
50033,
2124,
25,
2124,
17816,
18242,
6,
12962,
628,
198,
4299,
751,
62,
10459,
7,
18242,
11,
3108,
2599,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
34333,
257,
11055,
2723,
628,
220,
220,
220,
1058,
17143,
6167,
25,
6530,
286,
262,
11055,
2723,
13,
198,
220,
220,
220,
1058,
17143,
3108,
25,
10644,
286,
262,
11055,
2723,
13,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
256,
76,
489,
62,
82,
2203,
796,
651,
62,
82,
2203,
3419,
198,
220,
220,
220,
256,
76,
489,
62,
82,
2203,
13,
33295,
15090,
6,
18242,
10354,
6167,
11,
705,
6978,
10354,
3108,
30072,
198,
220,
220,
220,
264,
796,
6460,
13,
2220,
3419,
198,
220,
220,
220,
264,
13,
2617,
11395,
10786,
62,
11498,
17041,
14,
82,
2203,
3256,
33918,
13,
67,
8142,
7,
17209,
489,
62,
82,
2203,
4008,
628,
198,
4299,
42721,
62,
10459,
7,
18242,
2599,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
3982,
5241,
262,
7368,
11055,
2723,
13,
628,
220,
220,
220,
1058,
17143,
6167,
25,
6530,
286,
262,
11055,
2723,
284,
4781,
13,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
256,
76,
489,
62,
82,
2203,
796,
651,
62,
82,
2203,
3419,
198,
220,
220,
220,
329,
12351,
287,
256,
76,
489,
62,
82,
2203,
25,
198,
220,
220,
220,
220,
220,
220,
220,
611,
12351,
17816,
18242,
20520,
6624,
6167,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
256,
76,
489,
62,
82,
2203,
13,
28956,
7,
10677,
8,
198,
220,
220,
220,
264,
796,
6460,
13,
2220,
3419,
198,
220,
220,
220,
264,
13,
2617,
11395,
10786,
62,
11498,
17041,
14,
82,
2203,
3256,
33918,
13,
67,
8142,
7,
17209,
489,
62,
82,
2203,
4008,
628,
198,
4299,
1598,
62,
82,
2203,
33529,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
11459,
11055,
4237,
13,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
264,
796,
6460,
13,
2220,
3419,
198,
220,
220,
220,
264,
13,
2617,
11395,
10786,
62,
11498,
17041,
14,
82,
2203,
3256,
33918,
13,
67,
8142,
7,
21737,
4008,
628,
198,
4299,
651,
62,
11498,
17041,
7,
22872,
11639,
3256,
2723,
62,
24455,
28,
7061,
2599,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
29620,
262,
1351,
286,
24019,
13,
628,
220,
220,
220,
1058,
17143,
6536,
25,
37350,
6536,
284,
19818,
13,
198,
220,
220,
220,
220,
220,
220,
220,
532,
779,
366,
16775,
1,
284,
651,
1628,
24019,
198,
220,
220,
220,
220,
220,
220,
220,
532,
779,
366,
8979,
1,
284,
651,
2393,
24019,
198,
220,
220,
220,
220,
220,
220,
220,
532,
779,
281,
6565,
4731,
284,
19818,
606,
477,
357,
12286,
737,
628,
220,
220,
220,
1058,
17143,
2723,
25,
36052,
286,
262,
2723,
286,
262,
24019,
284,
19818,
13,
5765,
281,
6565,
4731,
284,
19818,
198,
220,
220,
220,
220,
220,
220,
220,
24019,
422,
477,
4237,
13,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
825,
29083,
62,
82,
2203,
33529,
198,
220,
220,
220,
220,
220,
220,
220,
37227,
198,
220,
220,
220,
220,
220,
220,
220,
25853,
1351,
286,
4237,
1912,
319,
262,
7559,
10459,
15506,
11507,
13,
198,
220,
220,
220,
220,
220,
220,
220,
37227,
198,
220,
220,
220,
220,
220,
220,
220,
256,
76,
489,
62,
82,
2203,
796,
651,
62,
82,
2203,
3419,
198,
220,
220,
220,
220,
220,
220,
220,
29083,
796,
17635,
198,
220,
220,
220,
220,
220,
220,
220,
611,
2723,
62,
24455,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1303,
691,
1394,
262,
9167,
11055,
2723,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
329,
12351,
287,
256,
76,
489,
62,
82,
2203,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
611,
12351,
17816,
18242,
20520,
6624,
2723,
62,
24455,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
29083,
13,
33295,
7,
10677,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2270,
198,
220,
220,
220,
220,
220,
220,
220,
2073,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
29083,
796,
256,
76,
489,
62,
82,
2203,
198,
220,
220,
220,
220,
220,
220,
220,
1441,
29083,
628,
220,
220,
220,
825,
651,
62,
28243,
7,
8671,
343,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
37227,
198,
220,
220,
220,
220,
220,
220,
220,
16409,
11055,
1366,
329,
262,
1813,
11055,
8619,
13,
628,
220,
220,
220,
220,
220,
220,
220,
16409,
6045,
611,
262,
11055,
318,
12515,
13,
628,
220,
220,
220,
220,
220,
220,
220,
1058,
17143,
256,
15908,
25,
37350,
8619,
284,
651,
1366,
422,
13,
198,
220,
220,
220,
220,
220,
220,
220,
37227,
198,
220,
220,
220,
220,
220,
220,
220,
256,
76,
489,
796,
6045,
198,
220,
220,
220,
220,
220,
220,
220,
11055,
62,
17752,
796,
28686,
13,
6978,
13,
22179,
7,
8671,
343,
11,
705,
28243,
13,
17752,
11537,
198,
220,
220,
220,
220,
220,
220,
220,
611,
407,
28686,
13,
6978,
13,
1069,
1023,
7,
28243,
62,
17752,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1303,
645,
11055,
13,
17752,
4613,
12515,
11055,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
4808,
6404,
1362,
22446,
40539,
10786,
1,
28243,
13,
17752,
1,
407,
1043,
287,
11055,
8619,
25,
4064,
81,
3256,
256,
15908,
8,
198,
220,
220,
220,
220,
220,
220,
220,
2073,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1949,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
351,
1280,
7,
28243,
62,
17752,
8,
355,
277,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
256,
76,
489,
796,
33918,
13,
46030,
7,
69,
13,
961,
28955,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2845,
357,
2640,
12331,
11,
33918,
13,
40386,
10707,
1098,
12331,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1303,
555,
46155,
11055,
13,
17752,
4613,
12515,
11055,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
4808,
6404,
1362,
22446,
1069,
4516,
10786,
47904,
284,
1100,
4064,
81,
3256,
11055,
62,
17752,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
256,
76,
489,
796,
6045,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2073,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1949,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
256,
76,
489,
62,
9246,
796,
256,
76,
489,
17816,
22872,
20520,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2845,
7383,
12331,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1303,
645,
20150,
393,
645,
6536,
287,
11055,
13,
17752,
4613,
12515,
11055,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
4808,
6404,
1362,
22446,
1069,
4516,
10786,
47904,
284,
1100,
6536,
422,
11055,
20150,
11,
705,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
705,
259,
20751,
11055,
13,
17752,
8348,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
256,
76,
489,
796,
6045,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2073,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1303,
4938,
11055,
357,
69,
3289,
737,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
256,
76,
489,
17816,
10459,
20520,
796,
12351,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
611,
6536,
290,
6536,
14512,
256,
76,
489,
62,
9246,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
4808,
6404,
1362,
22446,
24442,
10786,
260,
752,
278,
11055,
8619,
25,
4064,
81,
11,
12515,
6536,
3256,
256,
15908,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
256,
76,
489,
796,
6045,
198,
220,
220,
220,
220,
220,
220,
220,
1441,
256,
76,
489,
628,
220,
220,
220,
825,
1351,
15908,
7,
34945,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
37227,
198,
220,
220,
220,
220,
220,
220,
220,
26707,
306,
1351,
850,
12942,
1749,
286,
7559,
34945,
15506,
13,
628,
220,
220,
220,
220,
220,
220,
220,
16409,
281,
6565,
1351,
286,
281,
440,
5188,
81,
1472,
5091,
13,
198,
220,
220,
220,
220,
220,
220,
220,
37227,
198,
220,
220,
220,
220,
220,
220,
220,
1949,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1441,
28686,
13,
4868,
15908,
7,
34945,
8,
198,
220,
220,
220,
220,
220,
220,
220,
2845,
440,
5188,
81,
1472,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1441,
17635,
628,
220,
220,
220,
329,
12351,
287,
29083,
62,
82,
2203,
33529,
198,
220,
220,
220,
220,
220,
220,
220,
329,
256,
15908,
287,
1351,
15908,
7,
10677,
17816,
6978,
20520,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
256,
15908,
796,
28686,
13,
6978,
13,
22179,
7,
10677,
17816,
6978,
6,
4357,
256,
15908,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
611,
28686,
13,
6978,
13,
4468,
576,
7,
8671,
343,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2555,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
256,
76,
489,
796,
651,
62,
28243,
7,
8671,
343,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
611,
256,
76,
489,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
256,
76,
489,
17816,
6978,
20520,
796,
256,
15908,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
7800,
256,
76,
489,
628,
198,
4299,
651,
62,
28243,
7,
10459,
11,
11055,
2599,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
16409,
262,
7368,
11055,
1366,
13,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
329,
256,
287,
651,
62,
11498,
17041,
7,
10459,
62,
24455,
28,
10459,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
611,
256,
17816,
3672,
20520,
6624,
11055,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1441,
256,
198,
220,
220,
220,
1441,
6045,
628,
198,
198,
361,
11593,
3672,
834,
6624,
705,
834,
12417,
834,
10354,
198,
220,
220,
220,
1598,
62,
82,
2203,
3419,
198,
220,
220,
220,
751,
62,
10459,
10786,
8220,
33,
3535,
3256,
220,
31051,
11195,
14,
4033,
259,
14,
38354,
14,
71,
6021,
270,
12,
66,
672,
349,
14,
71,
6021,
270,
62,
66,
672,
349,
14,
11498,
17041,
11537,
198,
220,
220,
220,
751,
62,
10459,
10786,
37906,
3256,
31051,
11195,
14,
4033,
259,
14,
38354,
14,
71,
6021,
270,
12,
29412,
14,
71,
6021,
270,
62,
29412,
14,
11498,
17041,
11537,
198,
220,
220,
220,
329,
256,
76,
489,
287,
651,
62,
11498,
17041,
33529,
198,
220,
220,
220,
220,
220,
220,
220,
3601,
7,
17752,
13,
67,
8142,
7,
17209,
489,
11,
33793,
28,
19,
11,
3297,
62,
13083,
28,
17821,
4008,
198
] | 2.184029 | 3,043 |
"""
Convert video format x to MP4/H.264.
"""
import os
import sys
import logging
from .videometainfo import VideoMetaInfo
from .utils import sizeof_fmt, time_fmt, find_files, check_dependencies, call, ffmpeg
logger = logging.getLogger(__name__)
class VideoToMP4:
"""To Mp4"""
SUPPORTED_EXTENSIONS = ".wmv, .avi, .mkv, .mov, .flv"
RULES = {
".wmv": "-c:v libx264 -crf 19 ",
".avi":
"-vf yadif=1 -c:v h264_nvenc -preset slow -tune film -crf 17",
".mkv": "-c copy",
".mov": "-vcodec h264 -acodec aac -strict -2 -crf 19 ",
".flv": " -r 20 ",
}
def process(self, video_file: str):
"""Convert video files to MP4 container format."""
name = os.path.splitext(video_file)[0]
ext = os.path.splitext(video_file)[1]
new_name = f"{name}.mp4"
if os.path.exists(new_name):
logger.info(f"Skipping file {new_name} already exists!")
elif ext not in VideoToMP4.RULES:
logger.error(f"Skipping unsupported type {ext}!")
else:
print(f'Convert {ext} to MP4 {new_name} ... ')
meta_info = VideoMetaInfo(video_file)
rule = VideoToMP4.RULES[ext]
flags = "-movflags +faststart -pix_fmt yuv420p"
ffmpeg(
f'-i "{video_file}" {flags} {rule} -metadata date="{meta_info.original_date}" "{new_name}"'
)
| [
37811,
198,
3103,
1851,
2008,
5794,
2124,
284,
4904,
19,
14,
39,
13,
18897,
13,
198,
37811,
198,
198,
11748,
28686,
198,
11748,
25064,
198,
11748,
18931,
198,
198,
6738,
764,
85,
485,
908,
391,
6513,
1330,
7623,
48526,
12360,
198,
6738,
764,
26791,
1330,
39364,
62,
69,
16762,
11,
640,
62,
69,
16762,
11,
1064,
62,
16624,
11,
2198,
62,
45841,
3976,
11,
869,
11,
31246,
43913,
198,
198,
6404,
1362,
796,
18931,
13,
1136,
11187,
1362,
7,
834,
3672,
834,
8,
628,
198,
4871,
7623,
2514,
7378,
19,
25,
198,
220,
220,
220,
37227,
2514,
337,
79,
19,
37811,
198,
220,
220,
220,
43333,
1961,
62,
13918,
16938,
11053,
796,
27071,
26377,
85,
11,
764,
15820,
11,
764,
28015,
85,
11,
764,
76,
709,
11,
764,
2704,
85,
1,
198,
220,
220,
220,
371,
6239,
1546,
796,
1391,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
27071,
26377,
85,
1298,
27444,
66,
25,
85,
9195,
87,
18897,
532,
6098,
69,
678,
33172,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
27071,
15820,
1298,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
27444,
85,
69,
331,
324,
361,
28,
16,
532,
66,
25,
85,
289,
18897,
62,
77,
574,
66,
532,
18302,
316,
3105,
532,
83,
1726,
2646,
532,
6098,
69,
1596,
1600,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
27071,
28015,
85,
1298,
27444,
66,
4866,
1600,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
27071,
76,
709,
1298,
27444,
85,
19815,
721,
289,
18897,
532,
330,
375,
721,
257,
330,
532,
301,
2012,
532,
17,
532,
6098,
69,
678,
33172,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
27071,
2704,
85,
1298,
366,
532,
81,
1160,
33172,
198,
220,
220,
220,
220,
220,
220,
220,
1782,
628,
220,
220,
220,
825,
1429,
7,
944,
11,
2008,
62,
7753,
25,
965,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
37227,
3103,
1851,
2008,
3696,
284,
4904,
19,
9290,
5794,
526,
15931,
628,
220,
220,
220,
220,
220,
220,
220,
1438,
796,
28686,
13,
6978,
13,
22018,
578,
742,
7,
15588,
62,
7753,
38381,
15,
60,
198,
220,
220,
220,
220,
220,
220,
220,
1070,
796,
28686,
13,
6978,
13,
22018,
578,
742,
7,
15588,
62,
7753,
38381,
16,
60,
198,
220,
220,
220,
220,
220,
220,
220,
649,
62,
3672,
796,
277,
1,
90,
3672,
27422,
3149,
19,
1,
198,
220,
220,
220,
220,
220,
220,
220,
611,
28686,
13,
6978,
13,
1069,
1023,
7,
3605,
62,
3672,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
49706,
13,
10951,
7,
69,
1,
50,
4106,
2105,
2393,
1391,
3605,
62,
3672,
92,
1541,
7160,
2474,
8,
198,
220,
220,
220,
220,
220,
220,
220,
1288,
361,
1070,
407,
287,
7623,
2514,
7378,
19,
13,
49,
6239,
1546,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
49706,
13,
18224,
7,
69,
1,
50,
4106,
2105,
24222,
2099,
1391,
2302,
92,
2474,
8,
198,
220,
220,
220,
220,
220,
220,
220,
2073,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
3601,
7,
69,
6,
3103,
1851,
1391,
2302,
92,
284,
4904,
19,
1391,
3605,
62,
3672,
92,
2644,
705,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
13634,
62,
10951,
796,
7623,
48526,
12360,
7,
15588,
62,
7753,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
3896,
796,
7623,
2514,
7378,
19,
13,
49,
6239,
1546,
58,
2302,
60,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
9701,
796,
27444,
76,
709,
33152,
1343,
7217,
9688,
532,
79,
844,
62,
69,
16762,
331,
14795,
27211,
79,
1,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
31246,
43913,
7,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
277,
29001,
72,
45144,
15588,
62,
7753,
36786,
1391,
33152,
92,
1391,
25135,
92,
532,
38993,
3128,
2625,
90,
28961,
62,
10951,
13,
14986,
62,
4475,
36786,
45144,
3605,
62,
3672,
92,
30543,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1267,
198
] | 2.002782 | 719 |
from setuptools import setup
setup(
name='parasol',
dependency_links=[
],
install_requires=[
]
)
| [
6738,
900,
37623,
10141,
1330,
9058,
198,
40406,
7,
198,
220,
220,
220,
1438,
11639,
1845,
292,
349,
3256,
198,
220,
220,
220,
20203,
62,
28751,
41888,
198,
220,
220,
220,
16589,
198,
220,
220,
220,
2721,
62,
47911,
41888,
198,
220,
220,
220,
2361,
198,
8,
198
] | 2.4375 | 48 |
# Generated by Django 3.2.8 on 2021-11-02 12:46
from django.db import migrations, models
| [
2,
2980,
515,
416,
37770,
513,
13,
17,
13,
23,
319,
33448,
12,
1157,
12,
2999,
1105,
25,
3510,
198,
198,
6738,
42625,
14208,
13,
9945,
1330,
15720,
602,
11,
4981,
628
] | 2.84375 | 32 |
import csv
import io
import json
import logging
import os
import warnings
from collections import defaultdict
from ..utils.exceptions import OasisException
from ..utils.log import oasis_log
from .files import GENERAL_SETTINGS_FILE, GUL_SUMMARIES_FILE, IL_SUMMARIES_FILE, MODEL_SETTINGS_FILE
def _get_summaries(summary_file):
"""
Get a list representation of a summary file.
"""
summaries_dict = defaultdict(lambda: {'leccalc': {}})
with io.open(summary_file, 'r', encoding='utf-8') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
id = int(row[0])
if row[1].startswith('leccalc'):
summaries_dict[id]['leccalc'][row[1]] = row[2].lower() == 'true'
else:
summaries_dict[id][row[1]] = row[2].lower() == 'true'
summaries = list()
for id in sorted(summaries_dict):
summaries_dict[id]['id'] = id
summaries.append(summaries_dict[id])
return summaries
@oasis_log
def create_analysis_settings_json(directory):
"""
Generate an analysis settings JSON from a set of
CSV files in a specified directory.
Args:
``directory`` (string): the directory containing the CSV files.
Returns:
The analysis settings JSON.
"""
if not os.path.exists(directory):
error_message = "Directory does not exist: {}".format(directory)
logging.getLogger().error(error_message)
raise OasisException(error_message)
general_settings_file = os.path.join(directory, GENERAL_SETTINGS_FILE)
model_settings_file = os.path.join(directory, MODEL_SETTINGS_FILE)
gul_summaries_file = os.path.join(directory, GUL_SUMMARIES_FILE)
il_summaries_file = os.path.join(directory, IL_SUMMARIES_FILE)
for file in [general_settings_file, model_settings_file, gul_summaries_file, il_summaries_file]:
if not os.path.exists(file):
error_message = "File does not exist: {}".format(directory)
logging.getLogger().error(error_message)
raise OasisException(error_message)
general_settings = dict()
with io.open(general_settings_file, 'r', encoding='utf-8') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
general_settings[row[0]] = eval("{}('{}')".format(row[2], row[1]))
model_settings = dict()
with io.open(model_settings_file, 'r', encoding='utf-8') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
model_settings[row[0]] = eval("{}('{}')".format(row[2], row[1]))
gul_summaries = _get_summaries(gul_summaries_file)
il_summaries = _get_summaries(il_summaries_file)
analysis_settings = general_settings
analysis_settings['model_settings'] = model_settings
analysis_settings['gul_summaries'] = gul_summaries
analysis_settings['il_summaries'] = il_summaries
output_json = json.dumps(analysis_settings)
logging.getLogger().info("Analysis settings json: {}".format(output_json))
return output_json
def read_analysis_settings(analysis_settings_fp, il_files_exist=False,
ri_files_exist=False):
"""Read the analysis settings file"""
# Load analysis_settings file
try:
# Load as a json
with io.open(analysis_settings_fp, 'r', encoding='utf-8') as f:
analysis_settings = json.load(f)
# Extract the analysis_settings part within the json
if analysis_settings.get('analysis_settings'):
analysis_settings = analysis_settings['analysis_settings']
except (IOError, TypeError, ValueError):
raise OasisException('Invalid analysis settings file or file path: {}.'.format(
analysis_settings_fp))
# Reset il_output if the files are not there
if not il_files_exist or 'il_output' not in analysis_settings:
# No insured loss output
analysis_settings['il_output'] = False
analysis_settings['il_summaries'] = []
# Same for ri_output
if not ri_files_exist or 'ri_output' not in analysis_settings:
# No reinsured loss output
analysis_settings['ri_output'] = False
analysis_settings['ri_summaries'] = []
# If we want ri_output, we will need il_output, which needs il_files
if analysis_settings['ri_output'] and not analysis_settings['il_output']:
if not il_files_exist:
warnings.warn("ri_output selected, but il files not found")
analysis_settings['ri_output'] = False
analysis_settings['ri_summaries'] = []
else:
analysis_settings['il_output'] = True
# guard - Check if at least one output type is selected
if not any([
analysis_settings['gul_output'] if 'gul_output' in analysis_settings else False,
analysis_settings['il_output'] if 'il_output' in analysis_settings else False,
analysis_settings['ri_output'] if 'ri_output' in analysis_settings else False,
]):
raise OasisException(
'No valid output settings in: {}'.format(analysis_settings_fp))
return analysis_settings
| [
11748,
269,
21370,
198,
11748,
33245,
198,
11748,
33918,
198,
11748,
18931,
198,
11748,
28686,
198,
11748,
14601,
198,
198,
6738,
17268,
1330,
4277,
11600,
198,
198,
6738,
11485,
26791,
13,
1069,
11755,
1330,
440,
17765,
16922,
198,
6738,
11485,
26791,
13,
6404,
1330,
267,
17765,
62,
6404,
198,
6738,
764,
16624,
1330,
41877,
62,
28480,
51,
20754,
62,
25664,
11,
402,
6239,
62,
50,
5883,
40569,
11015,
62,
25664,
11,
14639,
62,
50,
5883,
40569,
11015,
62,
25664,
11,
19164,
3698,
62,
28480,
51,
20754,
62,
25664,
628,
198,
4299,
4808,
1136,
62,
82,
13929,
3166,
7,
49736,
62,
7753,
2599,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
3497,
257,
1351,
10552,
286,
257,
10638,
2393,
13,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
30114,
3166,
62,
11600,
796,
4277,
11600,
7,
50033,
25,
1391,
6,
293,
535,
282,
66,
10354,
1391,
11709,
8,
628,
220,
220,
220,
351,
33245,
13,
9654,
7,
49736,
62,
7753,
11,
705,
81,
3256,
21004,
11639,
40477,
12,
23,
11537,
355,
269,
21370,
7753,
25,
198,
220,
220,
220,
220,
220,
220,
220,
9173,
796,
269,
21370,
13,
46862,
7,
40664,
7753,
8,
198,
220,
220,
220,
220,
220,
220,
220,
329,
5752,
287,
9173,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
4686,
796,
493,
7,
808,
58,
15,
12962,
628,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
611,
5752,
58,
16,
4083,
9688,
2032,
342,
10786,
293,
535,
282,
66,
6,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
30114,
3166,
62,
11600,
58,
312,
7131,
6,
293,
535,
282,
66,
6,
7131,
808,
58,
16,
11907,
796,
5752,
58,
17,
4083,
21037,
3419,
6624,
705,
7942,
6,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2073,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
30114,
3166,
62,
11600,
58,
312,
7131,
808,
58,
16,
11907,
796,
5752,
58,
17,
4083,
21037,
3419,
6624,
705,
7942,
6,
628,
220,
220,
220,
30114,
3166,
796,
1351,
3419,
198,
220,
220,
220,
329,
4686,
287,
23243,
7,
82,
13929,
3166,
62,
11600,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
30114,
3166,
62,
11600,
58,
312,
7131,
6,
312,
20520,
796,
4686,
198,
220,
220,
220,
220,
220,
220,
220,
30114,
3166,
13,
33295,
7,
82,
13929,
3166,
62,
11600,
58,
312,
12962,
628,
220,
220,
220,
1441,
30114,
3166,
628,
198,
31,
78,
17765,
62,
6404,
198,
4299,
2251,
62,
20930,
62,
33692,
62,
17752,
7,
34945,
2599,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
2980,
378,
281,
3781,
6460,
19449,
422,
257,
900,
286,
198,
220,
220,
220,
44189,
3696,
287,
257,
7368,
8619,
13,
198,
220,
220,
220,
943,
14542,
25,
198,
220,
220,
220,
220,
220,
220,
220,
7559,
34945,
15506,
357,
8841,
2599,
262,
8619,
7268,
262,
44189,
3696,
13,
198,
220,
220,
220,
16409,
25,
198,
220,
220,
220,
220,
220,
220,
220,
383,
3781,
6460,
19449,
13,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
611,
407,
28686,
13,
6978,
13,
1069,
1023,
7,
34945,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
4049,
62,
20500,
796,
366,
43055,
857,
407,
2152,
25,
23884,
1911,
18982,
7,
34945,
8,
198,
220,
220,
220,
220,
220,
220,
220,
18931,
13,
1136,
11187,
1362,
22446,
18224,
7,
18224,
62,
20500,
8,
198,
220,
220,
220,
220,
220,
220,
220,
5298,
440,
17765,
16922,
7,
18224,
62,
20500,
8,
628,
220,
220,
220,
2276,
62,
33692,
62,
7753,
796,
28686,
13,
6978,
13,
22179,
7,
34945,
11,
41877,
62,
28480,
51,
20754,
62,
25664,
8,
198,
220,
220,
220,
2746,
62,
33692,
62,
7753,
796,
28686,
13,
6978,
13,
22179,
7,
34945,
11,
19164,
3698,
62,
28480,
51,
20754,
62,
25664,
8,
198,
220,
220,
220,
47161,
62,
82,
13929,
3166,
62,
7753,
796,
28686,
13,
6978,
13,
22179,
7,
34945,
11,
402,
6239,
62,
50,
5883,
40569,
11015,
62,
25664,
8,
198,
220,
220,
220,
4229,
62,
82,
13929,
3166,
62,
7753,
796,
28686,
13,
6978,
13,
22179,
7,
34945,
11,
14639,
62,
50,
5883,
40569,
11015,
62,
25664,
8,
628,
220,
220,
220,
329,
2393,
287,
685,
24622,
62,
33692,
62,
7753,
11,
2746,
62,
33692,
62,
7753,
11,
47161,
62,
82,
13929,
3166,
62,
7753,
11,
4229,
62,
82,
13929,
3166,
62,
7753,
5974,
198,
220,
220,
220,
220,
220,
220,
220,
611,
407,
28686,
13,
6978,
13,
1069,
1023,
7,
7753,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
4049,
62,
20500,
796,
366,
8979,
857,
407,
2152,
25,
23884,
1911,
18982,
7,
34945,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
18931,
13,
1136,
11187,
1362,
22446,
18224,
7,
18224,
62,
20500,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
5298,
440,
17765,
16922,
7,
18224,
62,
20500,
8,
628,
220,
220,
220,
2276,
62,
33692,
796,
8633,
3419,
198,
220,
220,
220,
351,
33245,
13,
9654,
7,
24622,
62,
33692,
62,
7753,
11,
705,
81,
3256,
21004,
11639,
40477,
12,
23,
11537,
355,
269,
21370,
7753,
25,
198,
220,
220,
220,
220,
220,
220,
220,
9173,
796,
269,
21370,
13,
46862,
7,
40664,
7753,
8,
198,
220,
220,
220,
220,
220,
220,
220,
329,
5752,
287,
9173,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2276,
62,
33692,
58,
808,
58,
15,
11907,
796,
5418,
7203,
90,
92,
10786,
90,
92,
11537,
1911,
18982,
7,
808,
58,
17,
4357,
5752,
58,
16,
60,
4008,
628,
220,
220,
220,
2746,
62,
33692,
796,
8633,
3419,
198,
220,
220,
220,
351,
33245,
13,
9654,
7,
19849,
62,
33692,
62,
7753,
11,
705,
81,
3256,
21004,
11639,
40477,
12,
23,
11537,
355,
269,
21370,
7753,
25,
198,
220,
220,
220,
220,
220,
220,
220,
9173,
796,
269,
21370,
13,
46862,
7,
40664,
7753,
8,
198,
220,
220,
220,
220,
220,
220,
220,
329,
5752,
287,
9173,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2746,
62,
33692,
58,
808,
58,
15,
11907,
796,
5418,
7203,
90,
92,
10786,
90,
92,
11537,
1911,
18982,
7,
808,
58,
17,
4357,
5752,
58,
16,
60,
4008,
628,
220,
220,
220,
47161,
62,
82,
13929,
3166,
796,
4808,
1136,
62,
82,
13929,
3166,
7,
70,
377,
62,
82,
13929,
3166,
62,
7753,
8,
198,
220,
220,
220,
4229,
62,
82,
13929,
3166,
796,
4808,
1136,
62,
82,
13929,
3166,
7,
346,
62,
82,
13929,
3166,
62,
7753,
8,
628,
220,
220,
220,
3781,
62,
33692,
796,
2276,
62,
33692,
198,
220,
220,
220,
3781,
62,
33692,
17816,
19849,
62,
33692,
20520,
796,
2746,
62,
33692,
198,
220,
220,
220,
3781,
62,
33692,
17816,
70,
377,
62,
82,
13929,
3166,
20520,
796,
47161,
62,
82,
13929,
3166,
198,
220,
220,
220,
3781,
62,
33692,
17816,
346,
62,
82,
13929,
3166,
20520,
796,
4229,
62,
82,
13929,
3166,
198,
220,
220,
220,
5072,
62,
17752,
796,
33918,
13,
67,
8142,
7,
20930,
62,
33692,
8,
198,
220,
220,
220,
18931,
13,
1136,
11187,
1362,
22446,
10951,
7203,
32750,
6460,
33918,
25,
23884,
1911,
18982,
7,
22915,
62,
17752,
4008,
628,
220,
220,
220,
1441,
5072,
62,
17752,
628,
198,
4299,
1100,
62,
20930,
62,
33692,
7,
20930,
62,
33692,
62,
46428,
11,
4229,
62,
16624,
62,
38476,
28,
25101,
11,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
374,
72,
62,
16624,
62,
38476,
28,
25101,
2599,
198,
220,
220,
220,
37227,
5569,
262,
3781,
6460,
2393,
37811,
628,
198,
220,
220,
220,
1303,
8778,
3781,
62,
33692,
2393,
198,
220,
220,
220,
1949,
25,
198,
220,
220,
220,
220,
220,
220,
220,
1303,
8778,
355,
257,
33918,
198,
220,
220,
220,
220,
220,
220,
220,
351,
33245,
13,
9654,
7,
20930,
62,
33692,
62,
46428,
11,
705,
81,
3256,
21004,
11639,
40477,
12,
23,
11537,
355,
277,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
3781,
62,
33692,
796,
33918,
13,
2220,
7,
69,
8,
628,
220,
220,
220,
220,
220,
220,
220,
1303,
29677,
262,
3781,
62,
33692,
636,
1626,
262,
33918,
198,
220,
220,
220,
220,
220,
220,
220,
611,
3781,
62,
33692,
13,
1136,
10786,
20930,
62,
33692,
6,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
3781,
62,
33692,
796,
3781,
62,
33692,
17816,
20930,
62,
33692,
20520,
628,
220,
220,
220,
2845,
357,
9399,
12331,
11,
5994,
12331,
11,
11052,
12331,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
5298,
440,
17765,
16922,
10786,
44651,
3781,
6460,
2393,
393,
2393,
3108,
25,
23884,
2637,
13,
18982,
7,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
3781,
62,
33692,
62,
46428,
4008,
628,
220,
220,
220,
1303,
30027,
4229,
62,
22915,
611,
262,
3696,
389,
407,
612,
198,
220,
220,
220,
611,
407,
4229,
62,
16624,
62,
38476,
393,
705,
346,
62,
22915,
6,
407,
287,
3781,
62,
33692,
25,
198,
220,
220,
220,
220,
220,
220,
220,
1303,
1400,
31977,
2994,
5072,
198,
220,
220,
220,
220,
220,
220,
220,
3781,
62,
33692,
17816,
346,
62,
22915,
20520,
796,
10352,
198,
220,
220,
220,
220,
220,
220,
220,
3781,
62,
33692,
17816,
346,
62,
82,
13929,
3166,
20520,
796,
17635,
628,
220,
220,
220,
1303,
16766,
329,
374,
72,
62,
22915,
198,
220,
220,
220,
611,
407,
374,
72,
62,
16624,
62,
38476,
393,
705,
380,
62,
22915,
6,
407,
287,
3781,
62,
33692,
25,
198,
220,
220,
220,
220,
220,
220,
220,
1303,
1400,
302,
28409,
2994,
5072,
198,
220,
220,
220,
220,
220,
220,
220,
3781,
62,
33692,
17816,
380,
62,
22915,
20520,
796,
10352,
198,
220,
220,
220,
220,
220,
220,
220,
3781,
62,
33692,
17816,
380,
62,
82,
13929,
3166,
20520,
796,
17635,
628,
220,
220,
220,
1303,
1002,
356,
765,
374,
72,
62,
22915,
11,
356,
481,
761,
4229,
62,
22915,
11,
543,
2476,
4229,
62,
16624,
198,
220,
220,
220,
611,
3781,
62,
33692,
17816,
380,
62,
22915,
20520,
290,
407,
3781,
62,
33692,
17816,
346,
62,
22915,
6,
5974,
198,
220,
220,
220,
220,
220,
220,
220,
611,
407,
4229,
62,
16624,
62,
38476,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
14601,
13,
40539,
7203,
380,
62,
22915,
6163,
11,
475,
4229,
3696,
407,
1043,
4943,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
3781,
62,
33692,
17816,
380,
62,
22915,
20520,
796,
10352,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
3781,
62,
33692,
17816,
380,
62,
82,
13929,
3166,
20520,
796,
17635,
198,
220,
220,
220,
220,
220,
220,
220,
2073,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
3781,
62,
33692,
17816,
346,
62,
22915,
20520,
796,
6407,
628,
220,
220,
220,
1303,
4860,
532,
6822,
611,
379,
1551,
530,
5072,
2099,
318,
6163,
198,
220,
220,
220,
611,
407,
597,
26933,
198,
220,
220,
220,
220,
220,
220,
220,
3781,
62,
33692,
17816,
70,
377,
62,
22915,
20520,
611,
705,
70,
377,
62,
22915,
6,
287,
3781,
62,
33692,
2073,
10352,
11,
198,
220,
220,
220,
220,
220,
220,
220,
3781,
62,
33692,
17816,
346,
62,
22915,
20520,
611,
705,
346,
62,
22915,
6,
287,
3781,
62,
33692,
2073,
10352,
11,
198,
220,
220,
220,
220,
220,
220,
220,
3781,
62,
33692,
17816,
380,
62,
22915,
20520,
611,
705,
380,
62,
22915,
6,
287,
3781,
62,
33692,
2073,
10352,
11,
198,
220,
220,
220,
2361,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
5298,
440,
17765,
16922,
7,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
705,
2949,
4938,
5072,
6460,
287,
25,
23884,
4458,
18982,
7,
20930,
62,
33692,
62,
46428,
4008,
628,
220,
220,
220,
1441,
3781,
62,
33692,
198
] | 2.540594 | 2,020 |
#!/usr/bin/env python
#--------------------------------------------------------------------------------
#Changes the sky coordinates (x,y,z) to the disk coordinates (x_d,y_d,z_d)
#The x axis is the rotation axis
#--------------------------------------------------------------------------------
#Radiative transfer equation
#--------------------------------------------------------------------------------
#Optical depth
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
#Black body radiation
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
#Lee las tablas de opacidad DSHARP
#Load opacities
with np.load('default_opacities_smooth.npz') as d:
a_w = d['a']
gsca_w = d['g']
lam_w = d['lam']
k_abs_w = d['k_abs']
k_sca_w = d['k_sca']
lam_avgs = wl
# We split the opacities within the range of frequency to make the calculations faster
k_abs_w = k_abs_w[(0.9*lam_avgs<lam_w) & (1.1*lam_avgs>lam_w),:]
k_sca_w = k_sca_w[(0.9*lam_avgs<lam_w) & (1.1*lam_avgs>lam_w),:]
k_sca_w = k_sca_w*(1. - gsca_w[(0.9*lam_avgs<lam_w) & (1.1*lam_avgs>lam_w),:])
lam_w = lam_w[(0.9*lam_avgs<lam_w) & (1.1*lam_avgs>lam_w)]
opac_grid = opacity.size_average_opacity(lam_avgs, a_w, lam_w, k_abs_w.T, k_sca_w.T, q=3.5, plot=True)
function_ext = interpolate.interp1d(a_w, opac_grid['ka'][:]+opac_grid['ks'][:],kind='cubic')
function_alb = interpolate.interp1d(a_w, opac_grid['ks'][:]/(opac_grid['ka'][:]+opac_grid['ks'][:]),kind='cubic')
if not scattering:
function_alb = interpolate.interp1d(a_w, np.zeros((np.shape(opac_grid['ks'][:]))),kind='cubic')
| [
2,
48443,
14629,
14,
8800,
14,
24330,
21015,
198,
198,
2,
10097,
1783,
198,
2,
29238,
262,
6766,
22715,
357,
87,
11,
88,
11,
89,
8,
284,
262,
11898,
22715,
357,
87,
62,
67,
11,
88,
62,
67,
11,
89,
62,
67,
8,
198,
2,
464,
2124,
16488,
318,
262,
13179,
16488,
198,
198,
2,
10097,
1783,
198,
2,
49,
9189,
876,
4351,
16022,
198,
198,
2,
10097,
1783,
198,
2,
27871,
605,
6795,
198,
198,
2,
10097,
1783,
198,
198,
2,
10097,
1783,
198,
2,
9915,
1767,
11881,
198,
198,
2,
10097,
1783,
198,
198,
2,
10097,
1783,
198,
198,
2,
10097,
1783,
198,
198,
2,
10097,
1783,
198,
2,
24338,
39990,
7400,
21921,
390,
1034,
330,
32482,
360,
9693,
36035,
198,
2,
8912,
1034,
330,
871,
198,
4480,
45941,
13,
2220,
10786,
12286,
62,
404,
330,
871,
62,
5796,
5226,
13,
37659,
89,
11537,
355,
288,
25,
198,
220,
220,
220,
257,
62,
86,
220,
220,
220,
220,
796,
288,
17816,
64,
20520,
198,
220,
220,
220,
308,
1416,
64,
62,
86,
220,
796,
288,
17816,
70,
20520,
198,
220,
220,
220,
30592,
62,
86,
220,
220,
796,
288,
17816,
2543,
20520,
198,
220,
220,
220,
479,
62,
8937,
62,
86,
796,
288,
17816,
74,
62,
8937,
20520,
198,
220,
220,
220,
479,
62,
1416,
64,
62,
86,
796,
288,
17816,
74,
62,
1416,
64,
20520,
198,
198,
2543,
62,
615,
14542,
796,
266,
75,
198,
2,
775,
6626,
262,
1034,
330,
871,
1626,
262,
2837,
286,
8373,
284,
787,
262,
16765,
5443,
198,
74,
62,
8937,
62,
86,
796,
479,
62,
8937,
62,
86,
58,
7,
15,
13,
24,
9,
2543,
62,
615,
14542,
27,
2543,
62,
86,
8,
1222,
357,
16,
13,
16,
9,
2543,
62,
615,
14542,
29,
2543,
62,
86,
828,
47715,
198,
74,
62,
1416,
64,
62,
86,
796,
479,
62,
1416,
64,
62,
86,
58,
7,
15,
13,
24,
9,
2543,
62,
615,
14542,
27,
2543,
62,
86,
8,
1222,
357,
16,
13,
16,
9,
2543,
62,
615,
14542,
29,
2543,
62,
86,
828,
47715,
198,
74,
62,
1416,
64,
62,
86,
796,
479,
62,
1416,
64,
62,
86,
9,
7,
16,
13,
532,
220,
308,
1416,
64,
62,
86,
58,
7,
15,
13,
24,
9,
2543,
62,
615,
14542,
27,
2543,
62,
86,
8,
1222,
357,
16,
13,
16,
9,
2543,
62,
615,
14542,
29,
2543,
62,
86,
828,
25,
12962,
198,
2543,
62,
86,
796,
30592,
62,
86,
58,
7,
15,
13,
24,
9,
2543,
62,
615,
14542,
27,
2543,
62,
86,
8,
1222,
357,
16,
13,
16,
9,
2543,
62,
615,
14542,
29,
2543,
62,
86,
15437,
198,
198,
404,
330,
62,
25928,
796,
45912,
13,
7857,
62,
23913,
62,
404,
4355,
7,
2543,
62,
615,
14542,
11,
257,
62,
86,
11,
30592,
62,
86,
11,
479,
62,
8937,
62,
86,
13,
51,
11,
479,
62,
1416,
64,
62,
86,
13,
51,
11,
10662,
28,
18,
13,
20,
11,
7110,
28,
17821,
8,
628,
198,
8818,
62,
2302,
796,
39555,
378,
13,
3849,
79,
16,
67,
7,
64,
62,
86,
11,
1034,
330,
62,
25928,
17816,
4914,
6,
7131,
47715,
10,
404,
330,
62,
25928,
17816,
591,
6,
7131,
25,
4357,
11031,
11639,
66,
549,
291,
11537,
198,
8818,
62,
282,
65,
796,
39555,
378,
13,
3849,
79,
16,
67,
7,
64,
62,
86,
11,
1034,
330,
62,
25928,
17816,
591,
6,
7131,
47715,
29006,
404,
330,
62,
25928,
17816,
4914,
6,
7131,
47715,
10,
404,
330,
62,
25928,
17816,
591,
6,
7131,
25,
46570,
11031,
11639,
66,
549,
291,
11537,
198,
361,
407,
45765,
25,
198,
220,
220,
220,
2163,
62,
282,
65,
796,
39555,
378,
13,
3849,
79,
16,
67,
7,
64,
62,
86,
11,
45941,
13,
9107,
418,
19510,
37659,
13,
43358,
7,
404,
330,
62,
25928,
17816,
591,
6,
7131,
47715,
4008,
828,
11031,
11639,
66,
549,
291,
11537,
198
] | 3.043411 | 645 |
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 16 18:06:05 2021
@author: jhask
"""
import csv
import pandas as pd
import numpy as np
import re
import scipy.io as sio
import os
# Map MCM names to TUV labels
j_vals_dict= dict({
'O3 -> O2 + O(1D)':'J1',
'O3 -> O2 + O(3P)':'J2',
'H2O2 -> 2 OH':'J3',
'NO2 -> NO + O(3P)':'J4',
'NO3 -> NO + O2':'J5',
'NO3 -> NO2 + O(3P)':'J6',
'HNO2 -> OH + NO':'J7',
'HNO3 -> OH + NO2':'J8',
'CH2O -> H + HCO':'J11',
'CH2O -> H2 + CO':'J12',
'CH3CHO -> CH3 + HCO':'J13',
'C2H5CHO -> C2H5 + HCO':'J14',
'CH2=C(CH3)CHO -> Products':'J18',
'CH3COCH3 -> CH3CO + CH3':'J21',
'CH3COCH2CH3 -> CH3CO + CH2CH3':'J22',
'CH3COCH=CH2 -> Products':'J23',
'CHOCHO -> H2 + 2CO':'J31',
'CHOCHO -> CH2O + CO':'J32',
'CHOCHO -> HCO + HCO':'J33',
'CH3COCHO -> CH3CO + HCO':'J34',
'CH3COCOCH3 -> Products':'J35',
'CH3OOH -> CH3O + OH':'J41',
'CH3ONO2 -> CH3O + NO2':'J51',
'C2H5ONO2 -> C2H5O + NO2':'J52',
'n-C3H7ONO2 -> C3H7O + NO2':'J53',
'CH3CHONO2CH3 -> CH3CHOCH3 + NO2':'J54',
'C(CH3)3(ONO2) -> C(CH3)3(O.) + NO2':'J55',
'CH3COCH2(ONO2) -> CH3COCH2(O.) + NO2':'J56',
'CH2(OH)COCH3 -> CH3CO + CH2(OH)':'Jn10',
'CH2=CHCHO -> Products':'Jn11',
'CH3CO(OONO2) -> CH3CO(OO) + NO2':'Jn14',
'CH3CO(OONO2) -> CH3CO(O) + NO3':'Jn15',
'CH3(OONO2) -> CH3(OO) + NO2':'Jn16',
'CH3(OONO2) -> CH3(OO) + NO2':'Jn17',
'N2O5 -> NO3 + NO2':'Jn19',
'N2O5 -> NO3 + NO + O(3P)':'Jn20',
'HNO4 -> HO2 + NO2':'Jn21'})
#TUV output file.
file= 'C:/Users/jhask/OneDrive/Documents/MATLAB/F0AM/Setups/SOAS_RCIM/foam_6_29_out.txt'
with open(file, "r",errors="ignore") as f: # read line by line.
reader = csv.reader(f, delimiter="\t")
# Initialize vars we fill in reading the file.
ln_num = 0; map_cols=dict({})
in_species_list=False;
pass_go=False
for row in reader:
line = " ".join(row) # read line by line.
hdrs= [key for key in list(j_vals_dict.keys()) if key in line]
if len(hdrs) > 0 :
headers= re.search(r"[\d]*[\=\w]", line)
print(line, hdrs, j_vals_dict[ hdrs[:][0]])
if headers: map_cols[headers.group()]=j_vals_dict[ hdrs[:][0]]
if (pass_go is True) and ('------' not in line ):
# Append the j-values to the dataframe at this point in time.
splt= [float(item) for item in line.split(" ") if item !='']
df.loc[len(df)]=np.array(splt)
if 'time, hrs. sza, deg.' in line:
pass_go=True
df=pd.DataFrame(columns= ['time', 'sza']+ list(map_cols.values()))
to_mat={name: col.values for name, col in df.items()}
filename= os.path.join('C:/Users/jhask/OneDrive/Documents/MATLAB/F0AM/Setups/SOAS_RCIM/'+'F0AM_tuv.mat')
sio.savemat(filename, to_mat)
print(filename)
| [
2,
532,
9,
12,
19617,
25,
3384,
69,
12,
23,
532,
9,
12,
201,
198,
37811,
201,
198,
41972,
319,
3300,
7653,
1467,
1248,
25,
3312,
25,
2713,
33448,
201,
198,
201,
198,
31,
9800,
25,
474,
71,
2093,
201,
198,
37811,
201,
198,
11748,
269,
21370,
220,
201,
198,
11748,
19798,
292,
355,
279,
67,
201,
198,
11748,
299,
32152,
355,
45941,
220,
201,
198,
11748,
302,
201,
198,
11748,
629,
541,
88,
13,
952,
355,
264,
952,
220,
201,
198,
11748,
28686,
220,
201,
198,
201,
198,
2,
9347,
13122,
44,
3891,
284,
309,
31667,
14722,
220,
201,
198,
73,
62,
12786,
62,
11600,
28,
8633,
15090,
201,
198,
6,
46,
18,
4613,
440,
17,
1343,
440,
7,
16,
35,
8,
10354,
6,
41,
16,
3256,
201,
198,
6,
46,
18,
4613,
440,
17,
1343,
440,
7,
18,
47,
8,
10354,
6,
41,
17,
3256,
201,
198,
6,
39,
17,
46,
17,
4613,
362,
18723,
10354,
6,
41,
18,
3256,
201,
198,
6,
15285,
17,
4613,
8005,
1343,
440,
7,
18,
47,
8,
10354,
6,
41,
19,
3256,
201,
198,
6,
15285,
18,
4613,
8005,
1343,
440,
17,
10354,
6,
41,
20,
3256,
201,
198,
6,
15285,
18,
4613,
8005,
17,
1343,
440,
7,
18,
47,
8,
10354,
6,
41,
21,
3256,
201,
198,
6,
39,
15285,
17,
4613,
18723,
1343,
8005,
10354,
6,
41,
22,
3256,
201,
198,
6,
39,
15285,
18,
4613,
18723,
1343,
8005,
17,
10354,
6,
41,
23,
3256,
201,
198,
6,
3398,
17,
46,
4613,
367,
1343,
367,
8220,
10354,
6,
41,
1157,
3256,
201,
198,
6,
3398,
17,
46,
4613,
367,
17,
1343,
7375,
10354,
6,
41,
1065,
3256,
201,
198,
6,
3398,
18,
44899,
4613,
5870,
18,
1343,
367,
8220,
10354,
6,
41,
1485,
3256,
201,
198,
6,
34,
17,
39,
20,
44899,
4613,
327,
17,
39,
20,
1343,
367,
8220,
10354,
6,
41,
1415,
3256,
201,
198,
6,
3398,
17,
28,
34,
7,
3398,
18,
8,
44899,
4613,
18675,
10354,
6,
41,
1507,
3256,
201,
198,
6,
3398,
18,
8220,
3398,
18,
4613,
5870,
18,
8220,
1343,
5870,
18,
10354,
6,
41,
2481,
3256,
201,
198,
6,
3398,
18,
8220,
3398,
17,
3398,
18,
4613,
5870,
18,
8220,
1343,
5870,
17,
3398,
18,
10354,
6,
41,
1828,
3256,
201,
198,
6,
3398,
18,
8220,
3398,
28,
3398,
17,
4613,
18675,
10354,
6,
41,
1954,
3256,
201,
198,
6,
44899,
44899,
4613,
367,
17,
1343,
362,
8220,
10354,
6,
41,
3132,
3256,
201,
198,
6,
44899,
44899,
4613,
5870,
17,
46,
1343,
7375,
10354,
6,
41,
2624,
3256,
201,
198,
6,
44899,
44899,
4613,
367,
8220,
1343,
367,
8220,
10354,
6,
41,
2091,
3256,
201,
198,
6,
3398,
18,
8220,
44899,
4613,
5870,
18,
8220,
1343,
367,
8220,
10354,
6,
41,
2682,
3256,
201,
198,
6,
3398,
18,
34,
4503,
46,
3398,
18,
4613,
18675,
10354,
6,
41,
2327,
3256,
201,
198,
6,
3398,
18,
6684,
39,
4613,
5870,
18,
46,
1343,
18723,
10354,
6,
41,
3901,
3256,
201,
198,
6,
3398,
18,
1340,
46,
17,
4613,
5870,
18,
46,
1343,
8005,
17,
10354,
6,
41,
4349,
3256,
201,
198,
6,
34,
17,
39,
20,
1340,
46,
17,
4613,
327,
17,
39,
20,
46,
1343,
8005,
17,
10354,
6,
41,
4309,
3256,
201,
198,
6,
77,
12,
34,
18,
39,
22,
1340,
46,
17,
4613,
327,
18,
39,
22,
46,
1343,
8005,
17,
10354,
6,
41,
4310,
3256,
201,
198,
6,
3398,
18,
3398,
1340,
46,
17,
3398,
18,
4613,
5870,
18,
44899,
3398,
18,
1343,
8005,
17,
10354,
6,
41,
4051,
3256,
201,
198,
6,
34,
7,
3398,
18,
8,
18,
7,
1340,
46,
17,
8,
4613,
327,
7,
3398,
18,
8,
18,
7,
46,
2014,
1343,
8005,
17,
10354,
6,
41,
2816,
3256,
201,
198,
6,
3398,
18,
8220,
3398,
17,
7,
1340,
46,
17,
8,
4613,
5870,
18,
8220,
3398,
17,
7,
46,
2014,
1343,
8005,
17,
10354,
6,
41,
3980,
3256,
201,
198,
6,
3398,
17,
7,
12096,
8,
8220,
3398,
18,
4613,
5870,
18,
8220,
1343,
5870,
17,
7,
12096,
8,
10354,
6,
41,
77,
940,
3256,
201,
198,
6,
3398,
17,
28,
3398,
44899,
4613,
18675,
10354,
6,
41,
77,
1157,
3256,
201,
198,
6,
3398,
18,
8220,
7,
46,
1340,
46,
17,
8,
4613,
5870,
18,
8220,
7,
6684,
8,
1343,
8005,
17,
10354,
6,
41,
77,
1415,
3256,
201,
198,
6,
3398,
18,
8220,
7,
46,
1340,
46,
17,
8,
4613,
5870,
18,
8220,
7,
46,
8,
1343,
8005,
18,
10354,
6,
41,
77,
1314,
3256,
201,
198,
6,
3398,
18,
7,
46,
1340,
46,
17,
8,
4613,
5870,
18,
7,
6684,
8,
1343,
8005,
17,
10354,
6,
41,
77,
1433,
3256,
201,
198,
6,
3398,
18,
7,
46,
1340,
46,
17,
8,
4613,
5870,
18,
7,
6684,
8,
1343,
8005,
17,
10354,
6,
41,
77,
1558,
3256,
201,
198,
6,
45,
17,
46,
20,
4613,
8005,
18,
1343,
8005,
17,
10354,
6,
41,
77,
1129,
3256,
201,
198,
6,
45,
17,
46,
20,
4613,
8005,
18,
1343,
8005,
1343,
440,
7,
18,
47,
8,
10354,
6,
41,
77,
1238,
3256,
201,
198,
6,
39,
15285,
19,
4613,
40115,
17,
1343,
8005,
17,
10354,
6,
41,
77,
2481,
6,
30072,
201,
198,
201,
198,
201,
198,
2,
51,
31667,
5072,
2393,
13,
220,
201,
198,
7753,
28,
705,
34,
14079,
14490,
14,
73,
71,
2093,
14,
3198,
24825,
14,
38354,
14,
41636,
48780,
14,
37,
15,
2390,
14,
7248,
4739,
14,
15821,
1921,
62,
7397,
3955,
14,
6513,
321,
62,
21,
62,
1959,
62,
448,
13,
14116,
6,
201,
198,
201,
198,
4480,
1280,
7,
7753,
11,
366,
81,
1600,
48277,
2625,
46430,
4943,
355,
277,
25,
1303,
1100,
1627,
416,
1627,
13,
201,
198,
220,
220,
220,
9173,
796,
269,
21370,
13,
46862,
7,
69,
11,
46728,
2676,
2625,
59,
83,
4943,
201,
198,
220,
220,
220,
220,
201,
198,
220,
220,
220,
1303,
20768,
1096,
410,
945,
356,
6070,
287,
3555,
262,
2393,
13,
220,
201,
198,
220,
220,
220,
300,
77,
62,
22510,
796,
657,
26,
3975,
62,
4033,
82,
28,
11600,
15090,
30072,
201,
198,
220,
220,
220,
287,
62,
35448,
62,
4868,
28,
25101,
26,
220,
201,
198,
201,
198,
220,
220,
220,
1208,
62,
2188,
28,
25101,
201,
198,
220,
220,
220,
329,
5752,
287,
9173,
25,
201,
198,
220,
220,
220,
220,
220,
220,
220,
1627,
796,
366,
27071,
22179,
7,
808,
8,
220,
1303,
1100,
1627,
416,
1627,
13,
220,
201,
198,
201,
198,
201,
198,
220,
220,
220,
220,
220,
220,
220,
289,
67,
3808,
28,
685,
2539,
220,
329,
1994,
287,
1351,
7,
73,
62,
12786,
62,
11600,
13,
13083,
28955,
611,
1994,
287,
1627,
60,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
201,
198,
220,
220,
220,
220,
220,
220,
220,
611,
18896,
7,
31298,
3808,
8,
1875,
657,
1058,
220,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
24697,
28,
302,
13,
12947,
7,
81,
17912,
59,
67,
60,
9,
58,
59,
28,
59,
86,
60,
1600,
1627,
8,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
3601,
7,
1370,
11,
289,
67,
3808,
11,
474,
62,
12786,
62,
11600,
58,
289,
67,
3808,
58,
25,
7131,
15,
11907,
8,
220,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
611,
24697,
25,
3975,
62,
4033,
82,
58,
50145,
13,
8094,
3419,
22241,
73,
62,
12786,
62,
11600,
58,
289,
67,
3808,
58,
25,
7131,
15,
11907,
201,
198,
201,
198,
220,
220,
220,
220,
220,
220,
220,
611,
357,
6603,
62,
2188,
318,
6407,
8,
290,
19203,
23031,
6,
407,
287,
1627,
15179,
220,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1303,
2034,
437,
262,
474,
12,
27160,
284,
262,
1366,
14535,
379,
428,
966,
287,
640,
13,
220,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
4328,
83,
28,
685,
22468,
7,
9186,
8,
329,
2378,
287,
1627,
13,
35312,
7203,
366,
8,
611,
2378,
14512,
7061,
60,
220,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
47764,
13,
17946,
58,
11925,
7,
7568,
15437,
28,
37659,
13,
18747,
7,
22018,
83,
8,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
201,
198,
220,
220,
220,
220,
220,
220,
220,
611,
705,
2435,
11,
36201,
13,
220,
264,
4496,
11,
3396,
2637,
287,
1627,
25,
220,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1208,
62,
2188,
28,
17821,
220,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
47764,
28,
30094,
13,
6601,
19778,
7,
28665,
82,
28,
37250,
2435,
3256,
705,
82,
4496,
20520,
10,
1351,
7,
8899,
62,
4033,
82,
13,
27160,
3419,
4008,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
201,
198,
201,
198,
1462,
62,
6759,
34758,
3672,
25,
951,
13,
27160,
329,
1438,
11,
951,
287,
47764,
13,
23814,
3419,
92,
201,
198,
201,
198,
34345,
28,
28686,
13,
6978,
13,
22179,
10786,
34,
14079,
14490,
14,
73,
71,
2093,
14,
3198,
24825,
14,
38354,
14,
41636,
48780,
14,
37,
15,
2390,
14,
7248,
4739,
14,
15821,
1921,
62,
7397,
3955,
14,
6,
10,
6,
37,
15,
2390,
62,
83,
14795,
13,
6759,
11537,
201,
198,
82,
952,
13,
21928,
6759,
7,
34345,
11,
284,
62,
6759,
8,
201,
198,
220,
220,
220,
220,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
201,
198,
4798,
7,
34345,
8,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
201,
198
] | 1.792441 | 1,614 |
'''
Imports
'''
from config import *
from newspaper import Article
import sys as sys
import pandas as pd
import csv
from collections import defaultdict
import re
'''
URL Extract
'''
columns = defaultdict(list)
with open('SecurityIDRBT.csv') as f:
reader = csv.DictReader(f) # read rows into a dictionary format
for row in reader: # read a row as {column1: value1, column2: value2,...}
for (k,v) in row.items(): # go over each column name and value
columns[k].append(v) # append the value into the appropriate list
url_list = [] # based on column name k
for element in range(len(columns['Body'])):
urls = re.findall('https?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+', columns['Body'][element])
for url in urls:
url_list.append(url)
'''
Find Unique URLs and filter with semantic search results
'''
url_unique = []
for element in url_list:
if element not in url_unique:
if element not in common_urls_http:
if element not in common_urls_https:
url_unique.append(element)
'''
Write it in a new CSV
'''
with open('url.csv', 'w',newline='') as myfile:
wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
for word in url_unique:
wr.writerow([word])
| [
7061,
6,
201,
198,
3546,
3742,
201,
198,
7061,
6,
201,
198,
6738,
4566,
1330,
1635,
201,
198,
6738,
7533,
1330,
10172,
201,
198,
11748,
25064,
355,
25064,
201,
198,
11748,
19798,
292,
355,
279,
67,
220,
201,
198,
11748,
269,
21370,
201,
198,
6738,
17268,
1330,
4277,
11600,
201,
198,
11748,
302,
201,
198,
7061,
6,
201,
198,
21886,
29677,
201,
198,
7061,
6,
201,
198,
28665,
82,
796,
4277,
11600,
7,
4868,
8,
201,
198,
4480,
1280,
10786,
24074,
2389,
49,
19313,
13,
40664,
11537,
355,
277,
25,
201,
198,
220,
220,
220,
9173,
796,
269,
21370,
13,
35,
713,
33634,
7,
69,
8,
1303,
1100,
15274,
656,
257,
22155,
5794,
201,
198,
220,
220,
220,
329,
5752,
287,
9173,
25,
1303,
1100,
257,
5752,
355,
1391,
28665,
16,
25,
1988,
16,
11,
5721,
17,
25,
1988,
17,
42303,
92,
201,
198,
220,
220,
220,
220,
220,
220,
220,
329,
357,
74,
11,
85,
8,
287,
5752,
13,
23814,
33529,
1303,
467,
625,
1123,
5721,
1438,
290,
1988,
220,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
15180,
58,
74,
4083,
33295,
7,
85,
8,
1303,
24443,
262,
1988,
656,
262,
5035,
1351,
201,
198,
6371,
62,
4868,
796,
17635,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1303,
1912,
319,
5721,
1438,
479,
201,
198,
1640,
5002,
287,
2837,
7,
11925,
7,
28665,
82,
17816,
25842,
6,
12962,
2599,
201,
198,
220,
220,
220,
220,
220,
220,
220,
2956,
7278,
796,
302,
13,
19796,
439,
10786,
5450,
30,
1378,
7,
27514,
58,
12,
59,
86,
8183,
91,
7,
27514,
4,
58,
59,
6814,
12,
69,
32,
12,
37,
60,
90,
17,
92,
4008,
10,
3256,
15180,
17816,
25842,
6,
7131,
30854,
12962,
201,
198,
220,
220,
220,
220,
220,
220,
220,
329,
19016,
287,
2956,
7278,
25,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
19016,
62,
4868,
13,
33295,
7,
6371,
8,
201,
198,
7061,
6,
201,
198,
16742,
30015,
32336,
290,
8106,
351,
37865,
2989,
2482,
201,
198,
7061,
6,
201,
198,
6371,
62,
34642,
796,
17635,
201,
198,
1640,
5002,
287,
19016,
62,
4868,
25,
201,
198,
220,
220,
220,
611,
5002,
407,
287,
19016,
62,
34642,
25,
201,
198,
220,
220,
220,
220,
220,
220,
220,
611,
5002,
407,
287,
2219,
62,
6371,
82,
62,
4023,
25,
220,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
611,
5002,
407,
287,
2219,
62,
6371,
82,
62,
5450,
25,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
19016,
62,
34642,
13,
33295,
7,
30854,
8,
201,
198,
7061,
6,
201,
198,
16594,
340,
287,
257,
649,
44189,
201,
198,
7061,
6,
220,
220,
220,
220,
201,
198,
201,
198,
4480,
1280,
10786,
6371,
13,
40664,
3256,
705,
86,
3256,
3605,
1370,
28,
7061,
8,
355,
616,
7753,
25,
201,
198,
220,
220,
220,
1319,
796,
269,
21370,
13,
16002,
7,
1820,
7753,
11,
28411,
28,
40664,
13,
10917,
23051,
62,
7036,
8,
201,
198,
220,
220,
220,
329,
1573,
287,
19016,
62,
34642,
25,
201,
198,
220,
220,
220,
220,
220,
220,
220,
1319,
13,
16002,
322,
26933,
4775,
12962,
201,
198,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
201,
198,
220
] | 2.284014 | 588 |
# -*- coding: utf-8 -*-
# Copyright 2018, IBM.
#
# This source code is licensed under the Apache License, Version 2.0 found in
# the LICENSE.txt file in the root directory of this source tree.
# pylint: disable=missing-docstring
from qiskit.mapper import _coupling
from .common import QiskitTestCase
| [
2,
532,
9,
12,
19617,
25,
3384,
69,
12,
23,
532,
9,
12,
198,
198,
2,
15069,
2864,
11,
19764,
13,
198,
2,
198,
2,
770,
2723,
2438,
318,
11971,
739,
262,
24843,
13789,
11,
10628,
362,
13,
15,
1043,
287,
198,
2,
262,
38559,
24290,
13,
14116,
2393,
287,
262,
6808,
8619,
286,
428,
2723,
5509,
13,
198,
198,
2,
279,
2645,
600,
25,
15560,
28,
45688,
12,
15390,
8841,
628,
198,
6738,
10662,
1984,
270,
13,
76,
11463,
1330,
4808,
66,
280,
11347,
198,
6738,
764,
11321,
1330,
1195,
1984,
270,
14402,
20448,
628
] | 3.177083 | 96 |
import os
import re
import k3d
import types
import random
import pytest
import numbers
import tempfile
import itertools
import numpy as np
import discretisedfield as df
import matplotlib.pyplot as plt
from .test_mesh import TestMesh
| [
11748,
28686,
198,
11748,
302,
198,
11748,
479,
18,
67,
198,
11748,
3858,
198,
11748,
4738,
198,
11748,
12972,
9288,
198,
11748,
3146,
198,
11748,
20218,
7753,
198,
11748,
340,
861,
10141,
198,
11748,
299,
32152,
355,
45941,
198,
11748,
1221,
1186,
1417,
3245,
355,
47764,
198,
11748,
2603,
29487,
8019,
13,
9078,
29487,
355,
458,
83,
198,
6738,
764,
9288,
62,
76,
5069,
1330,
6208,
37031,
628,
198
] | 3.405797 | 69 |
__all__ = ['get']
import collections
def get(input):
"""return a list with input values or [] if input is None"""
if input is None:
return []
if not _iterable(input) or _string(input):
return [input]
return list(input)
| [
834,
439,
834,
796,
37250,
1136,
20520,
628,
198,
11748,
17268,
628,
628,
198,
4299,
651,
7,
15414,
2599,
198,
220,
220,
220,
37227,
7783,
257,
1351,
351,
5128,
3815,
393,
17635,
611,
5128,
318,
6045,
37811,
198,
220,
220,
220,
611,
5128,
318,
6045,
25,
198,
220,
220,
220,
220,
220,
220,
220,
1441,
17635,
198,
220,
220,
220,
611,
407,
4808,
2676,
540,
7,
15414,
8,
393,
4808,
8841,
7,
15414,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
1441,
685,
15414,
60,
198,
220,
220,
220,
1441,
1351,
7,
15414,
8,
198
] | 2.677083 | 96 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2019/8/20 0020 16:49
# @Author : Hadrianl
# @File : __init__.py
from .widget import StrategyReviewer | [
2,
48443,
14629,
14,
8800,
14,
24330,
21015,
198,
2,
532,
9,
12,
19617,
25,
3384,
69,
12,
23,
532,
9,
12,
198,
2,
2488,
7575,
220,
220,
220,
1058,
13130,
14,
23,
14,
1238,
3571,
1238,
1467,
25,
2920,
198,
2,
2488,
13838,
220,
1058,
11161,
4484,
75,
220,
198,
2,
2488,
8979,
220,
220,
220,
1058,
11593,
15003,
834,
13,
9078,
198,
198,
6738,
764,
42655,
1330,
20561,
35407
] | 2.323944 | 71 |
import xml.etree.ElementTree as ET
xml_string = '''
<stuff>
<users>
<user x = "2">
<id>001</id>
<name>Chuck</name>
</user>
<user x = "7">
<id>007</id>
<name>Brent</name>
</user>
</users>
</stuff>
'''
root_stuff = ET.fromstring(xml_string)
#don't usually refer to root element
user_elements = root_stuff.findall('users/user')
print ('user count:', len(user_elements))
for user in user_elements:
print('name:', user.find('name').text)
print('id:', user.find('id').text)
print('attribute(x):', user.get('x'))
#to identify attribute use 'get's
| [
11748,
35555,
13,
316,
631,
13,
20180,
27660,
355,
12152,
198,
198,
19875,
62,
8841,
796,
705,
7061,
198,
27,
41094,
29,
198,
220,
220,
220,
1279,
18417,
29,
198,
220,
220,
220,
220,
220,
220,
220,
1279,
7220,
2124,
796,
366,
17,
5320,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1279,
312,
29,
8298,
3556,
312,
29,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1279,
3672,
29,
44324,
3556,
3672,
29,
198,
220,
220,
220,
220,
220,
220,
220,
7359,
7220,
29,
198,
220,
220,
220,
220,
220,
220,
220,
1279,
7220,
2124,
796,
366,
22,
5320,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1279,
312,
29,
25816,
3556,
312,
29,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1279,
3672,
29,
33,
1156,
3556,
3672,
29,
198,
220,
220,
220,
220,
220,
220,
220,
7359,
7220,
29,
198,
220,
220,
220,
7359,
18417,
29,
198,
3556,
41094,
29,
198,
7061,
6,
198,
198,
15763,
62,
41094,
796,
12152,
13,
6738,
8841,
7,
19875,
62,
8841,
8,
198,
2,
9099,
470,
3221,
3522,
284,
6808,
5002,
198,
7220,
62,
68,
3639,
796,
6808,
62,
41094,
13,
19796,
439,
10786,
18417,
14,
7220,
11537,
198,
4798,
19203,
7220,
954,
25,
3256,
18896,
7,
7220,
62,
68,
3639,
4008,
198,
198,
1640,
2836,
287,
2836,
62,
68,
3639,
25,
198,
220,
220,
220,
3601,
10786,
3672,
25,
3256,
2836,
13,
19796,
10786,
3672,
27691,
5239,
8,
198,
220,
220,
220,
3601,
10786,
312,
25,
3256,
2836,
13,
19796,
10786,
312,
27691,
5239,
8,
198,
220,
220,
220,
3601,
10786,
42348,
7,
87,
2599,
3256,
2836,
13,
1136,
10786,
87,
6,
4008,
198,
220,
220,
220,
1303,
1462,
5911,
11688,
779,
705,
1136,
338,
198
] | 2.142384 | 302 |
from multiprocessing.dummy import Pool
pool = Pool(3)
origin_num = [x for x in range(10)]
result = pool.map(calc_power2, origin_num)
print(f'计算1-10的平方分别为:{result}')
| [
6738,
18540,
305,
919,
278,
13,
67,
13513,
1330,
19850,
628,
198,
7742,
796,
19850,
7,
18,
8,
198,
47103,
62,
22510,
796,
685,
87,
329,
2124,
287,
2837,
7,
940,
15437,
198,
20274,
796,
5933,
13,
8899,
7,
9948,
66,
62,
6477,
17,
11,
8159,
62,
22510,
8,
198,
4798,
7,
69,
6,
164,
106,
94,
163,
106,
245,
16,
12,
940,
21410,
33176,
111,
43095,
26344,
228,
26344,
104,
10310,
118,
171,
120,
248,
90,
20274,
92,
11537,
628,
198
] | 2.060976 | 82 |
from django.apps import AppConfig
| [
6738,
42625,
14208,
13,
18211,
1330,
2034,
16934,
628
] | 3.888889 | 9 |
from django.core.urlresolvers import reverse
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.core.urlresolvers import reverse_lazy
from django.utils.decorators import method_decorator
from django.contrib.auth.decorators import login_required
from .models import Eintrag
from .forms import EintragForm
| [
6738,
42625,
14208,
13,
7295,
13,
6371,
411,
349,
690,
1330,
9575,
198,
6738,
42625,
14208,
13,
33571,
13,
41357,
13,
49170,
1330,
42585,
7680,
198,
6738,
42625,
14208,
13,
33571,
13,
41357,
13,
4868,
1330,
7343,
7680,
198,
6738,
42625,
14208,
13,
33571,
13,
41357,
13,
19312,
1330,
13610,
7680,
11,
10133,
7680,
11,
23520,
7680,
198,
6738,
42625,
14208,
13,
7295,
13,
6371,
411,
349,
690,
1330,
9575,
62,
75,
12582,
198,
6738,
42625,
14208,
13,
26791,
13,
12501,
273,
2024,
1330,
2446,
62,
12501,
273,
1352,
198,
6738,
42625,
14208,
13,
3642,
822,
13,
18439,
13,
12501,
273,
2024,
1330,
17594,
62,
35827,
198,
6738,
764,
27530,
1330,
412,
600,
22562,
198,
6738,
764,
23914,
1330,
412,
600,
22562,
8479,
628,
628,
628
] | 3.5 | 126 |
from typing import Any, Optional, Tuple, Union
import torch
from torch.nn.functional import mse_loss
import pystiche
import pystiche.loss.functional as F
from pystiche import enc, loss
from pystiche_papers.utils import HyperParameters
from ._utils import (
extract_normalized_patches2d,
hyper_parameters as _hyper_parameters,
multi_layer_encoder as _multi_layer_encoder,
target_transforms as _target_transforms,
)
__all__ = [
"FeatureReconstructionLoss",
"content_loss",
"MRFLoss",
"style_loss",
"TotalVariationLoss",
"regularization",
"perceptual_loss",
]
class FeatureReconstructionLoss(loss.FeatureReconstructionLoss):
r"""Feature reconstruction loss from :cite:`LW2016`.
Args:
encoder: Encoder used to encode the input.
impl_params: If ``False``, calculate the score with the squared error (SE)
instead of the mean squared error (MSE).
**feature_reconstruction_loss_kwargs: Additional parameters of a
:class:`pystiche.loss.FeatureReconstructionLoss`.
.. seealso::
:class:`pystiche.loss.FeatureReconstructionLoss`
"""
def content_loss(
impl_params: bool = True,
multi_layer_encoder: Optional[enc.MultiLayerEncoder] = None,
hyper_parameters: Optional[HyperParameters] = None,
) -> FeatureReconstructionLoss:
r"""Content loss from :cite:`LW2016`.
Args:
impl_params: Switch the behavior and hyper-parameters between the reference
implementation of the original authors and what is described in the paper.
For details see :ref:`here <li_wand_2016-impl_params>`.
multi_layer_encoder: Pretrained multi-layer encoder. If
omitted, :func:`~pystiche_papers.li_wand_2016.multi_layer_encoder` is used.
hyper_parameters: Hyper parameters. If omitted,
:func:`~pystiche_papers.li_wand_2016.hyper_parameters` is used.
.. seealso::
:class:`pystiche_papers.li_wand_2016.FeatureReconstructionLoss`
"""
if multi_layer_encoder is None:
multi_layer_encoder = _multi_layer_encoder()
if hyper_parameters is None:
hyper_parameters = _hyper_parameters(impl_params=impl_params)
return FeatureReconstructionLoss(
multi_layer_encoder.extract_encoder(hyper_parameters.content_loss.layer),
impl_params=impl_params,
score_weight=hyper_parameters.content_loss.score_weight,
)
class MRFLoss(loss.MRFLoss):
r"""MRF loss from :cite:`LW2016`.
Args:
encoder: Encoder used to encode the input.
patch_size: Spatial size of the neural patches.
impl_params: If ``True``, normalize the gradient of the neural patches. If
``False``, use a score correction factor of 1/2.
**mrf_loss_kwargs: Additional parameters of a :class:`pystiche.loss.MRFLoss`.
In contrast to :class:`pystiche.loss.MRFLoss`, the score is calculated with the
squared error (SE) instead of the mean squared error (MSE).
.. seealso::
- :class:`pystiche.loss.MRFLoss`
- :func:`pystiche_papers.li_wand_2016.extract_normalized_patches2d`
"""
def style_loss(
impl_params: bool = True,
multi_layer_encoder: Optional[enc.MultiLayerEncoder] = None,
hyper_parameters: Optional[HyperParameters] = None,
) -> loss.MultiLayerEncodingLoss:
r"""Style loss from :cite:`LW2016`.
Args:
impl_params: Switch the behavior and hyper-parameters between the reference
implementation of the original authors and what is described in the paper.
For details see :ref:`here <li_wand_2016-impl_params>`.
multi_layer_encoder: Pretrained multi-layer encoder. If
omitted, :func:`~pystiche_papers.li_wand_2016.multi_layer_encoder` is used.
hyper_parameters: Hyper parameters. If omitted,
:func:`~pystiche_papers.li_wand_2016.hyper_parameters` is used.
.. seealso::
- :class:`pystiche_papers.li_wand_2016.MRFLoss`
"""
if multi_layer_encoder is None:
multi_layer_encoder = _multi_layer_encoder()
if hyper_parameters is None:
hyper_parameters = _hyper_parameters(impl_params=impl_params)
return loss.MultiLayerEncodingLoss(
multi_layer_encoder,
hyper_parameters.style_loss.layers,
encoding_loss_fn,
layer_weights=hyper_parameters.style_loss.layer_weights,
score_weight=hyper_parameters.style_loss.score_weight,
)
class TotalVariationLoss(loss.TotalVariationLoss):
r"""Total variation loss from :cite:`LW2016`.
Args:
impl_params: If ``False``, use a score correction factor of 1/2.
**total_variation_loss_kwargs: Additional parameters of a
:class:`pystiche.loss.TotalVariationLoss`.
In contrast to :class:`pystiche.loss.TotalVariationLoss`, the the score is
calculated with the squared error (SE) instead of the mean squared error (MSE).
.. seealso::
- :class:`pystiche.loss.TotalVariationLoss`
"""
def regularization(
impl_params: bool = True,
hyper_parameters: Optional[HyperParameters] = None,
) -> TotalVariationLoss:
r"""Regularization from :cite:`LW2016`.
Args:
impl_params: Switch the behavior and hyper-parameters between the reference
implementation of the original authors and what is described in the paper.
For details see :ref:`here <li_wand_2016-impl_params>`.
hyper_parameters: Hyper parameters. If omitted,
:func:`~pystiche_papers.li_wand_2016.hyper_parameters` is used.
.. seealso::
- :class:`pystiche_papers.li_wand_2016.TotalVariationLoss`
"""
if hyper_parameters is None:
hyper_parameters = _hyper_parameters()
return TotalVariationLoss(
impl_params=impl_params,
score_weight=hyper_parameters.regularization.score_weight,
)
def perceptual_loss(
impl_params: bool = True,
multi_layer_encoder: Optional[enc.MultiLayerEncoder] = None,
hyper_parameters: Optional[HyperParameters] = None,
) -> loss.PerceptualLoss:
r"""Perceptual loss from :cite:`LW2016`.
Args:
impl_params: Switch the behavior and hyper-parameters between the reference
implementation of the original authors and what is described in the paper.
For details see :ref:`here <li_wand_2016-impl_params>`.
multi_layer_encoder: Pretrained multi-layer encoder. If
omitted, :func:`~pystiche_papers.li_wand_2016.multi_layer_encoder` is used.
hyper_parameters: Hyper parameters. If omitted,
:func:`~pystiche_papers.li_wand_2016.hyper_parameters` is used.
.. seealso::
- :func:`pystiche_papers.li_wand_2016.content_loss`
- :func:`pystiche_papers.li_wand_2016.style_loss`
- :func:`pystiche_papers.li_wand_2016.regularization`
"""
if multi_layer_encoder is None:
multi_layer_encoder = _multi_layer_encoder()
if hyper_parameters is None:
hyper_parameters = _hyper_parameters()
return loss.PerceptualLoss(
content_loss(
impl_params=impl_params,
multi_layer_encoder=multi_layer_encoder,
hyper_parameters=hyper_parameters,
),
style_loss(
impl_params=impl_params,
multi_layer_encoder=multi_layer_encoder,
hyper_parameters=hyper_parameters,
),
regularization(impl_params=impl_params, hyper_parameters=hyper_parameters),
)
| [
6738,
19720,
1330,
4377,
11,
32233,
11,
309,
29291,
11,
4479,
198,
198,
11748,
28034,
198,
6738,
28034,
13,
20471,
13,
45124,
1330,
285,
325,
62,
22462,
198,
198,
11748,
12972,
11268,
258,
198,
11748,
12972,
11268,
258,
13,
22462,
13,
45124,
355,
376,
198,
6738,
12972,
11268,
258,
1330,
2207,
11,
2994,
198,
6738,
12972,
11268,
258,
62,
40491,
13,
26791,
1330,
15079,
48944,
198,
198,
6738,
47540,
26791,
1330,
357,
198,
220,
220,
220,
7925,
62,
11265,
1143,
62,
8071,
2052,
17,
67,
11,
198,
220,
220,
220,
8718,
62,
17143,
7307,
355,
4808,
49229,
62,
17143,
7307,
11,
198,
220,
220,
220,
5021,
62,
29289,
62,
12685,
12342,
355,
4808,
41684,
62,
29289,
62,
12685,
12342,
11,
198,
220,
220,
220,
2496,
62,
7645,
23914,
355,
4808,
16793,
62,
7645,
23914,
11,
198,
8,
198,
198,
834,
439,
834,
796,
685,
198,
220,
220,
220,
366,
38816,
6690,
261,
15019,
43,
793,
1600,
198,
220,
220,
220,
366,
11299,
62,
22462,
1600,
198,
220,
220,
220,
366,
13599,
3697,
793,
1600,
198,
220,
220,
220,
366,
7635,
62,
22462,
1600,
198,
220,
220,
220,
366,
14957,
23907,
341,
43,
793,
1600,
198,
220,
220,
220,
366,
16338,
1634,
1600,
198,
220,
220,
220,
366,
525,
984,
723,
62,
22462,
1600,
198,
60,
628,
198,
4871,
27018,
6690,
261,
15019,
43,
793,
7,
22462,
13,
38816,
6690,
261,
15019,
43,
793,
2599,
198,
220,
220,
220,
374,
37811,
38816,
25056,
2994,
422,
1058,
66,
578,
25,
63,
43,
54,
5304,
44646,
628,
220,
220,
220,
943,
14542,
25,
198,
220,
220,
220,
220,
220,
220,
220,
2207,
12342,
25,
14711,
12342,
973,
284,
37773,
262,
5128,
13,
198,
220,
220,
220,
220,
220,
220,
220,
4114,
62,
37266,
25,
1002,
7559,
25101,
15506,
11,
15284,
262,
4776,
351,
262,
44345,
4049,
357,
5188,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2427,
286,
262,
1612,
44345,
4049,
357,
44,
5188,
737,
198,
220,
220,
220,
220,
220,
220,
220,
12429,
30053,
62,
260,
9979,
2762,
62,
22462,
62,
46265,
22046,
25,
15891,
10007,
286,
257,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1058,
4871,
25,
63,
9078,
11268,
258,
13,
22462,
13,
38816,
6690,
261,
15019,
43,
793,
44646,
628,
220,
220,
220,
11485,
766,
14508,
3712,
628,
220,
220,
220,
220,
220,
220,
220,
1058,
4871,
25,
63,
9078,
11268,
258,
13,
22462,
13,
38816,
6690,
261,
15019,
43,
793,
63,
198,
220,
220,
220,
37227,
628,
198,
4299,
2695,
62,
22462,
7,
198,
220,
220,
220,
4114,
62,
37266,
25,
20512,
796,
6407,
11,
198,
220,
220,
220,
5021,
62,
29289,
62,
12685,
12342,
25,
32233,
58,
12685,
13,
29800,
49925,
27195,
12342,
60,
796,
6045,
11,
198,
220,
220,
220,
8718,
62,
17143,
7307,
25,
32233,
58,
38197,
48944,
60,
796,
6045,
11,
198,
8,
4613,
27018,
6690,
261,
15019,
43,
793,
25,
198,
220,
220,
220,
374,
37811,
19746,
2994,
422,
1058,
66,
578,
25,
63,
43,
54,
5304,
44646,
628,
220,
220,
220,
943,
14542,
25,
198,
220,
220,
220,
220,
220,
220,
220,
4114,
62,
37266,
25,
14645,
262,
4069,
290,
8718,
12,
17143,
7307,
1022,
262,
4941,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
7822,
286,
262,
2656,
7035,
290,
644,
318,
3417,
287,
262,
3348,
13,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1114,
3307,
766,
1058,
5420,
25,
63,
1456,
1279,
4528,
62,
86,
392,
62,
5304,
12,
23928,
62,
37266,
29,
44646,
198,
220,
220,
220,
220,
220,
220,
220,
5021,
62,
29289,
62,
12685,
12342,
25,
37123,
13363,
5021,
12,
29289,
2207,
12342,
13,
1002,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
22532,
11,
1058,
20786,
25,
63,
93,
9078,
11268,
258,
62,
40491,
13,
4528,
62,
86,
392,
62,
5304,
13,
41684,
62,
29289,
62,
12685,
12342,
63,
318,
973,
13,
198,
220,
220,
220,
220,
220,
220,
220,
8718,
62,
17143,
7307,
25,
15079,
10007,
13,
1002,
22532,
11,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1058,
20786,
25,
63,
93,
9078,
11268,
258,
62,
40491,
13,
4528,
62,
86,
392,
62,
5304,
13,
49229,
62,
17143,
7307,
63,
318,
973,
13,
628,
220,
220,
220,
11485,
766,
14508,
3712,
628,
220,
220,
220,
220,
220,
220,
220,
1058,
4871,
25,
63,
9078,
11268,
258,
62,
40491,
13,
4528,
62,
86,
392,
62,
5304,
13,
38816,
6690,
261,
15019,
43,
793,
63,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
611,
5021,
62,
29289,
62,
12685,
12342,
318,
6045,
25,
198,
220,
220,
220,
220,
220,
220,
220,
5021,
62,
29289,
62,
12685,
12342,
796,
4808,
41684,
62,
29289,
62,
12685,
12342,
3419,
628,
220,
220,
220,
611,
8718,
62,
17143,
7307,
318,
6045,
25,
198,
220,
220,
220,
220,
220,
220,
220,
8718,
62,
17143,
7307,
796,
4808,
49229,
62,
17143,
7307,
7,
23928,
62,
37266,
28,
23928,
62,
37266,
8,
628,
220,
220,
220,
1441,
27018,
6690,
261,
15019,
43,
793,
7,
198,
220,
220,
220,
220,
220,
220,
220,
5021,
62,
29289,
62,
12685,
12342,
13,
2302,
974,
62,
12685,
12342,
7,
49229,
62,
17143,
7307,
13,
11299,
62,
22462,
13,
29289,
828,
198,
220,
220,
220,
220,
220,
220,
220,
4114,
62,
37266,
28,
23928,
62,
37266,
11,
198,
220,
220,
220,
220,
220,
220,
220,
4776,
62,
6551,
28,
49229,
62,
17143,
7307,
13,
11299,
62,
22462,
13,
26675,
62,
6551,
11,
198,
220,
220,
220,
1267,
628,
198,
4871,
17242,
3697,
793,
7,
22462,
13,
13599,
3697,
793,
2599,
198,
220,
220,
220,
374,
37811,
13599,
37,
2994,
422,
1058,
66,
578,
25,
63,
43,
54,
5304,
44646,
628,
220,
220,
220,
943,
14542,
25,
198,
220,
220,
220,
220,
220,
220,
220,
2207,
12342,
25,
14711,
12342,
973,
284,
37773,
262,
5128,
13,
198,
220,
220,
220,
220,
220,
220,
220,
8529,
62,
7857,
25,
1338,
34961,
2546,
286,
262,
17019,
16082,
13,
198,
220,
220,
220,
220,
220,
220,
220,
4114,
62,
37266,
25,
1002,
7559,
17821,
15506,
11,
3487,
1096,
262,
31312,
286,
262,
17019,
16082,
13,
1002,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
7559,
25101,
15506,
11,
779,
257,
4776,
17137,
5766,
286,
352,
14,
17,
13,
198,
220,
220,
220,
220,
220,
220,
220,
12429,
76,
41871,
62,
22462,
62,
46265,
22046,
25,
15891,
10007,
286,
257,
1058,
4871,
25,
63,
9078,
11268,
258,
13,
22462,
13,
13599,
3697,
793,
44646,
628,
220,
220,
220,
554,
6273,
284,
1058,
4871,
25,
63,
9078,
11268,
258,
13,
22462,
13,
13599,
3697,
793,
47671,
262,
4776,
318,
10488,
351,
262,
198,
220,
220,
220,
44345,
4049,
357,
5188,
8,
2427,
286,
262,
1612,
44345,
4049,
357,
44,
5188,
737,
628,
220,
220,
220,
11485,
766,
14508,
3712,
628,
220,
220,
220,
220,
220,
220,
220,
532,
1058,
4871,
25,
63,
9078,
11268,
258,
13,
22462,
13,
13599,
3697,
793,
63,
198,
220,
220,
220,
220,
220,
220,
220,
532,
1058,
20786,
25,
63,
9078,
11268,
258,
62,
40491,
13,
4528,
62,
86,
392,
62,
5304,
13,
2302,
974,
62,
11265,
1143,
62,
8071,
2052,
17,
67,
63,
198,
220,
220,
220,
37227,
628,
198,
4299,
3918,
62,
22462,
7,
198,
220,
220,
220,
4114,
62,
37266,
25,
20512,
796,
6407,
11,
198,
220,
220,
220,
5021,
62,
29289,
62,
12685,
12342,
25,
32233,
58,
12685,
13,
29800,
49925,
27195,
12342,
60,
796,
6045,
11,
198,
220,
220,
220,
8718,
62,
17143,
7307,
25,
32233,
58,
38197,
48944,
60,
796,
6045,
11,
198,
8,
4613,
2994,
13,
29800,
49925,
27195,
7656,
43,
793,
25,
198,
220,
220,
220,
374,
37811,
21466,
2994,
422,
1058,
66,
578,
25,
63,
43,
54,
5304,
44646,
628,
220,
220,
220,
943,
14542,
25,
198,
220,
220,
220,
220,
220,
220,
220,
4114,
62,
37266,
25,
14645,
262,
4069,
290,
8718,
12,
17143,
7307,
1022,
262,
4941,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
7822,
286,
262,
2656,
7035,
290,
644,
318,
3417,
287,
262,
3348,
13,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1114,
3307,
766,
1058,
5420,
25,
63,
1456,
1279,
4528,
62,
86,
392,
62,
5304,
12,
23928,
62,
37266,
29,
44646,
198,
220,
220,
220,
220,
220,
220,
220,
5021,
62,
29289,
62,
12685,
12342,
25,
37123,
13363,
5021,
12,
29289,
2207,
12342,
13,
1002,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
22532,
11,
1058,
20786,
25,
63,
93,
9078,
11268,
258,
62,
40491,
13,
4528,
62,
86,
392,
62,
5304,
13,
41684,
62,
29289,
62,
12685,
12342,
63,
318,
973,
13,
198,
220,
220,
220,
220,
220,
220,
220,
8718,
62,
17143,
7307,
25,
15079,
10007,
13,
1002,
22532,
11,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1058,
20786,
25,
63,
93,
9078,
11268,
258,
62,
40491,
13,
4528,
62,
86,
392,
62,
5304,
13,
49229,
62,
17143,
7307,
63,
318,
973,
13,
628,
220,
220,
220,
11485,
766,
14508,
3712,
628,
220,
220,
220,
220,
220,
220,
220,
532,
1058,
4871,
25,
63,
9078,
11268,
258,
62,
40491,
13,
4528,
62,
86,
392,
62,
5304,
13,
13599,
3697,
793,
63,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
611,
5021,
62,
29289,
62,
12685,
12342,
318,
6045,
25,
198,
220,
220,
220,
220,
220,
220,
220,
5021,
62,
29289,
62,
12685,
12342,
796,
4808,
41684,
62,
29289,
62,
12685,
12342,
3419,
628,
220,
220,
220,
611,
8718,
62,
17143,
7307,
318,
6045,
25,
198,
220,
220,
220,
220,
220,
220,
220,
8718,
62,
17143,
7307,
796,
4808,
49229,
62,
17143,
7307,
7,
23928,
62,
37266,
28,
23928,
62,
37266,
8,
628,
220,
220,
220,
1441,
2994,
13,
29800,
49925,
27195,
7656,
43,
793,
7,
198,
220,
220,
220,
220,
220,
220,
220,
5021,
62,
29289,
62,
12685,
12342,
11,
198,
220,
220,
220,
220,
220,
220,
220,
8718,
62,
17143,
7307,
13,
7635,
62,
22462,
13,
75,
6962,
11,
198,
220,
220,
220,
220,
220,
220,
220,
21004,
62,
22462,
62,
22184,
11,
198,
220,
220,
220,
220,
220,
220,
220,
7679,
62,
43775,
28,
49229,
62,
17143,
7307,
13,
7635,
62,
22462,
13,
29289,
62,
43775,
11,
198,
220,
220,
220,
220,
220,
220,
220,
4776,
62,
6551,
28,
49229,
62,
17143,
7307,
13,
7635,
62,
22462,
13,
26675,
62,
6551,
11,
198,
220,
220,
220,
1267,
628,
198,
4871,
7472,
23907,
341,
43,
793,
7,
22462,
13,
14957,
23907,
341,
43,
793,
2599,
198,
220,
220,
220,
374,
37811,
14957,
12291,
2994,
422,
1058,
66,
578,
25,
63,
43,
54,
5304,
44646,
628,
220,
220,
220,
943,
14542,
25,
198,
220,
220,
220,
220,
220,
220,
220,
4114,
62,
37266,
25,
1002,
7559,
25101,
15506,
11,
779,
257,
4776,
17137,
5766,
286,
352,
14,
17,
13,
198,
220,
220,
220,
220,
220,
220,
220,
12429,
23350,
62,
25641,
341,
62,
22462,
62,
46265,
22046,
25,
15891,
10007,
286,
257,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1058,
4871,
25,
63,
9078,
11268,
258,
13,
22462,
13,
14957,
23907,
341,
43,
793,
44646,
628,
220,
220,
220,
554,
6273,
284,
1058,
4871,
25,
63,
9078,
11268,
258,
13,
22462,
13,
14957,
23907,
341,
43,
793,
47671,
262,
262,
4776,
318,
198,
220,
220,
220,
10488,
351,
262,
44345,
4049,
357,
5188,
8,
2427,
286,
262,
1612,
44345,
4049,
357,
44,
5188,
737,
628,
220,
220,
220,
11485,
766,
14508,
3712,
628,
220,
220,
220,
220,
220,
220,
220,
532,
1058,
4871,
25,
63,
9078,
11268,
258,
13,
22462,
13,
14957,
23907,
341,
43,
793,
63,
198,
220,
220,
220,
37227,
628,
198,
4299,
3218,
1634,
7,
198,
220,
220,
220,
4114,
62,
37266,
25,
20512,
796,
6407,
11,
198,
220,
220,
220,
8718,
62,
17143,
7307,
25,
32233,
58,
38197,
48944,
60,
796,
6045,
11,
198,
8,
4613,
7472,
23907,
341,
43,
793,
25,
198,
220,
220,
220,
374,
37811,
40164,
1634,
422,
1058,
66,
578,
25,
63,
43,
54,
5304,
44646,
628,
220,
220,
220,
943,
14542,
25,
198,
220,
220,
220,
220,
220,
220,
220,
4114,
62,
37266,
25,
14645,
262,
4069,
290,
8718,
12,
17143,
7307,
1022,
262,
4941,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
7822,
286,
262,
2656,
7035,
290,
644,
318,
3417,
287,
262,
3348,
13,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1114,
3307,
766,
1058,
5420,
25,
63,
1456,
1279,
4528,
62,
86,
392,
62,
5304,
12,
23928,
62,
37266,
29,
44646,
198,
220,
220,
220,
220,
220,
220,
220,
8718,
62,
17143,
7307,
25,
15079,
10007,
13,
1002,
22532,
11,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1058,
20786,
25,
63,
93,
9078,
11268,
258,
62,
40491,
13,
4528,
62,
86,
392,
62,
5304,
13,
49229,
62,
17143,
7307,
63,
318,
973,
13,
628,
220,
220,
220,
11485,
766,
14508,
3712,
628,
220,
220,
220,
220,
220,
220,
220,
532,
1058,
4871,
25,
63,
9078,
11268,
258,
62,
40491,
13,
4528,
62,
86,
392,
62,
5304,
13,
14957,
23907,
341,
43,
793,
63,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
611,
8718,
62,
17143,
7307,
318,
6045,
25,
198,
220,
220,
220,
220,
220,
220,
220,
8718,
62,
17143,
7307,
796,
4808,
49229,
62,
17143,
7307,
3419,
628,
220,
220,
220,
1441,
7472,
23907,
341,
43,
793,
7,
198,
220,
220,
220,
220,
220,
220,
220,
4114,
62,
37266,
28,
23928,
62,
37266,
11,
198,
220,
220,
220,
220,
220,
220,
220,
4776,
62,
6551,
28,
49229,
62,
17143,
7307,
13,
16338,
1634,
13,
26675,
62,
6551,
11,
198,
220,
220,
220,
1267,
628,
198,
4299,
49615,
62,
22462,
7,
198,
220,
220,
220,
4114,
62,
37266,
25,
20512,
796,
6407,
11,
198,
220,
220,
220,
5021,
62,
29289,
62,
12685,
12342,
25,
32233,
58,
12685,
13,
29800,
49925,
27195,
12342,
60,
796,
6045,
11,
198,
220,
220,
220,
8718,
62,
17143,
7307,
25,
32233,
58,
38197,
48944,
60,
796,
6045,
11,
198,
8,
4613,
2994,
13,
5990,
984,
723,
43,
793,
25,
198,
220,
220,
220,
374,
37811,
5990,
984,
723,
2994,
422,
1058,
66,
578,
25,
63,
43,
54,
5304,
44646,
628,
220,
220,
220,
943,
14542,
25,
198,
220,
220,
220,
220,
220,
220,
220,
4114,
62,
37266,
25,
14645,
262,
4069,
290,
8718,
12,
17143,
7307,
1022,
262,
4941,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
7822,
286,
262,
2656,
7035,
290,
644,
318,
3417,
287,
262,
3348,
13,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1114,
3307,
766,
1058,
5420,
25,
63,
1456,
1279,
4528,
62,
86,
392,
62,
5304,
12,
23928,
62,
37266,
29,
44646,
198,
220,
220,
220,
220,
220,
220,
220,
5021,
62,
29289,
62,
12685,
12342,
25,
37123,
13363,
5021,
12,
29289,
2207,
12342,
13,
1002,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
22532,
11,
1058,
20786,
25,
63,
93,
9078,
11268,
258,
62,
40491,
13,
4528,
62,
86,
392,
62,
5304,
13,
41684,
62,
29289,
62,
12685,
12342,
63,
318,
973,
13,
198,
220,
220,
220,
220,
220,
220,
220,
8718,
62,
17143,
7307,
25,
15079,
10007,
13,
1002,
22532,
11,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1058,
20786,
25,
63,
93,
9078,
11268,
258,
62,
40491,
13,
4528,
62,
86,
392,
62,
5304,
13,
49229,
62,
17143,
7307,
63,
318,
973,
13,
628,
220,
220,
220,
11485,
766,
14508,
3712,
628,
220,
220,
220,
220,
220,
220,
220,
532,
1058,
20786,
25,
63,
9078,
11268,
258,
62,
40491,
13,
4528,
62,
86,
392,
62,
5304,
13,
11299,
62,
22462,
63,
198,
220,
220,
220,
220,
220,
220,
220,
532,
1058,
20786,
25,
63,
9078,
11268,
258,
62,
40491,
13,
4528,
62,
86,
392,
62,
5304,
13,
7635,
62,
22462,
63,
198,
220,
220,
220,
220,
220,
220,
220,
532,
1058,
20786,
25,
63,
9078,
11268,
258,
62,
40491,
13,
4528,
62,
86,
392,
62,
5304,
13,
16338,
1634,
63,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
611,
5021,
62,
29289,
62,
12685,
12342,
318,
6045,
25,
198,
220,
220,
220,
220,
220,
220,
220,
5021,
62,
29289,
62,
12685,
12342,
796,
4808,
41684,
62,
29289,
62,
12685,
12342,
3419,
628,
220,
220,
220,
611,
8718,
62,
17143,
7307,
318,
6045,
25,
198,
220,
220,
220,
220,
220,
220,
220,
8718,
62,
17143,
7307,
796,
4808,
49229,
62,
17143,
7307,
3419,
628,
220,
220,
220,
1441,
2994,
13,
5990,
984,
723,
43,
793,
7,
198,
220,
220,
220,
220,
220,
220,
220,
2695,
62,
22462,
7,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
4114,
62,
37266,
28,
23928,
62,
37266,
11,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
5021,
62,
29289,
62,
12685,
12342,
28,
41684,
62,
29289,
62,
12685,
12342,
11,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
8718,
62,
17143,
7307,
28,
49229,
62,
17143,
7307,
11,
198,
220,
220,
220,
220,
220,
220,
220,
10612,
198,
220,
220,
220,
220,
220,
220,
220,
3918,
62,
22462,
7,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
4114,
62,
37266,
28,
23928,
62,
37266,
11,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
5021,
62,
29289,
62,
12685,
12342,
28,
41684,
62,
29289,
62,
12685,
12342,
11,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
8718,
62,
17143,
7307,
28,
49229,
62,
17143,
7307,
11,
198,
220,
220,
220,
220,
220,
220,
220,
10612,
198,
220,
220,
220,
220,
220,
220,
220,
3218,
1634,
7,
23928,
62,
37266,
28,
23928,
62,
37266,
11,
8718,
62,
17143,
7307,
28,
49229,
62,
17143,
7307,
828,
198,
220,
220,
220,
1267,
198
] | 2.511022 | 2,994 |
# -*- coding: utf-8 -*-
# (c) 2017-2019, ETH Zurich, Institut fuer Theoretische Physik
# Author: Dominik Gresch <greschd@gmx.ch>
"""
Configuration file for the pytest tests.
"""
import os
import json
import pytest
import numpy as np
import bands_inspect as bi
import parameters # pylint: disable=wrong-import-order
#--------------------------FIXTURES-------------------------------------#
@pytest.fixture
def test_name(request):
"""Returns module_name.function_name for a given test"""
return request.module.__name__ + '/' + request._parent_request._pyfuncitem.name # pylint: disable=protected-access
@pytest.fixture
def compare_data(request, test_name, scope="session"): # pylint: disable=unused-argument,redefined-outer-name
"""Returns a function which either saves some data to a file or (if that file exists already) compares it to pre-existing data using a given comparison function."""
return inner
@pytest.fixture
def compare_equal(compare_data): # pylint: disable=redefined-outer-name
"""
Returns a function which checks that a given data is equal to the stored reference.
"""
return lambda data, tag=None: compare_data(lambda x, y: x == y, data, tag)
@pytest.fixture
def assert_equal():
"""
Returns a function which checks that two bands-inspect object instances are equal.
"""
return inner
@pytest.fixture
def sample():
"""
Returns the absolute path of the sample with a given name.
"""
return inner
| [
2,
532,
9,
12,
19617,
25,
3384,
69,
12,
23,
532,
9,
12,
198,
198,
2,
357,
66,
8,
2177,
12,
23344,
11,
35920,
43412,
11,
37931,
315,
14035,
263,
383,
9997,
46097,
8687,
1134,
198,
2,
6434,
25,
11817,
1134,
402,
411,
354,
1279,
34239,
354,
67,
31,
70,
36802,
13,
354,
29,
198,
37811,
198,
38149,
2393,
329,
262,
12972,
9288,
5254,
13,
198,
37811,
198,
198,
11748,
28686,
198,
11748,
33918,
198,
198,
11748,
12972,
9288,
198,
11748,
299,
32152,
355,
45941,
198,
198,
11748,
11760,
62,
1040,
806,
355,
3182,
198,
198,
11748,
10007,
220,
1303,
279,
2645,
600,
25,
15560,
28,
36460,
12,
11748,
12,
2875,
198,
198,
2,
22369,
438,
47084,
51,
29514,
3880,
30934,
2,
628,
198,
31,
9078,
9288,
13,
69,
9602,
198,
4299,
1332,
62,
3672,
7,
25927,
2599,
198,
220,
220,
220,
37227,
35561,
8265,
62,
3672,
13,
8818,
62,
3672,
329,
257,
1813,
1332,
37811,
198,
220,
220,
220,
1441,
2581,
13,
21412,
13,
834,
3672,
834,
1343,
31051,
6,
1343,
2581,
13557,
8000,
62,
25927,
13557,
9078,
20786,
9186,
13,
3672,
220,
1303,
279,
2645,
600,
25,
15560,
28,
24326,
12,
15526,
628,
198,
31,
9078,
9288,
13,
69,
9602,
198,
4299,
8996,
62,
7890,
7,
25927,
11,
1332,
62,
3672,
11,
8354,
2625,
29891,
1,
2599,
220,
1303,
279,
2645,
600,
25,
15560,
28,
403,
1484,
12,
49140,
11,
445,
18156,
12,
39605,
12,
3672,
198,
220,
220,
220,
37227,
35561,
257,
2163,
543,
2035,
16031,
617,
1366,
284,
257,
2393,
393,
357,
361,
326,
2393,
7160,
1541,
8,
23008,
340,
284,
662,
12,
25687,
1366,
1262,
257,
1813,
7208,
2163,
526,
15931,
628,
220,
220,
220,
1441,
8434,
628,
198,
31,
9078,
9288,
13,
69,
9602,
198,
4299,
8996,
62,
40496,
7,
5589,
533,
62,
7890,
2599,
220,
1303,
279,
2645,
600,
25,
15560,
28,
445,
18156,
12,
39605,
12,
3672,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
16409,
257,
2163,
543,
8794,
326,
257,
1813,
1366,
318,
4961,
284,
262,
8574,
4941,
13,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
1441,
37456,
1366,
11,
7621,
28,
14202,
25,
8996,
62,
7890,
7,
50033,
2124,
11,
331,
25,
2124,
6624,
331,
11,
1366,
11,
7621,
8,
628,
198,
31,
9078,
9288,
13,
69,
9602,
198,
4299,
6818,
62,
40496,
33529,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
16409,
257,
2163,
543,
8794,
326,
734,
11760,
12,
1040,
806,
2134,
10245,
389,
4961,
13,
198,
220,
220,
220,
37227,
628,
220,
220,
220,
1441,
8434,
628,
198,
31,
9078,
9288,
13,
69,
9602,
198,
4299,
6291,
33529,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
16409,
262,
4112,
3108,
286,
262,
6291,
351,
257,
1813,
1438,
13,
198,
220,
220,
220,
37227,
628,
220,
220,
220,
1441,
8434,
198
] | 3.191898 | 469 |
import os
# import tensorflow as tf
import tensorrt as trt
from tensorrt.parsers import uffparser
import pycuda.driver as cuda
# import uff
import cv2
import numpy as np
from tqdm import tqdm
TEST_PATH = "/media/andy/Data/DevWorkSpace/Projects/imageClassifier/data/test/"
LABEL = 0
ENGINE_PATH = "/home/andy/caffe/examples/mydata/slot_classifier/engine/px2_classifier.engine"
NET_INPUT_SHAPE = (256, 256)
NET_OUTPUT_SHAPE = 5
class_labels = ['error', 'half', 'invlb', 'invls', 'valid']
# Load Image
imgTestData = test_Loader(TEST_PATH, NET_INPUT_SHAPE)
# Load Engine file
G_LOGGER = trt.infer.ConsoleLogger(trt.infer.LogSeverity.ERROR)
engine = trt.utils.load_engine(G_LOGGER, ENGINE_PATH)
context = engine.create_execution_context()
runtime = trt.infer.create_infer_runtime(G_LOGGER)
# output = np.empty(1, dtype = np.float32)
# # Alocate device memory
# d_input = cuda.mem_alloc(1 * imgTestData[0][0][0].nbytes)
# d_output = cuda.mem_alloc(NET_OUTPUT_SHAPE * output.nbytes)
# bindings = [int(d_input), int(d_output)]
# stream = cuda.Stream()
predicts = []
pair = imgTestData[0]
for img, label in pair:
output = np.empty(NET_OUTPUT_SHAPE, dtype = np.float32)
# Alocate device memory
d_input = cuda.mem_alloc(1 * img.nbytes)
d_output = cuda.mem_alloc(1 * output.nbytes)
bindings = [int(d_input), int(d_output)]
stream = cuda.Stream()
# Transfer input data to device
cuda.memcpy_htod_async(d_input, img, stream)
# Execute model
context.enqueue(1, bindings, stream.handle, None)
# Transfer predictions back
cuda.memcpy_dtoh_async(output, d_output, stream)
# Syncronize threads
stream.synchronize()
softmax = np.exp(output) / np.sum(np.exp(output))
predict = np.argmax(softmax)
predicts.append(predict)
print("True = ",label, ", predict = ", predict, ", softmax = ", softmax)
grandTrue = np.array(imgTestData[1][1])
predicts = np.array(predicts)
error = predicts[predicts!=grandTrue]
print(imgTestData[1][1])
print("-------")
print(predicts)
print("-------")
print(len(error))
print((len(imgTestData[0])-len(error))/len(imgTestData[0])) | [
11748,
28686,
198,
2,
1330,
11192,
273,
11125,
355,
48700,
198,
11748,
11192,
273,
17034,
355,
491,
83,
198,
6738,
11192,
273,
17034,
13,
79,
945,
364,
1330,
334,
487,
48610,
198,
11748,
12972,
66,
15339,
13,
26230,
355,
269,
15339,
198,
2,
1330,
334,
487,
198,
11748,
269,
85,
17,
198,
11748,
299,
32152,
355,
45941,
198,
6738,
256,
80,
36020,
1330,
256,
80,
36020,
628,
198,
198,
51,
6465,
62,
34219,
796,
12813,
11431,
14,
10757,
14,
6601,
14,
13603,
12468,
14106,
14,
16775,
82,
14,
9060,
9487,
7483,
14,
7890,
14,
9288,
30487,
198,
48780,
3698,
796,
657,
198,
26808,
8881,
62,
34219,
796,
12813,
11195,
14,
10757,
14,
66,
21223,
14,
1069,
12629,
14,
1820,
7890,
14,
43384,
62,
4871,
7483,
14,
18392,
14,
8416,
17,
62,
4871,
7483,
13,
18392,
1,
198,
12884,
62,
1268,
30076,
62,
9693,
45721,
796,
357,
11645,
11,
17759,
8,
198,
12884,
62,
2606,
7250,
3843,
62,
9693,
45721,
796,
642,
198,
4871,
62,
23912,
1424,
796,
37250,
18224,
3256,
705,
13959,
3256,
705,
16340,
23160,
3256,
705,
16340,
7278,
3256,
705,
12102,
20520,
198,
198,
2,
8778,
7412,
628,
198,
9600,
14402,
6601,
796,
1332,
62,
17401,
7,
51,
6465,
62,
34219,
11,
30502,
62,
1268,
30076,
62,
9693,
45721,
8,
198,
198,
2,
8778,
7117,
2393,
198,
38,
62,
25294,
30373,
796,
491,
83,
13,
259,
2232,
13,
47581,
11187,
1362,
7,
2213,
83,
13,
259,
2232,
13,
11187,
50,
964,
414,
13,
24908,
8,
198,
18392,
796,
491,
83,
13,
26791,
13,
2220,
62,
18392,
7,
38,
62,
25294,
30373,
11,
36924,
8881,
62,
34219,
8,
198,
22866,
796,
3113,
13,
17953,
62,
18558,
1009,
62,
22866,
3419,
198,
43282,
796,
491,
83,
13,
259,
2232,
13,
17953,
62,
259,
2232,
62,
43282,
7,
38,
62,
25294,
30373,
8,
198,
198,
2,
5072,
796,
45941,
13,
28920,
7,
16,
11,
288,
4906,
796,
45941,
13,
22468,
2624,
8,
198,
198,
2,
1303,
978,
13369,
3335,
4088,
198,
2,
288,
62,
15414,
796,
269,
15339,
13,
11883,
62,
32332,
7,
16,
1635,
33705,
14402,
6601,
58,
15,
7131,
15,
7131,
15,
4083,
77,
33661,
8,
198,
2,
288,
62,
22915,
796,
269,
15339,
13,
11883,
62,
32332,
7,
12884,
62,
2606,
7250,
3843,
62,
9693,
45721,
1635,
5072,
13,
77,
33661,
8,
198,
198,
2,
34111,
796,
685,
600,
7,
67,
62,
15414,
828,
493,
7,
67,
62,
22915,
15437,
198,
198,
2,
4269,
796,
269,
15339,
13,
12124,
3419,
198,
198,
28764,
14137,
796,
17635,
198,
24874,
796,
33705,
14402,
6601,
58,
15,
60,
198,
1640,
33705,
11,
6167,
287,
5166,
25,
198,
220,
220,
220,
5072,
796,
45941,
13,
28920,
7,
12884,
62,
2606,
7250,
3843,
62,
9693,
45721,
11,
288,
4906,
796,
45941,
13,
22468,
2624,
8,
628,
220,
220,
220,
1303,
978,
13369,
3335,
4088,
198,
220,
220,
220,
288,
62,
15414,
796,
269,
15339,
13,
11883,
62,
32332,
7,
16,
1635,
33705,
13,
77,
33661,
8,
198,
220,
220,
220,
288,
62,
22915,
796,
269,
15339,
13,
11883,
62,
32332,
7,
16,
1635,
5072,
13,
77,
33661,
8,
628,
220,
220,
220,
34111,
796,
685,
600,
7,
67,
62,
15414,
828,
493,
7,
67,
62,
22915,
15437,
628,
220,
220,
220,
4269,
796,
269,
15339,
13,
12124,
3419,
198,
220,
220,
220,
1303,
20558,
5128,
1366,
284,
3335,
198,
220,
220,
220,
269,
15339,
13,
11883,
66,
9078,
62,
4352,
375,
62,
292,
13361,
7,
67,
62,
15414,
11,
33705,
11,
4269,
8,
198,
220,
220,
220,
1303,
8393,
1133,
2746,
220,
198,
220,
220,
220,
4732,
13,
268,
36560,
7,
16,
11,
34111,
11,
4269,
13,
28144,
11,
6045,
8,
198,
220,
220,
220,
1303,
20558,
16277,
736,
198,
220,
220,
220,
269,
15339,
13,
11883,
66,
9078,
62,
28664,
1219,
62,
292,
13361,
7,
22915,
11,
288,
62,
22915,
11,
4269,
8,
198,
220,
220,
220,
1303,
35908,
1313,
1096,
14390,
198,
220,
220,
220,
4269,
13,
28869,
11413,
1096,
3419,
628,
220,
220,
220,
2705,
9806,
796,
45941,
13,
11201,
7,
22915,
8,
1220,
45941,
13,
16345,
7,
37659,
13,
11201,
7,
22915,
4008,
198,
220,
220,
220,
4331,
796,
45941,
13,
853,
9806,
7,
4215,
9806,
8,
198,
220,
220,
220,
26334,
13,
33295,
7,
79,
17407,
8,
628,
220,
220,
220,
3601,
7203,
17821,
796,
33172,
18242,
11,
33172,
4331,
796,
33172,
4331,
11,
33172,
2705,
9806,
796,
33172,
2705,
9806,
8,
628,
198,
23936,
17821,
796,
45941,
13,
18747,
7,
9600,
14402,
6601,
58,
16,
7131,
16,
12962,
198,
28764,
14137,
796,
45941,
13,
18747,
7,
28764,
14137,
8,
198,
18224,
796,
26334,
58,
28764,
14137,
0,
28,
23936,
17821,
60,
198,
198,
4798,
7,
9600,
14402,
6601,
58,
16,
7131,
16,
12962,
198,
4798,
7203,
26866,
4943,
198,
4798,
7,
28764,
14137,
8,
198,
4798,
7203,
26866,
4943,
198,
4798,
7,
11925,
7,
18224,
4008,
198,
4798,
19510,
11925,
7,
9600,
14402,
6601,
58,
15,
12962,
12,
11925,
7,
18224,
4008,
14,
11925,
7,
9600,
14402,
6601,
58,
15,
60,
4008
] | 2.546108 | 835 |
import filters
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import freqz
from sklearn.neural_network import MLPRegressor
if __name__ == "__main__":
# Create a random dataset
# [fc, bandwidth, gain]
n = 100
filtersNum = 1
X, Y = genXY(n=n, filtersNum=filtersNum)
# Fit regression model
regr = MLPRegressor(hidden_layer_sizes=(10,), max_iter=10000)
regr.fit(X, Y)
print('train loss', regr.loss_)
# Predict
X_test, Y_test = genXY(n=n, filtersNum=filtersNum)
print('test loss', ((Y_test - regr.predict(X_test)) ** 2).mean())
# paras = [(1e4, 2500, 3), (300, 201, 10), (400, 600, 5), (600, 200, 8),
# (2000, 3500, 13), (6000, 4000, 3), (8500, 6000, 2.75),]
paras = [(1e4, 2500, 3),]
f, db = filterModel(paras)
plt.semilogx(f, db, label="target", color='red')
y_pred = regr.predict([db])
f, db = filterModel(y_pred.reshape(filtersNum, 3))
plt.semilogx(f, db, label="NN")
plt.legend()
plt.show() | [
11748,
16628,
201,
198,
11748,
299,
32152,
355,
45941,
201,
198,
11748,
2603,
29487,
8019,
13,
9078,
29487,
355,
458,
83,
201,
198,
6738,
629,
541,
88,
13,
12683,
282,
1330,
2030,
80,
89,
201,
198,
6738,
1341,
35720,
13,
710,
1523,
62,
27349,
1330,
10373,
4805,
1533,
44292,
201,
198,
220,
220,
220,
220,
201,
198,
220,
220,
220,
220,
201,
198,
201,
198,
361,
11593,
3672,
834,
6624,
366,
834,
12417,
834,
1298,
201,
198,
220,
220,
220,
1303,
13610,
257,
4738,
27039,
201,
198,
220,
220,
220,
1303,
685,
16072,
11,
19484,
11,
4461,
60,
201,
198,
220,
220,
220,
299,
796,
1802,
201,
198,
220,
220,
220,
16628,
33111,
796,
352,
201,
198,
201,
198,
220,
220,
220,
1395,
11,
575,
796,
2429,
34278,
7,
77,
28,
77,
11,
16628,
33111,
28,
10379,
1010,
33111,
8,
201,
198,
201,
198,
220,
220,
220,
1303,
25048,
20683,
2746,
201,
198,
220,
220,
220,
842,
81,
796,
10373,
4805,
1533,
44292,
7,
30342,
62,
29289,
62,
82,
4340,
16193,
940,
11,
828,
3509,
62,
2676,
28,
49388,
8,
201,
198,
220,
220,
220,
842,
81,
13,
11147,
7,
55,
11,
575,
8,
201,
198,
220,
220,
220,
3601,
10786,
27432,
2994,
3256,
842,
81,
13,
22462,
62,
8,
201,
198,
201,
198,
220,
220,
220,
1303,
49461,
201,
198,
220,
220,
220,
1395,
62,
9288,
11,
575,
62,
9288,
796,
2429,
34278,
7,
77,
28,
77,
11,
16628,
33111,
28,
10379,
1010,
33111,
8,
201,
198,
220,
220,
220,
3601,
10786,
9288,
2994,
3256,
14808,
56,
62,
9288,
532,
842,
81,
13,
79,
17407,
7,
55,
62,
9288,
4008,
12429,
362,
737,
32604,
28955,
201,
198,
220,
220,
220,
220,
201,
198,
220,
220,
220,
1303,
17850,
796,
47527,
16,
68,
19,
11,
33507,
11,
513,
828,
357,
6200,
11,
580,
11,
838,
828,
357,
7029,
11,
10053,
11,
642,
828,
357,
8054,
11,
939,
11,
807,
828,
220,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1303,
357,
11024,
11,
3439,
405,
11,
1511,
828,
357,
43434,
11,
30123,
11,
513,
828,
357,
23,
4059,
11,
39064,
11,
362,
13,
2425,
828,
60,
201,
198,
220,
220,
220,
17850,
796,
47527,
16,
68,
19,
11,
33507,
11,
513,
828,
60,
201,
198,
220,
220,
220,
277,
11,
20613,
796,
8106,
17633,
7,
1845,
292,
8,
201,
198,
220,
220,
220,
458,
83,
13,
325,
25433,
519,
87,
7,
69,
11,
20613,
11,
6167,
2625,
16793,
1600,
3124,
11639,
445,
11537,
201,
198,
220,
220,
220,
220,
201,
198,
220,
220,
220,
331,
62,
28764,
796,
842,
81,
13,
79,
17407,
26933,
9945,
12962,
220,
220,
220,
220,
201,
198,
220,
220,
220,
277,
11,
20613,
796,
8106,
17633,
7,
88,
62,
28764,
13,
3447,
1758,
7,
10379,
1010,
33111,
11,
513,
4008,
201,
198,
220,
220,
220,
458,
83,
13,
325,
25433,
519,
87,
7,
69,
11,
20613,
11,
6167,
2625,
6144,
4943,
201,
198,
220,
220,
220,
220,
201,
198,
220,
220,
220,
458,
83,
13,
1455,
437,
3419,
201,
198,
220,
220,
220,
458,
83,
13,
12860,
3419
] | 2.078998 | 519 |
import torch.distributed as dist
import torch
def synchronize():
"""
Helper function to synchronize (barrier) among all processes when
using distributed training
"""
if not dist.is_available():
return
if not dist.is_initialized():
return
world_size = dist.get_world_size()
if world_size == 1:
return
dist.barrier() | [
11748,
28034,
13,
17080,
6169,
355,
1233,
198,
11748,
28034,
198,
198,
4299,
18305,
1096,
33529,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
220,
220,
220,
5053,
525,
2163,
284,
18305,
1096,
357,
5657,
5277,
8,
1871,
477,
7767,
618,
198,
220,
220,
220,
220,
220,
220,
1262,
9387,
3047,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
611,
407,
1233,
13,
271,
62,
15182,
33529,
198,
220,
220,
220,
220,
220,
220,
220,
1441,
198,
220,
220,
220,
611,
407,
1233,
13,
271,
62,
17532,
33529,
198,
220,
220,
220,
220,
220,
220,
220,
1441,
198,
220,
220,
220,
995,
62,
7857,
796,
1233,
13,
1136,
62,
6894,
62,
7857,
3419,
198,
220,
220,
220,
611,
995,
62,
7857,
6624,
352,
25,
198,
220,
220,
220,
220,
220,
220,
220,
1441,
198,
220,
220,
220,
1233,
13,
5657,
5277,
3419
] | 2.645833 | 144 |
import json
import pymysql
import datetime
from dbutils.pooled_db import PooledDB
import pymysql
from conf.common import *
mysql_client = MysqlClient()
| [
11748,
33918,
198,
11748,
279,
4948,
893,
13976,
198,
11748,
4818,
8079,
198,
6738,
288,
4360,
4487,
13,
7742,
276,
62,
9945,
1330,
19850,
276,
11012,
198,
11748,
279,
4948,
893,
13976,
198,
198,
6738,
1013,
13,
11321,
1330,
1635,
628,
198,
198,
28744,
13976,
62,
16366,
796,
337,
893,
13976,
11792,
3419,
198
] | 2.888889 | 54 |
#!/usr/bin/env python
"""
Script to launch a VDI session (or connect to already running session)
and start a Jupyter server on the VDI
A ssh tunnel from the local machine to the VDI is set up and the local
webbrowser is spawned.
This is a python3 script (uses unicode strings). If you don't have
python3 on your local machine, try installing Miniconda3
The only external module is pexpect which may need to be installed
using conda or pip.
Usage:
- if you use a password, the script will ask for your password when needed
- if you have already set up SSH public key with Strudel, try running
$ ssh-add ~/.ssh/MassiveLauncherKey
to add your public key to the ssh key agent.
Author: James Munroe, 2017
"""
from __future__ import print_function
import re
import sys
import time
import getpass
import pexpect
import os
import configparser
# Requires future module https://pypi.org/project/future/
from builtins import input
import argparse
import logging
logging.basicConfig(format='[%(asctime)s jupyter_vdi.py] %(message)s',
datefmt='%H:%M:%S',
level=logging.INFO)
try:
import appscript
except ImportError:
import webbrowser
is_mac = False
else:
is_mac = True
DEFAULTS = {
'user' : getpass.getuser(),
'JupyterPort' : '8889',
'BokehPort' : '8787',
'execHost' : 'vdi.nci.org.au'
}
verbose = 0
config_path = os.path.expanduser('~/cosima_cookbook.conf')
parser = configparser.ConfigParser(defaults=DEFAULTS)
if os.path.exists(config_path):
logging.info('Using config file: {}'.format(config_path))
parser.read(config_path)
else:
logging.warn('No config file found. Creating default {} file.'.format(config_path))
logging.warn('*** Please edit this file as needed. ***')
while DEFAULTS['user']==getpass.getuser() or DEFAULTS['user']=="":
DEFAULTS['user']=input('What is your NCI username? ')
parser = configparser.ConfigParser(defaults=DEFAULTS)
with open(config_path, 'w') as f:
parser.write(f)
params = parser.defaults()
def ssh(cmd, params, login_timeout=10):
"""
Run a remote command via SSH
"""
clean_params(params)
cmd = ("ssh -x -l {user} {exechost} " + cmd).format(**params)
if verbose > 0: logging.info(cmd)
s = pexpect.spawn(cmd)
# SSH pexpect logic taken from pxshh:
i = s.expect(["(?i)are you sure you want to continue connecting",
"(?i)(?:password)|(?:passphrase for key)",
"(?i)permission denied",
"(?i)connection closed by remote host",
pexpect.EOF, pexpect.TIMEOUT], timeout=login_timeout)
# First phase
if i == 0:
# New certificate -- always accept it.
# This is what you get if SSH does not have the remote host's
# public key stored in the 'known_hosts' cache.
s.sendline("yes")
i = s.expect(["(?i)are you sure you want to continue connecting",
"(?i)(?:password)|(?:passphrase for key)",
"(?i)permission denied",
"(?i)connection closed by remote host",
pexpect.EOF, pexpect.TIMEOUT], timeout=login_timeout)
if i == 1: # password or passphrase
if 'password' not in params:
params['password'] = getpass.getpass('password: ')
s.sendline(params['password'])
i = s.expect(["(?i)are you sure you want to continue connecting",
"(?i)(?:password)|(?:passphrase for key)",
"(?i)permission denied",
"(?i)connection closed by remote host",
pexpect.EOF, pexpect.TIMEOUT], timeout=login_timeout)
# TODO: check if ssh connection is successful
return s
def session(func, *args, **kwargs):
"""wrapper for sending session-ctl commands"""
cmd = '/opt/vdi/bin/session-ctl --configver=20151620513 ' + func
s = ssh(cmd, *args, **kwargs)
s.close()
return s
tunnel_started = False
tunnel = None
if __name__ == "__main__":
main_argv()
| [
2,
48443,
14629,
14,
8800,
14,
24330,
21015,
198,
37811,
198,
7391,
284,
4219,
257,
569,
17931,
6246,
357,
273,
2018,
284,
1541,
2491,
6246,
8,
198,
392,
923,
257,
449,
929,
88,
353,
4382,
319,
262,
569,
17931,
198,
198,
32,
26678,
13275,
422,
262,
1957,
4572,
284,
262,
569,
17931,
318,
900,
510,
290,
262,
1957,
198,
732,
11848,
808,
2655,
318,
29013,
13,
198,
198,
1212,
318,
257,
21015,
18,
4226,
357,
2664,
28000,
1098,
13042,
737,
220,
1002,
345,
836,
470,
423,
198,
29412,
18,
319,
534,
1957,
4572,
11,
1949,
15975,
1855,
291,
13533,
18,
198,
464,
691,
7097,
8265,
318,
613,
87,
806,
543,
743,
761,
284,
307,
6589,
198,
3500,
1779,
64,
393,
7347,
13,
198,
198,
28350,
25,
198,
12,
611,
345,
779,
257,
9206,
11,
262,
4226,
481,
1265,
329,
534,
9206,
618,
2622,
198,
12,
611,
345,
423,
1541,
900,
510,
33825,
1171,
1994,
351,
4285,
463,
417,
11,
1949,
2491,
198,
220,
220,
220,
720,
26678,
12,
2860,
39763,
45824,
14,
20273,
425,
46182,
2044,
9218,
198,
220,
284,
751,
534,
1171,
1994,
284,
262,
26678,
1994,
5797,
13,
198,
198,
13838,
25,
3700,
12107,
20646,
11,
2177,
198,
37811,
198,
198,
6738,
11593,
37443,
834,
1330,
3601,
62,
8818,
198,
198,
11748,
302,
198,
11748,
25064,
198,
11748,
640,
198,
11748,
651,
6603,
198,
11748,
613,
87,
806,
198,
11748,
28686,
198,
11748,
4566,
48610,
198,
2,
26848,
2003,
8265,
3740,
1378,
79,
4464,
72,
13,
2398,
14,
16302,
14,
37443,
14,
198,
6738,
3170,
1040,
1330,
5128,
198,
11748,
1822,
29572,
198,
198,
11748,
18931,
198,
6404,
2667,
13,
35487,
16934,
7,
18982,
11639,
58,
4,
7,
292,
310,
524,
8,
82,
474,
929,
88,
353,
62,
85,
10989,
13,
9078,
60,
4064,
7,
20500,
8,
82,
3256,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
3128,
69,
16762,
11639,
4,
39,
25,
4,
44,
25,
4,
50,
3256,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1241,
28,
6404,
2667,
13,
10778,
8,
198,
28311,
25,
198,
220,
220,
220,
1330,
598,
12048,
198,
16341,
17267,
12331,
25,
198,
220,
220,
220,
1330,
3992,
40259,
198,
220,
220,
220,
318,
62,
20285,
796,
10352,
198,
17772,
25,
198,
220,
220,
220,
318,
62,
20285,
796,
6407,
198,
198,
7206,
7708,
35342,
796,
1391,
198,
220,
220,
220,
705,
7220,
6,
1058,
651,
6603,
13,
1136,
7220,
22784,
198,
220,
220,
220,
705,
41,
929,
88,
353,
13924,
6,
1058,
705,
3459,
4531,
3256,
198,
220,
220,
220,
705,
33,
2088,
71,
13924,
6,
1058,
705,
23,
41019,
3256,
198,
220,
220,
220,
705,
18558,
17932,
6,
1058,
220,
705,
85,
10989,
13,
77,
979,
13,
2398,
13,
559,
6,
198,
92,
198,
198,
19011,
577,
796,
657,
198,
198,
11250,
62,
6978,
796,
28686,
13,
6978,
13,
11201,
392,
7220,
10786,
93,
14,
6966,
8083,
62,
27916,
2070,
13,
10414,
11537,
198,
48610,
796,
4566,
48610,
13,
16934,
46677,
7,
12286,
82,
28,
7206,
7708,
35342,
8,
198,
198,
361,
28686,
13,
6978,
13,
1069,
1023,
7,
11250,
62,
6978,
2599,
198,
220,
220,
220,
18931,
13,
10951,
10786,
12814,
4566,
2393,
25,
23884,
4458,
18982,
7,
11250,
62,
6978,
4008,
198,
220,
220,
220,
30751,
13,
961,
7,
11250,
62,
6978,
8,
198,
17772,
25,
198,
220,
220,
220,
18931,
13,
40539,
10786,
2949,
4566,
2393,
1043,
13,
30481,
4277,
23884,
2393,
2637,
13,
18982,
7,
11250,
62,
6978,
4008,
198,
220,
220,
220,
18931,
13,
40539,
10786,
8162,
4222,
4370,
428,
2393,
355,
2622,
13,
17202,
11537,
198,
220,
220,
220,
981,
5550,
7708,
35342,
17816,
7220,
20520,
855,
1136,
6603,
13,
1136,
7220,
3419,
393,
5550,
7708,
35342,
17816,
7220,
20520,
855,
1,
1298,
198,
220,
220,
220,
220,
220,
220,
220,
5550,
7708,
35342,
17816,
7220,
20520,
28,
15414,
10786,
2061,
318,
534,
8823,
40,
20579,
30,
705,
8,
198,
220,
220,
220,
30751,
796,
4566,
48610,
13,
16934,
46677,
7,
12286,
82,
28,
7206,
7708,
35342,
8,
628,
220,
220,
220,
351,
1280,
7,
11250,
62,
6978,
11,
705,
86,
11537,
355,
277,
25,
198,
220,
220,
220,
220,
220,
220,
220,
30751,
13,
13564,
7,
69,
8,
198,
198,
37266,
796,
30751,
13,
12286,
82,
3419,
198,
198,
4299,
26678,
7,
28758,
11,
42287,
11,
17594,
62,
48678,
28,
940,
2599,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
5660,
257,
6569,
3141,
2884,
33825,
198,
220,
220,
220,
37227,
628,
220,
220,
220,
3424,
62,
37266,
7,
37266,
8,
628,
220,
220,
220,
23991,
796,
5855,
45824,
532,
87,
532,
75,
1391,
7220,
92,
1391,
1069,
3055,
455,
92,
366,
1343,
23991,
737,
18982,
7,
1174,
37266,
8,
198,
220,
220,
220,
611,
15942,
577,
1875,
657,
25,
18931,
13,
10951,
7,
28758,
8,
198,
220,
220,
220,
264,
796,
613,
87,
806,
13,
48183,
7,
28758,
8,
628,
220,
220,
220,
1303,
33825,
613,
87,
806,
9156,
2077,
422,
279,
87,
1477,
71,
25,
198,
220,
220,
220,
1312,
796,
264,
13,
1069,
806,
7,
14692,
7,
30,
72,
8,
533,
345,
1654,
345,
765,
284,
2555,
14320,
1600,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
30629,
30,
72,
5769,
27514,
28712,
14726,
7,
27514,
6603,
34675,
329,
1994,
42501,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
30629,
30,
72,
8,
525,
3411,
6699,
1600,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
30629,
30,
72,
8,
38659,
4838,
416,
6569,
2583,
1600,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
613,
87,
806,
13,
4720,
37,
11,
613,
87,
806,
13,
34694,
12425,
4357,
26827,
28,
38235,
62,
48678,
8,
628,
220,
220,
220,
1303,
3274,
7108,
198,
220,
220,
220,
611,
1312,
6624,
657,
25,
198,
220,
220,
220,
220,
220,
220,
220,
1303,
968,
10703,
1377,
1464,
2453,
340,
13,
198,
220,
220,
220,
220,
220,
220,
220,
1303,
770,
318,
644,
345,
651,
611,
33825,
857,
407,
423,
262,
6569,
2583,
338,
198,
220,
220,
220,
220,
220,
220,
220,
1303,
1171,
1994,
8574,
287,
262,
705,
4002,
62,
4774,
82,
6,
12940,
13,
198,
220,
220,
220,
220,
220,
220,
220,
264,
13,
21280,
1370,
7203,
8505,
4943,
198,
220,
220,
220,
220,
220,
220,
220,
1312,
796,
264,
13,
1069,
806,
7,
14692,
7,
30,
72,
8,
533,
345,
1654,
345,
765,
284,
2555,
14320,
1600,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
30629,
30,
72,
5769,
27514,
28712,
14726,
7,
27514,
6603,
34675,
329,
1994,
42501,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
30629,
30,
72,
8,
525,
3411,
6699,
1600,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
30629,
30,
72,
8,
38659,
4838,
416,
6569,
2583,
1600,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
613,
87,
806,
13,
4720,
37,
11,
613,
87,
806,
13,
34694,
12425,
4357,
26827,
28,
38235,
62,
48678,
8,
628,
220,
220,
220,
611,
1312,
6624,
352,
25,
220,
1303,
9206,
393,
1208,
34675,
198,
220,
220,
220,
220,
220,
220,
220,
611,
705,
28712,
6,
407,
287,
42287,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
42287,
17816,
28712,
20520,
796,
651,
6603,
13,
1136,
6603,
10786,
28712,
25,
705,
8,
628,
220,
220,
220,
220,
220,
220,
220,
264,
13,
21280,
1370,
7,
37266,
17816,
28712,
6,
12962,
198,
220,
220,
220,
220,
220,
220,
220,
1312,
796,
264,
13,
1069,
806,
7,
14692,
7,
30,
72,
8,
533,
345,
1654,
345,
765,
284,
2555,
14320,
1600,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
30629,
30,
72,
5769,
27514,
28712,
14726,
7,
27514,
6603,
34675,
329,
1994,
42501,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
30629,
30,
72,
8,
525,
3411,
6699,
1600,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
30629,
30,
72,
8,
38659,
4838,
416,
6569,
2583,
1600,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
613,
87,
806,
13,
4720,
37,
11,
613,
87,
806,
13,
34694,
12425,
4357,
26827,
28,
38235,
62,
48678,
8,
628,
220,
220,
220,
1303,
16926,
46,
25,
2198,
611,
26678,
4637,
318,
4388,
628,
220,
220,
220,
1441,
264,
198,
198,
4299,
6246,
7,
20786,
11,
1635,
22046,
11,
12429,
46265,
22046,
2599,
198,
220,
220,
220,
37227,
48553,
329,
7216,
6246,
12,
34168,
9729,
37811,
198,
220,
220,
220,
23991,
796,
31051,
8738,
14,
85,
10989,
14,
8800,
14,
29891,
12,
34168,
1377,
11250,
332,
28,
4626,
1433,
21261,
1485,
705,
1343,
25439,
198,
220,
220,
220,
264,
796,
26678,
7,
28758,
11,
1635,
22046,
11,
12429,
46265,
22046,
8,
198,
220,
220,
220,
264,
13,
19836,
3419,
198,
220,
220,
220,
1441,
264,
198,
198,
28286,
4954,
62,
46981,
796,
10352,
198,
28286,
4954,
796,
6045,
198,
198,
361,
11593,
3672,
834,
6624,
366,
834,
12417,
834,
1298,
628,
220,
220,
220,
1388,
62,
853,
85,
3419,
198
] | 2.474803 | 1,647 |
# -*- coding=utf-8 -*-
__all__ = [
'tiny_imagenet',
'imagewoof2',
'imagenette2'
]
import os
import torch
import torchvision
_default_batch_size = 32
_default_num_workers = 4
| [
2,
532,
9,
12,
19617,
28,
40477,
12,
23,
532,
9,
12,
198,
198,
834,
439,
834,
796,
685,
198,
220,
220,
220,
705,
44152,
62,
320,
11286,
316,
3256,
198,
220,
220,
220,
705,
48466,
413,
37711,
17,
3256,
198,
220,
220,
220,
705,
320,
11286,
5857,
17,
6,
198,
60,
198,
198,
11748,
28686,
198,
11748,
28034,
198,
11748,
28034,
10178,
198,
198,
62,
12286,
62,
43501,
62,
7857,
796,
3933,
198,
62,
12286,
62,
22510,
62,
22896,
796,
604,
628,
628,
198
] | 2.270588 | 85 |
from django.db import models
from django.contrib.auth.models import User
from django.db.models import Sum
from datetime import datetime
| [
6738,
42625,
14208,
13,
9945,
1330,
4981,
198,
6738,
42625,
14208,
13,
3642,
822,
13,
18439,
13,
27530,
1330,
11787,
198,
6738,
42625,
14208,
13,
9945,
13,
27530,
1330,
5060,
198,
6738,
4818,
8079,
1330,
4818,
8079,
628,
198
] | 3.538462 | 39 |
#!/usr/bin/env pytest
import io
import json
from os import path
from pytest import fixture, mark
from sls import App
import storyscript.hub.Hub as StoryHub
from storyhub.sdk.AutoUpdateThread import AutoUpdateThread
from tests.e2e.utils.features import parse_options
from tests.e2e.utils.fixtures import find_test_files, hub, test_dir
test_files = find_test_files(relative=True)
@fixture
# compile a story and compare its completion with the expected tree
# load a story from the file system and load its expected result file (.json)
@mark.usefixtures("patched_storyhub")
@mark.parametrize("test_file", test_files)
| [
2,
48443,
14629,
14,
8800,
14,
24330,
12972,
9288,
198,
11748,
33245,
198,
11748,
33918,
198,
6738,
28686,
1330,
3108,
198,
198,
6738,
12972,
9288,
1330,
29220,
11,
1317,
198,
198,
6738,
1017,
82,
1330,
2034,
198,
198,
11748,
1621,
12048,
13,
40140,
13,
16066,
355,
8362,
16066,
198,
6738,
1621,
40140,
13,
21282,
74,
13,
27722,
10260,
16818,
1330,
11160,
10260,
16818,
628,
198,
6738,
5254,
13,
68,
17,
68,
13,
26791,
13,
40890,
1330,
21136,
62,
25811,
198,
6738,
5254,
13,
68,
17,
68,
13,
26791,
13,
69,
25506,
1330,
1064,
62,
9288,
62,
16624,
11,
12575,
11,
1332,
62,
15908,
628,
198,
9288,
62,
16624,
796,
1064,
62,
9288,
62,
16624,
7,
43762,
28,
17821,
8,
628,
198,
31,
69,
9602,
628,
198,
2,
17632,
257,
1621,
290,
8996,
663,
11939,
351,
262,
2938,
5509,
628,
198,
2,
3440,
257,
1621,
422,
262,
2393,
1080,
290,
3440,
663,
2938,
1255,
2393,
20262,
17752,
8,
628,
198,
31,
4102,
13,
1904,
69,
25506,
7203,
8071,
1740,
62,
13571,
40140,
4943,
198,
31,
4102,
13,
17143,
316,
380,
2736,
7203,
9288,
62,
7753,
1600,
1332,
62,
16624,
8,
198
] | 3.310526 | 190 |
""" Where's My Mouse? """
import tkinter
root = tkinter.Tk()
root.bind('<Button>', mouse_click)
root.mainloop()
| [
37811,
6350,
338,
2011,
21839,
30,
37227,
201,
198,
11748,
256,
74,
3849,
201,
198,
220,
220,
220,
220,
201,
198,
15763,
796,
256,
74,
3849,
13,
51,
74,
3419,
201,
198,
15763,
13,
21653,
10786,
27,
21864,
29,
3256,
10211,
62,
12976,
8,
201,
198,
15763,
13,
12417,
26268,
3419,
201,
198
] | 2.320755 | 53 |
from dataclasses import dataclass
from enum import Enum
from typing import Callable, Dict, Final, Optional, Type, Union
from botx import Bot, Collector, Message
from botx.concurrency import callable_to_coroutine
from botx.middlewares.base import BaseMiddleware
from botx.typing import Executor
_default_transition: Final = object()
@dataclass
| [
6738,
4818,
330,
28958,
1330,
4818,
330,
31172,
198,
6738,
33829,
1330,
2039,
388,
198,
6738,
19720,
1330,
4889,
540,
11,
360,
713,
11,
8125,
11,
32233,
11,
5994,
11,
4479,
198,
198,
6738,
10214,
87,
1330,
18579,
11,
17573,
11,
16000,
198,
6738,
10214,
87,
13,
1102,
34415,
1330,
869,
540,
62,
1462,
62,
10215,
28399,
198,
6738,
10214,
87,
13,
27171,
86,
3565,
13,
8692,
1330,
7308,
34621,
1574,
198,
6738,
10214,
87,
13,
774,
13886,
1330,
8393,
38409,
198,
198,
62,
12286,
62,
7645,
653,
25,
8125,
796,
2134,
3419,
628,
198,
31,
19608,
330,
31172,
628,
628,
198
] | 3.441176 | 102 |
#!/usr/bin/env python
'''
This program attempts to convert XPLOR Pseudocontact shift restraints in AMBER format
XPLOR:
assign ( resid 200 and name OO ) ( resid 200 and name Z ) ( resid 200 and name X ) (resid 200 and name Y ) ( resid 13 and name C ) 0.2400 0.2000
assign ( resid 200 and name OO ) ( resid 200 and name Z ) ( resid 200 and name X ) ( resid 200 and name Y ) ( resid 13 and name CA ) 0.4300 0.2000
assign ( resid 200 and name OO ) ( resid 200 and name Z ) ( resid 200 and name X ) ( resid 200 and name Y )( resid 13 and name CB ) 0.1000 0.2000
AMBER:
&align
num_datasets=2,
dcut= -1.0, freezemol= .false.,
ndip= 10, dwt= 5*0.1, 5*0.1
gigj= 5*-3.1631,5*-3.1631,
dij= 5*1.041,5*1.041,
s11= -4.236,-4.236
s12= 56.860,56.860
s13= -34.696,-34.696
s22= -27.361,-27.361
s23= -12.867,-12.867
dataset=1,
id(1)=20, jd(1)=19, dobsl(1)=-2.13, dobsu(1)=-2.13,
id(2)=31, jd(2)=30, dobsl(2)= 1.10, dobsu(2)= 1.10,
id(3)=43, jd(3)=42, dobsl(3)=-5.54, dobsu(3)=-5.54,
...
...
&end
'''
import sys
import os
import commands
from optparse import OptionParser
from xml_parser import *
from normalize_tbl import normalize
from constants import convtable
if __name__ == '__main__':
usage = "usage: %prog -w working_directory -p pdb_filename -o out_filename"
parser = OptionParser(usage)
parser.add_option("-w", "--wdir", dest="wd",
help="Working directory", metavar="WORKDIR")
parser.add_option("-p", "--pdbfile", dest="pdbfile",
help="PDB filename", metavar="FILE")
parser.add_option("-o", "--outfile", dest="outfile",
help="Output filename", metavar="FILE")
(options, args) = parser.parse_args()
if not options.wd:
parser.error("Working directory is required")
wd=os.path.abspath(options.wd)+'/'
if options.pdbfile:
pdbfile=os.path.join(wd, options.pdbfile)
else:
parser.error("PDB filename is required")
if options.outfile:
outfile=os.path.join(wd, options.outfile)
else:
parser.error("Output filename is required")
xml_input=os.path.join(wd,'input.xml')
doc = etree.parse(xml_input)
ndoc = etree.tostring(doc)
new=parse_node(etree.fromstring(ndoc))
out=convert(pdbfile, new, wd)
fout=open(outfile,'w')
fout.writelines(out)
fout.close() | [
2,
48443,
14629,
14,
8800,
14,
24330,
21015,
198,
7061,
6,
198,
1212,
1430,
6370,
284,
10385,
1395,
6489,
1581,
49693,
463,
420,
756,
529,
6482,
45369,
287,
3001,
13246,
5794,
198,
55,
6489,
1581,
25,
198,
562,
570,
357,
15384,
939,
220,
290,
1438,
440,
46,
1267,
357,
15384,
939,
220,
290,
1438,
1168,
1267,
357,
15384,
939,
220,
290,
1438,
1395,
1267,
357,
411,
312,
939,
220,
290,
1438,
575,
1267,
357,
15384,
220,
1511,
220,
290,
1438,
327,
1267,
220,
220,
657,
13,
1731,
405,
220,
657,
13,
11024,
220,
198,
562,
570,
357,
15384,
939,
220,
290,
1438,
440,
46,
1267,
357,
15384,
939,
220,
290,
1438,
1168,
1267,
357,
15384,
939,
220,
290,
1438,
1395,
1267,
357,
15384,
939,
220,
290,
1438,
575,
1267,
357,
15384,
220,
1511,
220,
290,
1438,
7257,
1267,
657,
13,
3559,
405,
220,
657,
13,
11024,
220,
198,
562,
570,
357,
15384,
939,
220,
290,
1438,
440,
46,
1267,
357,
15384,
939,
220,
290,
1438,
1168,
1267,
357,
15384,
939,
220,
290,
1438,
1395,
1267,
357,
220,
15384,
939,
220,
290,
1438,
575,
1267,
7,
15384,
220,
1511,
220,
290,
1438,
10078,
1267,
657,
13,
12825,
220,
657,
13,
11024,
220,
628,
198,
2390,
13246,
25,
198,
5,
31494,
198,
22510,
62,
19608,
292,
1039,
28,
17,
11,
198,
220,
220,
288,
8968,
28,
532,
16,
13,
15,
11,
1479,
89,
368,
349,
28,
764,
9562,
1539,
628,
220,
220,
299,
67,
541,
28,
838,
11,
43756,
83,
28,
642,
9,
15,
13,
16,
11,
642,
9,
15,
13,
16,
198,
220,
220,
12526,
73,
28,
642,
9,
12,
18,
13,
1433,
3132,
11,
20,
9,
12,
18,
13,
1433,
3132,
11,
198,
220,
220,
2566,
73,
28,
642,
9,
16,
13,
50049,
11,
20,
9,
16,
13,
50049,
11,
198,
220,
264,
1157,
28,
532,
19,
13,
24940,
12095,
19,
13,
24940,
198,
220,
264,
1065,
28,
7265,
13,
45039,
11,
3980,
13,
45039,
198,
220,
264,
1485,
28,
532,
2682,
13,
38205,
12095,
2682,
13,
38205,
198,
220,
264,
1828,
28,
532,
1983,
13,
35195,
12095,
1983,
13,
35195,
198,
220,
264,
1954,
28,
532,
1065,
13,
23,
3134,
12095,
1065,
13,
23,
3134,
198,
220,
220,
198,
220,
27039,
28,
16,
11,
198,
220,
220,
4686,
7,
16,
47505,
1238,
11,
474,
67,
7,
16,
47505,
1129,
11,
466,
1443,
75,
7,
16,
8,
10779,
17,
13,
1485,
11,
466,
1443,
84,
7,
16,
8,
10779,
17,
13,
1485,
11,
198,
220,
220,
4686,
7,
17,
47505,
3132,
11,
474,
67,
7,
17,
47505,
1270,
11,
466,
1443,
75,
7,
17,
47505,
352,
13,
940,
11,
466,
1443,
84,
7,
17,
47505,
352,
13,
940,
11,
198,
220,
220,
4686,
7,
18,
47505,
3559,
11,
474,
67,
7,
18,
47505,
3682,
11,
466,
1443,
75,
7,
18,
8,
10779,
20,
13,
4051,
11,
466,
1443,
84,
7,
18,
8,
10779,
20,
13,
4051,
11,
198,
220,
220,
2644,
198,
220,
220,
2644,
198,
5,
437,
198,
7061,
6,
198,
198,
11748,
25064,
198,
11748,
28686,
198,
11748,
9729,
198,
6738,
2172,
29572,
1330,
16018,
46677,
198,
6738,
35555,
62,
48610,
1330,
1635,
198,
6738,
3487,
1096,
62,
83,
2436,
1330,
3487,
1096,
198,
6738,
38491,
1330,
3063,
11487,
198,
198,
361,
11593,
3672,
834,
6624,
705,
834,
12417,
834,
10354,
198,
220,
220,
220,
198,
220,
220,
220,
8748,
796,
366,
26060,
25,
4064,
1676,
70,
532,
86,
1762,
62,
34945,
220,
532,
79,
279,
9945,
62,
34345,
532,
78,
503,
62,
34345,
1,
198,
220,
220,
198,
220,
220,
220,
30751,
796,
16018,
46677,
7,
26060,
8,
198,
220,
220,
220,
30751,
13,
2860,
62,
18076,
7203,
12,
86,
1600,
366,
438,
86,
15908,
1600,
2244,
2625,
16993,
1600,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1037,
2625,
28516,
8619,
1600,
1138,
615,
283,
2625,
33249,
34720,
4943,
198,
220,
220,
198,
220,
220,
220,
220,
198,
220,
220,
220,
30751,
13,
2860,
62,
18076,
7203,
12,
79,
1600,
366,
438,
79,
9945,
7753,
1600,
2244,
2625,
79,
9945,
7753,
1600,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1037,
2625,
5760,
33,
29472,
1600,
1138,
615,
283,
2625,
25664,
4943,
198,
220,
220,
198,
220,
220,
220,
30751,
13,
2860,
62,
18076,
7203,
12,
78,
1600,
366,
438,
448,
7753,
1600,
2244,
2625,
448,
7753,
1600,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1037,
2625,
26410,
29472,
1600,
1138,
615,
283,
2625,
25664,
4943,
198,
220,
220,
198,
220,
220,
220,
357,
25811,
11,
26498,
8,
796,
30751,
13,
29572,
62,
22046,
3419,
198,
220,
220,
220,
220,
198,
220,
220,
220,
220,
220,
220,
220,
220,
198,
220,
220,
220,
611,
407,
3689,
13,
16993,
25,
198,
220,
220,
220,
220,
220,
220,
220,
30751,
13,
18224,
7203,
28516,
8619,
318,
2672,
4943,
198,
220,
220,
220,
220,
198,
220,
220,
220,
266,
67,
28,
418,
13,
6978,
13,
397,
2777,
776,
7,
25811,
13,
16993,
47762,
26488,
6,
198,
220,
220,
220,
220,
198,
220,
220,
220,
611,
3689,
13,
79,
9945,
7753,
25,
198,
220,
220,
220,
220,
220,
220,
220,
279,
9945,
7753,
28,
418,
13,
6978,
13,
22179,
7,
16993,
11,
3689,
13,
79,
9945,
7753,
8,
198,
220,
220,
220,
2073,
25,
198,
220,
220,
220,
220,
220,
220,
220,
30751,
13,
18224,
7203,
5760,
33,
29472,
318,
2672,
4943,
198,
220,
220,
220,
220,
220,
220,
220,
220,
198,
220,
220,
220,
611,
3689,
13,
448,
7753,
25,
198,
220,
220,
220,
220,
220,
220,
220,
503,
7753,
28,
418,
13,
6978,
13,
22179,
7,
16993,
11,
3689,
13,
448,
7753,
8,
198,
220,
220,
220,
2073,
25,
198,
220,
220,
220,
220,
220,
220,
220,
30751,
13,
18224,
7203,
26410,
29472,
318,
2672,
4943,
198,
220,
220,
220,
220,
198,
220,
220,
220,
220,
220,
220,
220,
220,
198,
220,
220,
220,
35555,
62,
15414,
28,
418,
13,
6978,
13,
22179,
7,
16993,
4032,
15414,
13,
19875,
11537,
198,
220,
220,
220,
2205,
796,
2123,
631,
13,
29572,
7,
19875,
62,
15414,
8,
198,
220,
220,
220,
299,
15390,
796,
2123,
631,
13,
83,
455,
1806,
7,
15390,
8,
198,
220,
220,
220,
649,
28,
29572,
62,
17440,
7,
316,
631,
13,
6738,
8841,
7,
358,
420,
4008,
198,
220,
220,
220,
503,
28,
1102,
1851,
7,
79,
9945,
7753,
11,
649,
11,
266,
67,
8,
198,
220,
220,
220,
277,
448,
28,
9654,
7,
448,
7753,
4032,
86,
11537,
198,
220,
220,
220,
277,
448,
13,
8933,
20655,
7,
448,
8,
198,
220,
220,
220,
277,
448,
13,
19836,
3419
] | 2.166078 | 1,132 |
"""Versioned body readers and writers for track message bodies.
Attributes:
LATEST_VERSION (int): Latest version supported by the library.
"""
from typing import Callable, Tuple
from . import TrackInfo, codec
LATEST_VERSION = 2
ReaderType = Callable[[codec.Reader], TrackInfo]
WriterType = Callable[[codec.Writer, TrackInfo], None]
_FORMAT_VERSIONS = {
1: (read_body_v1, write_body_v1),
2: (read_body_v2, write_body_v2),
}
def get_reader(version: int) -> ReaderType:
"""Get a body reader for the given version.
Raises:
ValueError: If the version isn't supported.
"""
return _get_format(version)[0]
def get_writer(version: int) -> WriterType:
"""Get a body writer for the given version.
Raises:
ValueError: If the version isn't supported.
"""
return _get_format(version)[1]
| [
37811,
14815,
276,
1767,
7183,
290,
8786,
329,
2610,
3275,
5920,
13,
198,
198,
29021,
25,
198,
220,
220,
220,
42355,
6465,
62,
43717,
357,
600,
2599,
26603,
2196,
4855,
416,
262,
5888,
13,
198,
37811,
198,
198,
6738,
19720,
1330,
4889,
540,
11,
309,
29291,
198,
198,
6738,
764,
1330,
17762,
12360,
11,
40481,
198,
198,
43,
1404,
6465,
62,
43717,
796,
362,
628,
628,
628,
628,
198,
33634,
6030,
796,
4889,
540,
30109,
19815,
721,
13,
33634,
4357,
17762,
12360,
60,
198,
34379,
6030,
796,
4889,
540,
30109,
19815,
721,
13,
34379,
11,
17762,
12360,
4357,
6045,
60,
198,
198,
62,
21389,
1404,
62,
28884,
11053,
796,
1391,
198,
220,
220,
220,
352,
25,
357,
961,
62,
2618,
62,
85,
16,
11,
3551,
62,
2618,
62,
85,
16,
828,
198,
220,
220,
220,
362,
25,
357,
961,
62,
2618,
62,
85,
17,
11,
3551,
62,
2618,
62,
85,
17,
828,
198,
92,
628,
198,
198,
4299,
651,
62,
46862,
7,
9641,
25,
493,
8,
4613,
25342,
6030,
25,
198,
220,
220,
220,
37227,
3855,
257,
1767,
9173,
329,
262,
1813,
2196,
13,
628,
220,
220,
220,
7567,
2696,
25,
198,
220,
220,
220,
220,
220,
220,
220,
11052,
12331,
25,
1002,
262,
2196,
2125,
470,
4855,
13,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
1441,
4808,
1136,
62,
18982,
7,
9641,
38381,
15,
60,
628,
198,
4299,
651,
62,
16002,
7,
9641,
25,
493,
8,
4613,
26606,
6030,
25,
198,
220,
220,
220,
37227,
3855,
257,
1767,
6260,
329,
262,
1813,
2196,
13,
628,
220,
220,
220,
7567,
2696,
25,
198,
220,
220,
220,
220,
220,
220,
220,
11052,
12331,
25,
1002,
262,
2196,
2125,
470,
4855,
13,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
1441,
4808,
1136,
62,
18982,
7,
9641,
38381,
16,
60,
198
] | 2.824503 | 302 |
/home/runner/.cache/pip/pool/f3/de/85/7dca1e096a43e00e6ff1ca900dda1ca91c8c5c3a1d6798e466a9173a00 | [
14,
11195,
14,
16737,
11757,
23870,
14,
79,
541,
14,
7742,
14,
69,
18,
14,
2934,
14,
5332,
14,
22,
67,
6888,
16,
68,
2931,
21,
64,
3559,
68,
405,
68,
21,
487,
16,
6888,
12865,
1860,
64,
16,
6888,
6420,
66,
23,
66,
20,
66,
18,
64,
16,
67,
3134,
4089,
68,
42199,
64,
24,
25399,
64,
405
] | 1.627119 | 59 |
"""
The Alarm Extension provides easy access to setting an application alarm to
handle timing out operations. See the
`Python Signal Library <https://docs.python.org/3.5/library/signal.html>`_.
Requirements
------------
* No external dependencies.
* Only available on Unix/Linux
Configuration
-------------
This extension does not honor any application configuration settings.
Usage
-----
.. code-block:: python
import time
from cement.core.foundation import CementApp
from cement.core.exc import CaughtSignal
class MyApp(CementApp):
class Meta:
label = 'myapp'
exit_on_close = True
extensions = ['alarm']
with MyApp() as app:
try:
app.run()
app.alarm.set(3, "The operation timed out after 3 seconds!")
# do something that takes time to operate
time.sleep(5)
app.alarm.stop()
except CaughtSignal as e:
print(e.msg)
app.exit_code = 1
Looks like:
.. code-block:: console
$ python myapp.py
ERROR: The operation timed out after 3 seconds!
Caught signal 14
"""
import signal
from ..utils.misc import minimal_logger
LOG = minimal_logger(__name__)
class AlarmManager(object):
"""
Lets the developer easily set and stop an alarm. If the
alarm exceeds the given time it will raise ``signal.SIGALRM``.
"""
def set(self, time, msg):
"""
Set the application alarm to ``time`` seconds. If the time is
exceeded ``signal.SIGALRM`` is raised.
:param time: The time in seconds to set the alarm to.
:param msg: The message to display if the alarm is triggered.
"""
LOG.debug('setting application alarm for %s seconds' % time)
self.msg = msg
signal.alarm(int(time))
def stop(self):
"""
Stop the application alarm.
"""
LOG.debug('stopping application alarm')
signal.alarm(0)
| [
37811,
198,
464,
978,
1670,
27995,
3769,
2562,
1895,
284,
4634,
281,
3586,
10436,
284,
198,
28144,
10576,
503,
4560,
13,
220,
4091,
262,
198,
63,
37906,
26484,
10074,
1279,
5450,
1378,
31628,
13,
29412,
13,
2398,
14,
18,
13,
20,
14,
32016,
14,
12683,
282,
13,
6494,
29,
63,
44807,
198,
198,
42249,
198,
10541,
628,
1635,
1400,
7097,
20086,
13,
198,
1635,
5514,
1695,
319,
33501,
14,
19314,
628,
198,
38149,
198,
32501,
198,
198,
1212,
7552,
857,
407,
7522,
597,
3586,
8398,
6460,
13,
628,
198,
28350,
198,
30934,
198,
198,
492,
2438,
12,
9967,
3712,
21015,
628,
220,
220,
220,
1330,
640,
198,
220,
220,
220,
422,
20534,
13,
7295,
13,
42526,
1330,
327,
972,
4677,
198,
220,
220,
220,
422,
20534,
13,
7295,
13,
41194,
1330,
327,
3413,
11712,
282,
628,
198,
220,
220,
220,
1398,
2011,
4677,
7,
34,
972,
4677,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
1398,
30277,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
6167,
796,
705,
1820,
1324,
6,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
8420,
62,
261,
62,
19836,
796,
6407,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
18366,
796,
37250,
282,
1670,
20520,
628,
198,
220,
220,
220,
351,
2011,
4677,
3419,
355,
598,
25,
198,
220,
220,
220,
220,
220,
220,
220,
1949,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
598,
13,
5143,
3419,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
598,
13,
282,
1670,
13,
2617,
7,
18,
11,
366,
464,
4905,
28805,
503,
706,
513,
4201,
2474,
8,
628,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1303,
466,
1223,
326,
2753,
640,
284,
8076,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
640,
13,
42832,
7,
20,
8,
628,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
598,
13,
282,
1670,
13,
11338,
3419,
628,
220,
220,
220,
220,
220,
220,
220,
2845,
327,
3413,
11712,
282,
355,
304,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
3601,
7,
68,
13,
19662,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
598,
13,
37023,
62,
8189,
796,
352,
198,
198,
41102,
588,
25,
198,
198,
492,
2438,
12,
9967,
3712,
8624,
628,
220,
220,
220,
720,
21015,
616,
1324,
13,
9078,
198,
220,
220,
220,
33854,
25,
383,
4905,
28805,
503,
706,
513,
4201,
0,
198,
220,
220,
220,
327,
3413,
6737,
1478,
198,
198,
37811,
198,
198,
11748,
6737,
198,
6738,
11485,
26791,
13,
44374,
1330,
10926,
62,
6404,
1362,
198,
198,
25294,
796,
10926,
62,
6404,
1362,
7,
834,
3672,
834,
8,
628,
198,
198,
4871,
978,
1670,
13511,
7,
15252,
2599,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
38257,
262,
8517,
3538,
900,
290,
2245,
281,
10436,
13,
220,
1002,
262,
198,
220,
220,
220,
10436,
21695,
262,
1813,
640,
340,
481,
5298,
7559,
12683,
282,
13,
50,
3528,
1847,
29138,
15506,
13,
628,
220,
220,
220,
37227,
628,
220,
220,
220,
825,
900,
7,
944,
11,
640,
11,
31456,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
37227,
198,
220,
220,
220,
220,
220,
220,
220,
5345,
262,
3586,
10436,
284,
7559,
2435,
15506,
4201,
13,
220,
1002,
262,
640,
318,
198,
220,
220,
220,
220,
220,
220,
220,
20672,
7559,
12683,
282,
13,
50,
3528,
1847,
29138,
15506,
318,
4376,
13,
628,
220,
220,
220,
220,
220,
220,
220,
1058,
17143,
640,
25,
383,
640,
287,
4201,
284,
900,
262,
10436,
284,
13,
198,
220,
220,
220,
220,
220,
220,
220,
1058,
17143,
31456,
25,
383,
3275,
284,
3359,
611,
262,
10436,
318,
13973,
13,
198,
220,
220,
220,
220,
220,
220,
220,
37227,
628,
220,
220,
220,
220,
220,
220,
220,
41605,
13,
24442,
10786,
33990,
3586,
10436,
329,
4064,
82,
4201,
6,
4064,
640,
8,
198,
220,
220,
220,
220,
220,
220,
220,
2116,
13,
19662,
796,
31456,
198,
220,
220,
220,
220,
220,
220,
220,
6737,
13,
282,
1670,
7,
600,
7,
2435,
4008,
628,
220,
220,
220,
825,
2245,
7,
944,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
37227,
198,
220,
220,
220,
220,
220,
220,
220,
13707,
262,
3586,
10436,
13,
198,
220,
220,
220,
220,
220,
220,
220,
37227,
198,
220,
220,
220,
220,
220,
220,
220,
41605,
13,
24442,
10786,
301,
33307,
3586,
10436,
11537,
198,
220,
220,
220,
220,
220,
220,
220,
6737,
13,
282,
1670,
7,
15,
8,
628
] | 2.591203 | 773 |
from meross_iot.cloud.abilities import *
from meross_iot.cloud.device import AbstractMerossDevice
from meross_iot.logger import POWER_PLUGS_LOGGER as l
from meross_iot.meross_event import DeviceSwitchStatusEvent
| [
6738,
4017,
793,
62,
5151,
13,
17721,
13,
5738,
1330,
1635,
198,
6738,
4017,
793,
62,
5151,
13,
17721,
13,
25202,
1330,
27741,
13102,
793,
24728,
198,
6738,
4017,
793,
62,
5151,
13,
6404,
1362,
1330,
40295,
62,
6489,
7340,
50,
62,
25294,
30373,
355,
300,
198,
6738,
4017,
793,
62,
5151,
13,
647,
793,
62,
15596,
1330,
16232,
38978,
19580,
9237,
628
] | 3.380952 | 63 |
from django.db.backends.mysql.introspection import *
from django.db.backends.mysql.introspection import DatabaseIntrospection as MYSQLDatabaseIntrospection
from django.utils.functional import cached_property
| [
6738,
42625,
14208,
13,
9945,
13,
1891,
2412,
13,
28744,
13976,
13,
600,
305,
31308,
1330,
1635,
198,
6738,
42625,
14208,
13,
9945,
13,
1891,
2412,
13,
28744,
13976,
13,
600,
305,
31308,
1330,
24047,
5317,
305,
31308,
355,
337,
16309,
9711,
38105,
5317,
305,
31308,
198,
6738,
42625,
14208,
13,
26791,
13,
45124,
1330,
39986,
62,
26745,
628,
628
] | 3.516667 | 60 |
import highiq
import numpy as np
| [
11748,
1029,
25011,
198,
11748,
299,
32152,
355,
45941,
628,
628,
628
] | 3.166667 | 12 |
# Base imports
import subprocess
from typing import Iterable, Optional
# Project imports
from docker import common
from docker.run import run
| [
2,
7308,
17944,
198,
11748,
850,
14681,
198,
6738,
19720,
1330,
40806,
540,
11,
32233,
198,
198,
2,
4935,
17944,
198,
6738,
36253,
1330,
2219,
198,
6738,
36253,
13,
5143,
1330,
1057,
628,
198
] | 4.264706 | 34 |
import json
import glob
import numpy as np
import os
path = "data_state_space_v3/"
out_path = "small_data/"
files = glob.glob(path + "*.npy") # ワイルドカードが使用可能
train_data_num = 100
test_data_num = 10
train_data = {}
test_data = {}
for filename in files:
obj = np.load(filename)
if filename.find("_test.npy") >= 0:
test_data[filename] = obj
else:
train_data[filename] = obj
os.makedirs(out_path, exist_ok=True)
for k, v in train_data.items():
b = os.path.basename(k)
print(b, v.shape)
o = v[:train_data_num]
np.save(out_path + b, o)
for k, v in test_data.items():
b = os.path.basename(k)
print(b, v.shape)
o = v[:test_data_num]
np.save(out_path + b, o)
fp = open(path + "pack_selected_info.json")
obj = json.load(fp)
obj["pid_list_train"] = obj["pid_list_train"][:train_data_num]
obj["pid_list_test"] = obj["pid_list_test"][:test_data_num]
fp = open(out_path + "pack_selected_info.json", "w")
json.dump(obj, fp)
| [
11748,
33918,
198,
11748,
15095,
198,
11748,
299,
32152,
355,
45941,
198,
11748,
28686,
198,
198,
6978,
796,
366,
7890,
62,
5219,
62,
13200,
62,
85,
18,
30487,
198,
448,
62,
6978,
796,
366,
17470,
62,
7890,
30487,
198,
16624,
796,
15095,
13,
4743,
672,
7,
6978,
1343,
366,
24620,
77,
9078,
4943,
220,
1303,
14524,
107,
11482,
9202,
13765,
21763,
12045,
231,
35585,
45635,
18796,
101,
20998,
107,
47797,
121,
198,
27432,
62,
7890,
62,
22510,
796,
1802,
198,
9288,
62,
7890,
62,
22510,
796,
838,
198,
27432,
62,
7890,
796,
23884,
198,
9288,
62,
7890,
796,
23884,
198,
1640,
29472,
287,
3696,
25,
198,
220,
220,
220,
26181,
796,
45941,
13,
2220,
7,
34345,
8,
198,
220,
220,
220,
611,
29472,
13,
19796,
7203,
62,
9288,
13,
77,
9078,
4943,
18189,
657,
25,
198,
220,
220,
220,
220,
220,
220,
220,
1332,
62,
7890,
58,
34345,
60,
796,
26181,
198,
220,
220,
220,
2073,
25,
198,
220,
220,
220,
220,
220,
220,
220,
4512,
62,
7890,
58,
34345,
60,
796,
26181,
198,
418,
13,
76,
4335,
17062,
7,
448,
62,
6978,
11,
2152,
62,
482,
28,
17821,
8,
198,
1640,
479,
11,
410,
287,
4512,
62,
7890,
13,
23814,
33529,
198,
220,
220,
220,
275,
796,
28686,
13,
6978,
13,
12093,
12453,
7,
74,
8,
198,
220,
220,
220,
3601,
7,
65,
11,
410,
13,
43358,
8,
198,
220,
220,
220,
267,
796,
410,
58,
25,
27432,
62,
7890,
62,
22510,
60,
198,
220,
220,
220,
45941,
13,
21928,
7,
448,
62,
6978,
1343,
275,
11,
267,
8,
198,
198,
1640,
479,
11,
410,
287,
1332,
62,
7890,
13,
23814,
33529,
198,
220,
220,
220,
275,
796,
28686,
13,
6978,
13,
12093,
12453,
7,
74,
8,
198,
220,
220,
220,
3601,
7,
65,
11,
410,
13,
43358,
8,
198,
220,
220,
220,
267,
796,
410,
58,
25,
9288,
62,
7890,
62,
22510,
60,
198,
220,
220,
220,
45941,
13,
21928,
7,
448,
62,
6978,
1343,
275,
11,
267,
8,
198,
46428,
796,
1280,
7,
6978,
1343,
366,
8002,
62,
34213,
62,
10951,
13,
17752,
4943,
198,
26801,
796,
33918,
13,
2220,
7,
46428,
8,
198,
26801,
14692,
35317,
62,
4868,
62,
27432,
8973,
796,
26181,
14692,
35317,
62,
4868,
62,
27432,
1,
7131,
25,
27432,
62,
7890,
62,
22510,
60,
198,
26801,
14692,
35317,
62,
4868,
62,
9288,
8973,
796,
26181,
14692,
35317,
62,
4868,
62,
9288,
1,
7131,
25,
9288,
62,
7890,
62,
22510,
60,
198,
46428,
796,
1280,
7,
448,
62,
6978,
1343,
366,
8002,
62,
34213,
62,
10951,
13,
17752,
1600,
366,
86,
4943,
198,
17752,
13,
39455,
7,
26801,
11,
277,
79,
8,
198
] | 2.206818 | 440 |
# https://www.hackerrank.com/challenges/three-month-preparation-kit-maxsubarray/problem
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'maxSubarray' function below.
#
# The function is expected to return an INTEGER_ARRAY.
# The function accepts INTEGER_ARRAY arr as parameter.
#
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input().strip())
for t_itr in range(t):
n = int(input().strip())
arr = list(map(int, input().rstrip().split()))
result = maxSubarray(arr)
fptr.write(' '.join(map(str, result)))
fptr.write('\n')
fptr.close() | [
2,
3740,
1378,
2503,
13,
31153,
8056,
962,
13,
785,
14,
36747,
34120,
14,
15542,
12,
8424,
12,
3866,
1845,
341,
12,
15813,
12,
9806,
7266,
18747,
14,
45573,
198,
198,
2,
48443,
8800,
14,
29412,
18,
198,
198,
11748,
10688,
198,
11748,
28686,
198,
11748,
4738,
198,
11748,
302,
198,
11748,
25064,
198,
198,
2,
198,
2,
13248,
262,
705,
9806,
7004,
18747,
6,
2163,
2174,
13,
198,
2,
198,
2,
383,
2163,
318,
2938,
284,
1441,
281,
17828,
7156,
1137,
62,
1503,
30631,
13,
198,
2,
383,
2163,
18178,
17828,
7156,
1137,
62,
1503,
30631,
5240,
355,
11507,
13,
198,
2,
198,
198,
361,
11593,
3672,
834,
6624,
705,
834,
12417,
834,
10354,
198,
220,
220,
220,
277,
20692,
796,
1280,
7,
418,
13,
268,
2268,
17816,
2606,
7250,
3843,
62,
34219,
6,
4357,
705,
86,
11537,
628,
220,
220,
220,
256,
796,
493,
7,
15414,
22446,
36311,
28955,
628,
220,
220,
220,
329,
256,
62,
270,
81,
287,
2837,
7,
83,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
299,
796,
493,
7,
15414,
22446,
36311,
28955,
628,
220,
220,
220,
220,
220,
220,
220,
5240,
796,
1351,
7,
8899,
7,
600,
11,
5128,
22446,
81,
36311,
22446,
35312,
3419,
4008,
628,
220,
220,
220,
220,
220,
220,
220,
1255,
796,
3509,
7004,
18747,
7,
3258,
8,
628,
220,
220,
220,
220,
220,
220,
220,
277,
20692,
13,
13564,
10786,
45302,
22179,
7,
8899,
7,
2536,
11,
1255,
22305,
198,
220,
220,
220,
220,
220,
220,
220,
277,
20692,
13,
13564,
10786,
59,
77,
11537,
628,
220,
220,
220,
277,
20692,
13,
19836,
3419
] | 2.507463 | 268 |
import torch
from torch.nn.modules.module import Module
from torch.autograd import Function
import correlation_cuda
| [
11748,
28034,
198,
6738,
28034,
13,
20471,
13,
18170,
13,
21412,
1330,
19937,
198,
6738,
28034,
13,
2306,
519,
6335,
1330,
15553,
198,
11748,
16096,
62,
66,
15339,
628
] | 4.034483 | 29 |
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import tensorflow as tf
from tensorflow.python.ops import data_flow_ops
import tensorflow.contrib.tensorrt as trt
import numpy as np
import time
from tensorflow.python.platform import gfile
from tensorflow.python.client import timeline
import argparse, sys, itertools,datetime
import json
tf.logging.set_verbosity(tf.logging.INFO)
import os
from utils import *
#main
if "__main__" in __name__:
P=argparse.ArgumentParser(prog="trt_convert")
P.add_argument('--FP32',action='store_true')
P.add_argument('--FP16',action='store_true')
P.add_argument('--INT8',action='store_true')
P.add_argument('--input_file',type=str)
P.add_argument('--input_path_calibration',type=str,default='./',help="path to read input files from for calibration mode")
P.add_argument('--output_prefix',type=str)
P.add_argument('--batch_size',type=int, default=32)
P.add_argument('--num_calibration_runs',type=int, default=10)
P.add_argument('--workspace_size',type=int, default=1<<20,help="workspace size in MB")
P.add_argument('--gpu', type=int, default=0)
#P.add_argument('--update_graphdef',action='store_true')
#parse args
f,unparsed=P.parse_known_args()
#select the GPU
os.environ["CUDA_VISIBLE_DEVICES"]=str(f.gpu) #selects a specific device
#create a session just in case
sess = tf.Session()
#print graph
print_graph(f.input_file)
#do the conversion
if f.FP32:
getFP32(input_file=f.input_file, output_prefix=f.output_prefix, output=["Softmax"], batch_size=f.batch_size, workspace_size=f.workspace_size)
if f.FP16:
getFP16(input_file=f.input_file, output_prefix=f.output_prefix, output=["Softmax"], batch_size=f.batch_size, workspace_size=f.workspace_size)
if f.INT8:
calibGraph = getINT8CalibGraph(input_file=f.input_file, output_prefix=f.output_prefix, output=["Softmax"], batch_size=f.batch_size, workspace_size=f.workspace_size)
print('Calibrating Graph...')
#run graph
runGraph(calibGraph, f.batch_size, f.num_calibration_runs, "Placeholder", ["Softmax"], dtype=np.float32, input_data=f.input_path_calibration)
print('done...')
#get int8 graph
getINT8InferenceGraph(output_prefix=f.output_prefix, calibGraph=calibGraph)
sys.exit(0)
| [
6738,
11593,
37443,
834,
1330,
4112,
62,
11748,
198,
6738,
11593,
37443,
834,
1330,
7297,
198,
6738,
11593,
37443,
834,
1330,
3601,
62,
8818,
198,
198,
11748,
11192,
273,
11125,
355,
48700,
198,
6738,
11192,
273,
11125,
13,
29412,
13,
2840,
1330,
1366,
62,
11125,
62,
2840,
198,
11748,
11192,
273,
11125,
13,
3642,
822,
13,
83,
22854,
17034,
355,
491,
83,
198,
198,
11748,
299,
32152,
355,
45941,
198,
11748,
640,
198,
6738,
11192,
273,
11125,
13,
29412,
13,
24254,
1330,
308,
7753,
198,
6738,
11192,
273,
11125,
13,
29412,
13,
16366,
1330,
15264,
198,
11748,
1822,
29572,
11,
25064,
11,
340,
861,
10141,
11,
19608,
8079,
198,
11748,
33918,
198,
27110,
13,
6404,
2667,
13,
2617,
62,
19011,
16579,
7,
27110,
13,
6404,
2667,
13,
10778,
8,
198,
198,
11748,
28686,
198,
198,
6738,
3384,
4487,
1330,
1635,
198,
198,
2,
12417,
198,
361,
366,
834,
12417,
834,
1,
287,
11593,
3672,
834,
25,
198,
220,
220,
198,
220,
350,
28,
853,
29572,
13,
28100,
1713,
46677,
7,
1676,
70,
2625,
2213,
83,
62,
1102,
1851,
4943,
198,
220,
350,
13,
2860,
62,
49140,
10786,
438,
5837,
2624,
3256,
2673,
11639,
8095,
62,
7942,
11537,
198,
220,
350,
13,
2860,
62,
49140,
10786,
438,
5837,
1433,
3256,
2673,
11639,
8095,
62,
7942,
11537,
198,
220,
350,
13,
2860,
62,
49140,
10786,
438,
12394,
23,
3256,
2673,
11639,
8095,
62,
7942,
11537,
198,
220,
350,
13,
2860,
62,
49140,
10786,
438,
15414,
62,
7753,
3256,
4906,
28,
2536,
8,
198,
220,
350,
13,
2860,
62,
49140,
10786,
438,
15414,
62,
6978,
62,
9948,
571,
1358,
3256,
4906,
28,
2536,
11,
12286,
28,
4458,
14,
3256,
16794,
2625,
6978,
284,
1100,
5128,
3696,
422,
329,
36537,
4235,
4943,
198,
220,
350,
13,
2860,
62,
49140,
10786,
438,
22915,
62,
40290,
3256,
4906,
28,
2536,
8,
198,
220,
350,
13,
2860,
62,
49140,
10786,
438,
43501,
62,
7857,
3256,
4906,
28,
600,
11,
4277,
28,
2624,
8,
198,
220,
350,
13,
2860,
62,
49140,
10786,
438,
22510,
62,
9948,
571,
1358,
62,
48381,
3256,
4906,
28,
600,
11,
4277,
28,
940,
8,
198,
220,
350,
13,
2860,
62,
49140,
10786,
438,
5225,
10223,
62,
7857,
3256,
4906,
28,
600,
11,
4277,
28,
16,
16791,
1238,
11,
16794,
2625,
5225,
10223,
2546,
287,
10771,
4943,
198,
220,
350,
13,
2860,
62,
49140,
10786,
438,
46999,
3256,
2099,
28,
600,
11,
4277,
28,
15,
8,
198,
220,
1303,
47,
13,
2860,
62,
49140,
10786,
438,
19119,
62,
34960,
4299,
3256,
2673,
11639,
8095,
62,
7942,
11537,
198,
220,
220,
198,
220,
1303,
29572,
26498,
198,
220,
277,
11,
403,
79,
945,
276,
28,
47,
13,
29572,
62,
4002,
62,
22046,
3419,
198,
220,
220,
198,
220,
1303,
19738,
262,
11362,
198,
220,
28686,
13,
268,
2268,
14692,
43633,
5631,
62,
29817,
34563,
62,
39345,
34444,
8973,
28,
2536,
7,
69,
13,
46999,
8,
1303,
19738,
82,
257,
2176,
3335,
628,
220,
1303,
17953,
257,
6246,
655,
287,
1339,
198,
220,
264,
408,
796,
48700,
13,
36044,
3419,
628,
220,
1303,
4798,
4823,
198,
220,
3601,
62,
34960,
7,
69,
13,
15414,
62,
7753,
8,
198,
220,
220,
198,
220,
1303,
4598,
262,
11315,
198,
220,
611,
277,
13,
5837,
2624,
25,
198,
220,
220,
220,
651,
5837,
2624,
7,
15414,
62,
7753,
28,
69,
13,
15414,
62,
7753,
11,
5072,
62,
40290,
28,
69,
13,
22915,
62,
40290,
11,
5072,
28,
14692,
18380,
9806,
33116,
15458,
62,
7857,
28,
69,
13,
43501,
62,
7857,
11,
44573,
62,
7857,
28,
69,
13,
5225,
10223,
62,
7857,
8,
198,
220,
611,
277,
13,
5837,
1433,
25,
198,
220,
220,
220,
651,
5837,
1433,
7,
15414,
62,
7753,
28,
69,
13,
15414,
62,
7753,
11,
5072,
62,
40290,
28,
69,
13,
22915,
62,
40290,
11,
5072,
28,
14692,
18380,
9806,
33116,
15458,
62,
7857,
28,
69,
13,
43501,
62,
7857,
11,
44573,
62,
7857,
28,
69,
13,
5225,
10223,
62,
7857,
8,
198,
220,
611,
277,
13,
12394,
23,
25,
198,
220,
220,
220,
27417,
37065,
796,
651,
12394,
23,
9771,
571,
37065,
7,
15414,
62,
7753,
28,
69,
13,
15414,
62,
7753,
11,
5072,
62,
40290,
28,
69,
13,
22915,
62,
40290,
11,
5072,
28,
14692,
18380,
9806,
33116,
15458,
62,
7857,
28,
69,
13,
43501,
62,
7857,
11,
44573,
62,
7857,
28,
69,
13,
5225,
10223,
62,
7857,
8,
198,
220,
220,
220,
3601,
10786,
9771,
2889,
803,
29681,
986,
11537,
198,
220,
220,
220,
1303,
5143,
4823,
198,
220,
220,
220,
1057,
37065,
7,
9948,
571,
37065,
11,
277,
13,
43501,
62,
7857,
11,
277,
13,
22510,
62,
9948,
571,
1358,
62,
48381,
11,
366,
27271,
13829,
1600,
14631,
18380,
9806,
33116,
288,
4906,
28,
37659,
13,
22468,
2624,
11,
5128,
62,
7890,
28,
69,
13,
15414,
62,
6978,
62,
9948,
571,
1358,
8,
198,
220,
220,
220,
3601,
10786,
28060,
986,
11537,
198,
220,
220,
220,
1303,
1136,
493,
23,
4823,
198,
220,
220,
220,
651,
12394,
23,
818,
4288,
37065,
7,
22915,
62,
40290,
28,
69,
13,
22915,
62,
40290,
11,
27417,
37065,
28,
9948,
571,
37065,
8,
198,
220,
220,
220,
220,
198,
220,
25064,
13,
37023,
7,
15,
8,
198
] | 2.707317 | 861 |
import Adafruit_SSD1306
import Image
import ImageDraw
import ImageFont
# I2C ADDRESS / BITS
SSD1306_ADDRESS = 0x3C
| [
11748,
1215,
1878,
4872,
62,
5432,
35,
12952,
21,
198,
11748,
7412,
198,
11748,
7412,
25302,
198,
11748,
7412,
23252,
198,
198,
2,
314,
17,
34,
5984,
7707,
7597,
1220,
347,
29722,
198,
5432,
35,
12952,
21,
62,
2885,
7707,
7597,
796,
657,
87,
18,
34,
628
] | 2.489362 | 47 |
if __name__ == '__main__':
print compute(1, 0.1) # default values
| [
198,
361,
11593,
3672,
834,
6624,
705,
834,
12417,
834,
10354,
198,
220,
220,
220,
3601,
24061,
7,
16,
11,
657,
13,
16,
8,
1303,
4277,
3815,
628
] | 2.571429 | 28 |
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
from ..optimization import discretization
from ..common.decorators import Registry
registry = Registry()
@registry.register
@registry.register
@registry.register
@registry.register
@registry.register
@registry.register
@registry.register
@registry.register
@registry.register
@registry.register
@registry.register
@registry.register
def lunacek(x: np.ndarray) -> float:
""" Based on https://www.cs.unm.edu/~neal.holts/dga/benchmarkFunction/lunacek.html."""
problemDimensions = len(x)
s = 1.0 - (1.0 / (2.0 * np.sqrt(problemDimensions + 20.0) - 8.2))
mu1 = 2.5
mu2 = - np.sqrt(abs((mu1**2 - 1.0) / s))
firstSum = 0.0
secondSum = 0.0
thirdSum = 0.0
for i in range(problemDimensions):
firstSum += (x[i]-mu1)**2
secondSum += (x[i]-mu2)**2
thirdSum += 1.0 - np.cos(2*np.pi*(x[i]-mu1))
return min(firstSum, 1.0*problemDimensions + secondSum)+10*thirdSum
# following functions using discretization should not be used with translation/rotation
@registry.register_with_info(no_transfrom=True)
@registry.register_with_info(no_transfrom=True)
@registry.register_with_info(no_transfrom=True)
@registry.register_with_info(no_transfrom=True)
@registry.register_with_info(no_transfrom=True)
@registry.register_with_info(no_transfrom=True)
@registry.register_with_info(no_transfrom=True)
@registry.register_with_info(no_transfrom=True)
@registry.register_with_info(no_transfrom=True)
@registry.register_with_info(no_transfrom=True)
@registry.register_with_info(no_transfrom=True)
@registry.register_with_info(no_transfrom=True)
@registry.register_with_info(no_transfrom=True)
@registry.register_with_info(no_transfrom=True)
@registry.register
@registry.register
@registry.register
@registry.register
@registry.register
@registry.register
@registry.register
@registry.register
| [
2,
15069,
357,
66,
8,
3203,
11,
3457,
13,
290,
663,
29116,
13,
1439,
6923,
33876,
13,
198,
2,
198,
2,
770,
2723,
2438,
318,
11971,
739,
262,
17168,
5964,
1043,
287,
262,
198,
2,
38559,
24290,
2393,
287,
262,
6808,
8619,
286,
428,
2723,
5509,
13,
198,
198,
11748,
299,
32152,
355,
45941,
198,
6738,
11485,
40085,
1634,
1330,
1221,
1186,
1634,
198,
6738,
11485,
11321,
13,
12501,
273,
2024,
1330,
33432,
628,
198,
2301,
4592,
796,
33432,
3419,
628,
628,
628,
198,
31,
2301,
4592,
13,
30238,
628,
198,
31,
2301,
4592,
13,
30238,
628,
198,
31,
2301,
4592,
13,
30238,
628,
198,
31,
2301,
4592,
13,
30238,
628,
198,
31,
2301,
4592,
13,
30238,
628,
198,
31,
2301,
4592,
13,
30238,
628,
198,
31,
2301,
4592,
13,
30238,
628,
198,
31,
2301,
4592,
13,
30238,
628,
198,
31,
2301,
4592,
13,
30238,
628,
198,
31,
2301,
4592,
13,
30238,
628,
198,
31,
2301,
4592,
13,
30238,
628,
198,
31,
2301,
4592,
13,
30238,
198,
4299,
14678,
558,
74,
7,
87,
25,
45941,
13,
358,
18747,
8,
4613,
12178,
25,
198,
220,
220,
220,
37227,
13403,
319,
3740,
1378,
2503,
13,
6359,
13,
403,
76,
13,
15532,
14,
93,
710,
282,
13,
3937,
912,
14,
67,
4908,
14,
26968,
4102,
22203,
14,
75,
403,
558,
74,
13,
6494,
526,
15931,
198,
220,
220,
220,
1917,
29271,
5736,
796,
18896,
7,
87,
8,
198,
220,
220,
220,
264,
796,
352,
13,
15,
532,
357,
16,
13,
15,
1220,
357,
17,
13,
15,
1635,
45941,
13,
31166,
17034,
7,
45573,
29271,
5736,
1343,
1160,
13,
15,
8,
532,
807,
13,
17,
4008,
198,
220,
220,
220,
38779,
16,
796,
362,
13,
20,
198,
220,
220,
220,
38779,
17,
796,
532,
45941,
13,
31166,
17034,
7,
8937,
19510,
30300,
16,
1174,
17,
532,
352,
13,
15,
8,
1220,
264,
4008,
198,
220,
220,
220,
717,
13065,
796,
657,
13,
15,
198,
220,
220,
220,
1218,
13065,
796,
657,
13,
15,
198,
220,
220,
220,
2368,
13065,
796,
657,
13,
15,
198,
220,
220,
220,
329,
1312,
287,
2837,
7,
45573,
29271,
5736,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
717,
13065,
15853,
357,
87,
58,
72,
45297,
30300,
16,
8,
1174,
17,
198,
220,
220,
220,
220,
220,
220,
220,
1218,
13065,
15853,
357,
87,
58,
72,
45297,
30300,
17,
8,
1174,
17,
198,
220,
220,
220,
220,
220,
220,
220,
2368,
13065,
15853,
352,
13,
15,
532,
45941,
13,
6966,
7,
17,
9,
37659,
13,
14415,
9,
7,
87,
58,
72,
45297,
30300,
16,
4008,
198,
220,
220,
220,
1441,
949,
7,
11085,
13065,
11,
352,
13,
15,
9,
45573,
29271,
5736,
1343,
1218,
13065,
47762,
940,
9,
17089,
13065,
628,
198,
2,
1708,
5499,
1262,
1221,
1186,
1634,
815,
407,
307,
973,
351,
11059,
14,
10599,
341,
628,
198,
31,
2301,
4592,
13,
30238,
62,
4480,
62,
10951,
7,
3919,
62,
7645,
6738,
28,
17821,
8,
628,
198,
31,
2301,
4592,
13,
30238,
62,
4480,
62,
10951,
7,
3919,
62,
7645,
6738,
28,
17821,
8,
628,
198,
31,
2301,
4592,
13,
30238,
62,
4480,
62,
10951,
7,
3919,
62,
7645,
6738,
28,
17821,
8,
628,
198,
31,
2301,
4592,
13,
30238,
62,
4480,
62,
10951,
7,
3919,
62,
7645,
6738,
28,
17821,
8,
628,
198,
31,
2301,
4592,
13,
30238,
62,
4480,
62,
10951,
7,
3919,
62,
7645,
6738,
28,
17821,
8,
628,
198,
31,
2301,
4592,
13,
30238,
62,
4480,
62,
10951,
7,
3919,
62,
7645,
6738,
28,
17821,
8,
628,
198,
31,
2301,
4592,
13,
30238,
62,
4480,
62,
10951,
7,
3919,
62,
7645,
6738,
28,
17821,
8,
628,
198,
31,
2301,
4592,
13,
30238,
62,
4480,
62,
10951,
7,
3919,
62,
7645,
6738,
28,
17821,
8,
628,
198,
31,
2301,
4592,
13,
30238,
62,
4480,
62,
10951,
7,
3919,
62,
7645,
6738,
28,
17821,
8,
628,
198,
31,
2301,
4592,
13,
30238,
62,
4480,
62,
10951,
7,
3919,
62,
7645,
6738,
28,
17821,
8,
628,
198,
31,
2301,
4592,
13,
30238,
62,
4480,
62,
10951,
7,
3919,
62,
7645,
6738,
28,
17821,
8,
628,
198,
31,
2301,
4592,
13,
30238,
62,
4480,
62,
10951,
7,
3919,
62,
7645,
6738,
28,
17821,
8,
628,
198,
31,
2301,
4592,
13,
30238,
62,
4480,
62,
10951,
7,
3919,
62,
7645,
6738,
28,
17821,
8,
628,
198,
31,
2301,
4592,
13,
30238,
62,
4480,
62,
10951,
7,
3919,
62,
7645,
6738,
28,
17821,
8,
628,
198,
31,
2301,
4592,
13,
30238,
628,
198,
31,
2301,
4592,
13,
30238,
628,
198,
31,
2301,
4592,
13,
30238,
628,
198,
31,
2301,
4592,
13,
30238,
628,
198,
31,
2301,
4592,
13,
30238,
628,
198,
31,
2301,
4592,
13,
30238,
628,
198,
31,
2301,
4592,
13,
30238,
628,
198,
31,
2301,
4592,
13,
30238,
198
] | 2.67087 | 793 |
string = input()
d = {}
for i in string:
if i in d:
d[i] += 1
else:
d[i] = 1
s = sorted(sorted(d), key = d.get, reverse = True)
for i in s[:3]:
print(i, d[i])
| [
8841,
796,
5128,
3419,
198,
67,
796,
23884,
198,
1640,
1312,
287,
4731,
25,
198,
220,
220,
220,
611,
1312,
287,
288,
25,
198,
220,
220,
220,
220,
220,
220,
220,
288,
58,
72,
60,
15853,
352,
198,
220,
220,
220,
2073,
25,
198,
220,
220,
220,
220,
220,
220,
220,
288,
58,
72,
60,
796,
352,
198,
82,
796,
23243,
7,
82,
9741,
7,
67,
828,
1994,
796,
288,
13,
1136,
11,
9575,
796,
6407,
8,
198,
1640,
1312,
287,
264,
58,
25,
18,
5974,
198,
220,
220,
220,
3601,
7,
72,
11,
288,
58,
72,
12962,
198
] | 1.888889 | 99 |
for row in solve(10):
print(row)
| [
198,
198,
1640,
5752,
287,
8494,
7,
940,
2599,
198,
220,
220,
220,
3601,
7,
808,
8,
198
] | 2.166667 | 18 |
import random
import string
from subprocess import run
from types import SimpleNamespace
import psycopg2
import versions
from docker_helpers import get_image_name, pull, exec_safely
from service_config import api_db_user
from settings import get_secret
root_user = "vimc"
# these tables should only be modified via sql migrations
protected_tables = ["gavi_support_level", "activity_type",
"burden_outcome",
"gender",
"responsibility_set_status",
"impact_outcome",
"gavi_support_level",
"support_type",
"touchstone_status",
"permission",
"role",
"role_permission"]
def for_each_user(root_password, users, operation):
"""Operation is a callback (function) that takes the connection cursor
and a UserConfig object"""
with connect(root_user, root_password) as conn:
with conn.cursor() as cur:
for user in users:
operation(cur, user)
conn.commit()
# NOTE: it might be worth revisiting this to not run this script
# directly (that requires corresponding changes in montagu-db to move
# the inline sql into a standalone .sql file and then getting psql to
# run it via docker exec - it must run as the vimc user). The
# passwords might move directly under control here using set_password
# (but these are special users so we'd not want to use the rest of the
# user machinery). But I suggest waiting until the restore is done
# VIMC-1560) because that is likely to affect how we deal with users
| [
11748,
4738,
198,
11748,
4731,
198,
6738,
850,
14681,
1330,
1057,
198,
6738,
3858,
1330,
17427,
36690,
10223,
198,
198,
11748,
17331,
22163,
70,
17,
198,
198,
11748,
6300,
198,
6738,
36253,
62,
16794,
364,
1330,
651,
62,
9060,
62,
3672,
11,
2834,
11,
2452,
62,
21230,
306,
198,
6738,
2139,
62,
11250,
1330,
40391,
62,
9945,
62,
7220,
198,
6738,
6460,
1330,
651,
62,
21078,
198,
198,
15763,
62,
7220,
796,
366,
31124,
66,
1,
198,
2,
777,
8893,
815,
691,
307,
9518,
2884,
44161,
15720,
602,
198,
24326,
62,
83,
2977,
796,
14631,
70,
15820,
62,
11284,
62,
5715,
1600,
366,
21797,
62,
4906,
1600,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
366,
65,
42568,
62,
448,
2958,
1600,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
366,
8388,
1600,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
366,
16733,
2247,
62,
2617,
62,
13376,
1600,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
366,
48240,
62,
448,
2958,
1600,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
366,
70,
15820,
62,
11284,
62,
5715,
1600,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
366,
11284,
62,
4906,
1600,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
366,
29332,
6440,
62,
13376,
1600,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
366,
525,
3411,
1600,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
366,
18090,
1600,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
366,
18090,
62,
525,
3411,
8973,
628,
628,
628,
628,
628,
628,
628,
628,
198,
198,
4299,
329,
62,
27379,
62,
7220,
7,
15763,
62,
28712,
11,
2985,
11,
4905,
2599,
198,
220,
220,
220,
37227,
32180,
318,
257,
23838,
357,
8818,
8,
326,
2753,
262,
4637,
23493,
198,
220,
220,
220,
290,
257,
11787,
16934,
2134,
37811,
198,
220,
220,
220,
351,
2018,
7,
15763,
62,
7220,
11,
6808,
62,
28712,
8,
355,
48260,
25,
198,
220,
220,
220,
220,
220,
220,
220,
351,
48260,
13,
66,
21471,
3419,
355,
1090,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
329,
2836,
287,
2985,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
4905,
7,
22019,
11,
2836,
8,
198,
220,
220,
220,
220,
220,
220,
220,
48260,
13,
41509,
3419,
628,
198,
198,
2,
24550,
25,
340,
1244,
307,
2861,
22124,
1780,
428,
284,
407,
1057,
428,
4226,
198,
2,
3264,
357,
5562,
4433,
11188,
2458,
287,
40689,
11433,
12,
9945,
284,
1445,
198,
2,
262,
26098,
44161,
656,
257,
27669,
764,
25410,
2393,
290,
788,
1972,
279,
25410,
284,
198,
2,
1057,
340,
2884,
36253,
2452,
532,
340,
1276,
1057,
355,
262,
43907,
66,
2836,
737,
220,
383,
198,
2,
21442,
1244,
1445,
3264,
739,
1630,
994,
1262,
900,
62,
28712,
198,
2,
357,
4360,
777,
389,
2041,
2985,
523,
356,
1549,
407,
765,
284,
779,
262,
1334,
286,
262,
198,
2,
2836,
20230,
737,
220,
887,
314,
1950,
4953,
1566,
262,
11169,
318,
1760,
198,
2,
569,
3955,
34,
12,
1314,
1899,
8,
780,
326,
318,
1884,
284,
2689,
703,
356,
1730,
351,
2985,
628
] | 2.615987 | 638 |
#!/usr/bin/env python3
import poplib
import argparse
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='MailBox basic params')
parser.add_argument('--hostname', action="store", dest="hostname")
parser.add_argument('--port', action="store", dest="port")
parser.add_argument('--user', action="store", dest="user")
given_args = parser.parse_args()
hostname = given_args.hostname
port = given_args.port
user = given_args.user
import getpass
password = getpass.getpass(prompt='Enter your password:')
main(hostname,port,user,password)
| [
2,
48443,
14629,
14,
8800,
14,
24330,
21015,
18,
198,
198,
11748,
1461,
8019,
198,
11748,
1822,
29572,
198,
198,
361,
11593,
3672,
834,
6624,
705,
834,
12417,
834,
10354,
198,
220,
220,
220,
220,
220,
220,
220,
30751,
796,
1822,
29572,
13,
28100,
1713,
46677,
7,
11213,
11639,
25804,
14253,
4096,
42287,
11537,
198,
220,
220,
220,
220,
220,
220,
220,
30751,
13,
2860,
62,
49140,
10786,
438,
4774,
3672,
3256,
2223,
2625,
8095,
1600,
2244,
2625,
4774,
3672,
4943,
198,
220,
220,
220,
220,
220,
220,
220,
30751,
13,
2860,
62,
49140,
10786,
438,
634,
3256,
2223,
2625,
8095,
1600,
2244,
2625,
634,
4943,
198,
220,
220,
220,
220,
220,
220,
220,
30751,
13,
2860,
62,
49140,
10786,
438,
7220,
3256,
2223,
2625,
8095,
1600,
2244,
2625,
7220,
4943,
628,
220,
220,
220,
220,
220,
220,
220,
1813,
62,
22046,
796,
30751,
13,
29572,
62,
22046,
3419,
220,
198,
220,
220,
220,
220,
220,
220,
220,
2583,
3672,
796,
1813,
62,
22046,
13,
4774,
3672,
198,
220,
220,
220,
220,
220,
220,
220,
2493,
796,
1813,
62,
22046,
13,
634,
198,
220,
220,
220,
220,
220,
220,
220,
2836,
796,
1813,
62,
22046,
13,
7220,
628,
220,
220,
220,
220,
220,
220,
220,
1330,
651,
6603,
220,
198,
220,
220,
220,
220,
220,
220,
220,
9206,
796,
651,
6603,
13,
1136,
6603,
7,
16963,
457,
11639,
17469,
534,
9206,
25,
11537,
628,
220,
220,
220,
220,
220,
220,
220,
1388,
7,
4774,
3672,
11,
634,
11,
7220,
11,
28712,
8,
628
] | 2.557312 | 253 |
import sys
import time
import redis
from openob.rtp.tx import RTPTransmitter
from openob.rtp.rx import RTPReceiver
import gst
from colorama import Fore, Back, Style
# OpenOB Link Manager
# One of these runs at each end and negotiates everything (RX pushes config info to TX), reconnects when links fail, and so on.
class Manager:
'''OpenOB Manager. Handles management of links, mostly recovery from failures.'''
| [
11748,
25064,
201,
198,
11748,
640,
201,
198,
11748,
2266,
271,
201,
198,
6738,
1280,
672,
13,
17034,
79,
13,
17602,
1330,
371,
7250,
8291,
37974,
201,
198,
6738,
1280,
672,
13,
17034,
79,
13,
40914,
1330,
371,
7250,
3041,
39729,
201,
198,
11748,
308,
301,
201,
198,
6738,
3124,
1689,
1330,
4558,
11,
5157,
11,
17738,
201,
198,
2,
4946,
9864,
7502,
9142,
201,
198,
2,
1881,
286,
777,
4539,
379,
1123,
886,
290,
5578,
689,
2279,
357,
49,
55,
20070,
4566,
7508,
284,
15326,
828,
37671,
82,
618,
6117,
2038,
11,
290,
523,
319,
13,
201,
198,
4871,
9142,
25,
201,
198,
220,
705,
7061,
11505,
9864,
9142,
13,
7157,
829,
4542,
286,
6117,
11,
4632,
7628,
422,
15536,
2637,
7061,
201,
198
] | 3.4 | 125 |
End of preview. Expand
in Dataset Viewer.
README.md exists but content is empty.
Use the Edit dataset card button to edit it.
- Downloads last month
- 85