content
stringlengths 0
894k
| type
stringclasses 2
values |
---|---|
import pytest
from pySnowRadar.timefunc import utcleap
def test_utcleap_invalid():
with pytest.raises(Exception):
result = utcleap('a')
def test_utcleap_valid():
true_time = 1092121230.0
assert utcleap(1092121243.0) == true_time | python |
import argparse
import csv
import logging
logging.basicConfig(level=logging.INFO,
format='%(asctime)s | [%(levelname)s] : %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
parser = argparse.ArgumentParser()
parser.add_argument("--package_list",
type=argparse.FileType('r'),
help="Path to the file that contains a list of packages extracted from AndroidManifest at Github",
required=True)
parser.add_argument(
'--output', default=open('pkgs_one_manifest_repo', 'w'),
type=argparse.FileType('w'),
help='Output file. Default: pkgs_one_manifest_repo.')
args = parser.parse_args()
csv_reader = csv.reader(args.package_list, delimiter=',')
next(csv_reader, None)
lines = []
for row in csv_reader:
lines.append("{}\n".format(row[0]))
n_lines = len(lines)
args.package_list.close()
logging.info("Extracting packages names")
logging.info("{} packages found.".format(n_lines))
logging.info("Removing duplicated packages")
uniq_lines = set(lines)
n_uniq = len(uniq_lines)
logging.info("{} packages remaining. {} packages duplicated removed".format(n_uniq, n_lines - n_uniq))
args.output.write(''.join(sorted(uniq_lines)))
| python |
# Generated by Django 3.0.1 on 2020-02-10 02:06
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('recipes', '0001_initial'),
('main', '0016_auto_20191222_2333'),
]
operations = [
migrations.AlterField(
model_name='profile',
name='saved_recipes',
field=models.ManyToManyField(related_name='saved_by', to='recipes.Recipe'),
),
]
| python |
#Functions and some global variables were moved here simply to clean up main.py.
import re #import regular expressions
import string
import obj_wordlist
#Limit on the length of generated sentences.
#TODO. Later you could do a depth-limited, depth-first search for a path to a period to end the sentence.
sentenceLengthLimit = 20
#Word list - store all words and connections here
wordlist = obj_wordlist.WordList()
#Keep track of rejected words for testing purposes
rejected_words = []
#For now, use a regular expression to match only words containing
#alpha-numeric characters, hyphens, or apostrophes.
alpha = re.compile("^[\w\'-]+$")
#Match articles
articles = re.compile('a|an|the')
def processFile(filetoreadin, articlesSep):
"""Takes a filename and returns an array of strings ready to be fed to the wordlist"""
"""
global alpha, rejected_words, articles
to_return = []
file_handle=open(filetoreadin)
line = file_handle.readline()
article = '' #This will be set if an article is found.
while line:
line = string.lower(line) #lower case the whole string.
words = line.split(' ')
for i in xrange(len(words)):
w = words[i]
#Remove white space
w = w.strip()
#Deal with commas
if w.endswith(","):
w = w.replace(",","")
#Deal with periods
endsWithPeriod = False
if w.endswith("."):
w = w.replace(".","")
endsWithPeriod = True
#for now, remove anything that is not purely alpha-numeric
result = alpha.match(w)
if result is None:
if not w in rejected_words:
rejected_words.append(w)
else:
result = articles.match(w)
if not articlesSep and not result is None:
article = w
else:
if article:
to_return.append(article+' '+w)
article = ''
else:
to_return.append(w)
if endsWithPeriod:
to_return.append('.')
line = file_handle.readline()
"""
file_handle.close()
return to_return
def hasValidExtension(f, extensions):
for e in extensions:
if f.endswith(e):
return True
return False
| python |
# Generated by Django 2.2.7 on 2020-01-15 14:39
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('web', '0013_auto_20200108_2257'),
]
operations = [
migrations.AlterField(
model_name='article',
name='src_url',
field=models.CharField(max_length=1024, unique=True, verbose_name='原始链接'),
),
migrations.AlterField(
model_name='article',
name='title',
field=models.CharField(max_length=200, verbose_name='标题'),
),
migrations.AlterField(
model_name='site',
name='creator',
field=models.CharField(blank=True, choices=[('system', '系统录入'), ('user', '用户提交'), ('wemp', '微信公众号')], db_index=True, default='system', max_length=20, null=True, verbose_name='创建人'),
),
migrations.AlterField(
model_name='site',
name='link',
field=models.CharField(max_length=1024, verbose_name='主页'),
),
migrations.AlterField(
model_name='site',
name='rss',
field=models.CharField(blank=True, max_length=1024, null=True, verbose_name='RSS地址'),
),
]
| python |
'''
最小体力消耗路径
你准备参加一场远足活动。给你一个二维 rows x columns 的地图 heights ,其中 heights[row][col] 表示格子 (row, col) 的高度。
一开始你在最左上角的格子 (0, 0) ,且你希望去最右下角的格子 (rows-1, columns-1) (注意下标从 0 开始编号)。
你每次可以往 上,下,左,右 四个方向之一移动,你想要找到耗费 体力 最小的一条路径。
一条路径耗费的 体力值 是路径上相邻格子之间 高度差绝对值 的 最大值 决定的。
请你返回从左上角走到右下角的最小 体力消耗值 。
提示:
rows == heights.length
columns == heights[i].length
1 <= rows, columns <= 100
1 <= heights[i][j] <= 10^6
'''
from typing import List
'''
思路:Dijkstra计算最短路径
经典的无向有权图的求解问题,使用Dijkstra算法
Dijkstra算法是一种贪心算法,它设置一个数组d,保存原点到各单元格的路径长度
用最小堆从d中提取路径最小的单元格g,然后对从g出发的路径进行松弛relax。
重复上面的过程,直至找到终点。
时间复杂度:O(mn*logmn),最坏情况下需要遍历m*n,每次访问最小堆的时间复杂度O(logmn)
空间复杂度:O(mn),保存路径长度的数组d大小为m*n,保存单元格是否遍历过的数组v大小为m*n,最小堆大小为m*n
'''
class Solution:
def minimumEffortPath(self, heights: List[List[int]]) -> int:
rows, cols = len(heights), len(heights[0])
d = [float('inf')] * rows * cols # 保存从节点0到该单元格的路径长度
d[0] = 0
heap = MinHeap(rows * cols, d) # 建立最小堆,最小堆用于选择距离0最小的元素
# 松弛函数,松弛2个节点的距离
def relax(u, v):
w = abs(heights[u // cols][u % cols] - heights[v // cols][v % cols]) # 两个节点的距离为2个节点的高度差
if max(d[u], w) < d[v]:
heap.decKey(v, max(d[u], w)) # 将d[v],也就是v节点到0点的距离更新为d[u]+w
end = rows * cols - 1
while heap.size > 0:
u = heap.extractMin()
i, j = divmod(u, cols)
for x, y in [(i + 1, j), (i, j + 1), (i - 1, j), (i, j - 1)]:
nextpos = x * cols + y
if 0 <= x < rows and 0 <= y < cols:
relax(u, nextpos)
if u == end:
return d[u]
return d[end]
# 最小堆,Dijkstra算法下用于存放原点到各节点路径的下标
class MinHeap():
def __init__(self, size, d):
# 第0个元素最小,其他元素都是正无穷大,默认就是最小堆
self.heap = [i for i in range(size)]
self.size = size
self.d = d
self.nodeIdMap = {}
for i in range(self.size):
self.nodeIdMap[i] = i
# 从堆中删除最小元素并返回
def extractMin(self):
i = self.heap[0]
self.size = self.size - 1
if self.size > 0:
self.heap[0] = self.heap[self.size]
self.minHeapify(0)
return i
# 减少最小堆里面的一个节点的值
def decKey(self, nodeid, val):
self.d[nodeid] = val
heapIndex = self.nodeIdMap[nodeid]
parent = (heapIndex - 1) // 2
while heapIndex > 0 and self.d[self.heap[parent]] > self.d[self.heap[heapIndex]]:
self.nodeIdMap[self.heap[parent]] = heapIndex
self.nodeIdMap[self.heap[heapIndex]] = parent
self.heap[parent], self.heap[heapIndex] = self.heap[heapIndex], self.heap[parent]
heapIndex, parent = parent, (parent - 1) // 2
# 保持最小堆的性质
def minHeapify(self, i):
left = 2 * i + 1
right = 2 * i + 2
minIndex = i
# 如果左、右子节点指向的路径小于父节点的路径,不满足最小堆性质,需要将父节点与左或右节点交换,使之满足最小堆性质
if left < self.size and self.d[self.heap[left]] < self.d[self.heap[minIndex]]:
minIndex = left
if right < self.size and self.d[self.heap[right]] < self.d[self.heap[minIndex]]:
minIndex = right
if minIndex != i:
self.nodeIdMap[self.heap[minIndex]] = i
self.nodeIdMap[self.heap[i]] = minIndex
self.heap[minIndex], self.heap[i] = self.heap[i], self.heap[minIndex]
self.minHeapify(minIndex) # 交换后子节点可能不满足最小堆性质,需要递归向下执行
s = Solution()
print(s.minimumEffortPath([[3]]))
print(s.minimumEffortPath([[3], [3], [7], [2], [9], [9], [3], [7], [10]]))
print(s.minimumEffortPath(heights=[[1, 2, 2], [3, 8, 2], [5, 3, 5]]))
print(s.minimumEffortPath([[1, 2, 3], [3, 8, 4], [5, 3, 5]]))
print(s.minimumEffortPath([[1, 2, 1, 1, 1], [1, 2, 1, 2, 1], [1, 2, 1, 2, 1], [1, 2, 1, 2, 1], [1, 1, 1, 2, 1]]))
| python |
lista = pares = impares = []
while True:
lista.append(int(input('Digite um número: ')))
resp = ' '
while resp not in 'SN':
resp = str(input('Deseja continuar? [S/N] ')).strip().upper()[0]
if resp == 'N':
break
for c, v in enumerate(lista):
if v % 2 == 0:
pares.append(v)
else:
impares.append(v)
print(f'A lista completa é {lista}.')
print(f'A lista de pares é: {pares}.')
print(f'A lista de ímpares é: {impares}.')
| python |
from PyQt5.QtCore import QUrl
from PyQt5.QtMultimedia import (QMediaContent, QMediaPlaylist, QMediaPlayer, QAudio)
import mutagen.mp3
import os
import files
import util
def is_music_file(file: str):
return os.path.isfile(file) and file.lower().endswith('.mp3')
class InvalidFile(Exception):
pass
# noinspection PyArgumentList
class WMediaPlayer(QMediaPlayer):
def __init__(self, parent=None):
super(WMediaPlayer, self).__init__(parent)
self.mainwindow = parent.mainwindow
self.has_playlist = False
self.setAudioRole(QAudio.MusicRole)
self.stateChanged.connect(self.state_changed)
self.positionChanged.connect(self.position_changed)
self.mediaStatusChanged.connect(self.media_status_changed)
def state_changed(self, state):
if state == QMediaPlayer.StoppedState:
self.mainwindow.set_drpc_activity("stopped")
elif state == QMediaPlayer.PlayingState:
self.mainwindow.set_drpc_activity("playing")
elif state == QMediaPlayer.PausedState:
self.mainwindow.set_drpc_activity("paused")
else:
self.mainwindow.set_drpc_activity("broken")
def position_changed(self, position):
if not self.state() == QMediaPlayer.StoppedState:
self.mainwindow.music_control_box.music_position_label.setText(util.format_duration(position))
self.mainwindow.music_control_box.duration_slider.setValue(position)
def media_status_changed(self, status):
if status == QMediaPlayer.EndOfMedia and self.mainwindow.music_control_box.repeat_button.repeating:
self.play()
elif status == QMediaPlayer.EndOfMedia and self.has_playlist:
self.next_index()
elif status == QMediaPlayer.EndOfMedia:
self.mainwindow.music_control_box.reset_duration()
self.mainwindow.music_control_box.duration_slider.setDisabled(True)
self.mainwindow.music_control_box.set_end_of_media_buttons()
def next_index(self):
self.mainwindow.song_list_tree.remove_highlight(self.mainwindow.playlist)
if self.mainwindow.playlist.currentIndex() >= self.mainwindow.playlist.mediaCount() - 1:
self.mainwindow.playlist.setCurrentIndex(0)
else:
self.mainwindow.playlist.next()
self.set_new_current_song()
def previous_index(self):
self.mainwindow.song_list_tree.remove_highlight(self.mainwindow.playlist)
if self.mainwindow.playlist.currentIndex() <= 0:
self.mainwindow.playlist.setCurrentIndex(self.mainwindow.playlist.mediaCount() - 1)
else:
self.mainwindow.playlist.previous()
self.set_new_current_song()
def goto_index(self, index):
self.mainwindow.song_list_tree.remove_highlight(self.mainwindow.playlist)
self.mainwindow.playlist.setCurrentIndex(index)
self.set_new_current_song()
def set_new_current_song(self):
# This method needs a better name.
self.mainwindow.song.set_song(self.mainwindow.playlist.get_current_song())
self.mainwindow.music_control_box.reset_duration()
self.mainwindow.music_control_box.duration_slider.setMaximum(self.mainwindow.song.get_player_duration())
self.mainwindow.music_info_box.set_song_info()
self.mainwindow.song_list_tree.add_highlight(self.mainwindow.playlist)
self.state_changed(self.state())
# noinspection PyArgumentList
class WPlaylist(QMediaPlaylist):
def __init__(self, parent=None):
super(WPlaylist, self).__init__(None)
self.mainwindow = parent
def get_current_song(self):
return self.currentMedia().canonicalUrl().path()[1:]
def get_song(self, index):
return self.media(index).canonicalUrl().path()[1:]
def get_all_song_file_locations(self):
songs = []
for i in range(0, self.mediaCount()):
song = self.media(i)
songs.append(song.canonicalUrl().path()[1:])
return songs
def set_playlist_from_folder(self, folder):
if not os.path.isdir(os.path.join(folder)):
return
for file in os.listdir(folder):
if is_music_file(os.path.join(folder, file)):
self.addMedia(QMediaContent(QUrl.fromLocalFile(os.path.join(folder, file))))
def set_playlist_files(self):
for folder in self.mainwindow.options.user_music_folders:
if not os.path.isdir(os.path.join(folder)):
continue
for file in os.listdir(folder):
if is_music_file(os.path.join(folder, file)):
self.addMedia(QMediaContent(QUrl.fromLocalFile(os.path.join(folder, file))))
# noinspection PyArgumentList
class WSong:
ARTIST = "artist"
TITLE = "title"
ALBUM = "album"
def __init__(self):
self.file_location = None
self.mp3 = None
self.content = None # For QMediaPlayer
def set_song(self, file_location: str):
self.file_location = file_location
self.mp3 = mutagen.mp3.EasyMP3(file_location)
self.content = QMediaContent(QUrl.fromLocalFile(file_location))
def has_song(self):
return self.file_location is not None
def get_info(self, wanted_info: str = TITLE):
"""Gets the desired metadata from the mp3 file.
:return: Metadata in string form.
"""
try:
info = str(self.mp3[wanted_info])
return info[2:len(info) - 2] # Removes the ['']
except KeyError:
return "N/A"
def get_file_size(self):
return util.sizeof_fmt(self.file_location)
def get_apic(self, file_output=False):
"""Extracts album art from a given MP3 file. Output is raw JPEG data.
:return: False if mp3 can't be opened, and None if no art was found
"""
# https://uploads.s.zeid.me/python/apic-extract.py
try:
tags = mutagen.mp3.Open(self.file_location)
except mutagen.MutagenError:
return False
data = b""
for i in tags:
if i.startswith("APIC"):
data = tags[i].data
break
if not data:
return None
if file_output:
with open(files.TEMP_PNG_FILE, 'bw') as out:
out.write(data)
return True
return data
@staticmethod
def remove_apic_file():
os.remove(files.TEMP_PNG_FILE)
def get_real_duration(self):
"""
:return: The song's true duration in milliseconds.
"""
return int(self.mp3.info.length * 1000)
def get_player_duration(self):
"""
:return: The song's duration for QMediaPlayer in milliseconds.
"""
# QMediaPlayer adds 202 milliseconds to the duration, no idea why.
return self.get_real_duration() + 202
| python |
import os, sys, json, unittest, logging, uuid, decimal, datetime, time
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import aurora_data_api # noqa
from aurora_data_api.mysql_error_codes import MySQLErrorCodes # noqa
from aurora_data_api.postgresql_error_codes import PostgreSQLErrorCodes # noqa
logging.basicConfig(level=logging.INFO)
logging.getLogger("aurora_data_api").setLevel(logging.DEBUG)
logging.getLogger("urllib3.connectionpool").setLevel(logging.DEBUG)
class TestAuroraDataAPI(unittest.TestCase):
using_mysql = False
@classmethod
def setUpClass(cls):
cls.db_name = os.environ.get("AURORA_DB_NAME", __name__)
with aurora_data_api.connect(database=cls.db_name) as conn, conn.cursor() as cur:
try:
cur.execute("""
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
DROP TABLE IF EXISTS aurora_data_api_test;
CREATE TABLE aurora_data_api_test (
id SERIAL,
name TEXT,
doc JSONB DEFAULT '{}',
num NUMERIC (10, 5) DEFAULT 0.0,
ts TIMESTAMP WITHOUT TIME ZONE
)
""")
cur.executemany("""
INSERT INTO aurora_data_api_test(name, doc, num, ts)
VALUES (:name, CAST(:doc AS JSONB), :num, CAST(:ts AS TIMESTAMP))
""", [
{
"name": "row{}".format(i),
"doc": json.dumps({"x": i, "y": str(i), "z": [i, i * i, i ** i if i < 512 else 0]}),
"num": decimal.Decimal("%d.%d" % (i, i)),
"ts": "2020-09-17 13:49:32.780180",
} for i in range(2048)]
)
except aurora_data_api.DatabaseError as e:
if e.args[0] != MySQLErrorCodes.ER_PARSE_ERROR:
raise
cls.using_mysql = True
cur.execute("DROP TABLE IF EXISTS aurora_data_api_test")
cur.execute(
"CREATE TABLE aurora_data_api_test (id SERIAL, name TEXT, birthday DATE, num NUMERIC(10, 5))"
)
cur.executemany(
"INSERT INTO aurora_data_api_test(name, birthday, num) VALUES (:name, :birthday, :num)", [{
"name": "row{}".format(i),
"birthday": "2000-01-01",
"num": decimal.Decimal("%d.%d" % (i, i))
} for i in range(2048)]
)
@classmethod
def tearDownClass(cls):
with aurora_data_api.connect(database=cls.db_name) as conn, conn.cursor() as cur:
cur.execute("DROP TABLE IF EXISTS aurora_data_api_test")
def test_invalid_statements(self):
with aurora_data_api.connect(database=self.db_name) as conn, conn.cursor() as cur:
with self.assertRaisesRegex(aurora_data_api.DatabaseError, "syntax"):
cur.execute("selec * from table")
def test_iterators(self):
with aurora_data_api.connect(database=self.db_name) as conn, conn.cursor() as cur:
if not self.using_mysql:
cur.execute("select count(*) from aurora_data_api_test where pg_column_size(doc) < :s", dict(s=2**6))
self.assertEqual(cur.fetchone()[0], 0)
cur.execute("select count(*) from aurora_data_api_test where pg_column_size(doc) < :s", dict(s=2**7))
self.assertEqual(cur.fetchone()[0], 1594)
cur.execute("select count(*) from aurora_data_api_test where pg_column_size(doc) < :s", dict(s=2**8))
self.assertEqual(cur.fetchone()[0], 1697)
cur.execute("select count(*) from aurora_data_api_test where pg_column_size(doc) < :s", dict(s=2**10))
self.assertEqual(cur.fetchone()[0], 2048)
with conn.cursor() as cursor:
expect_row0 = (1,
'row0',
datetime.date(2000, 1, 1) if self.using_mysql else '{"x": 0, "y": "0", "z": [0, 0, 1]}',
decimal.Decimal(0),
datetime.datetime(2020, 9, 17, 13, 49, 32, 780180))
i = 0
cursor.execute("select * from aurora_data_api_test")
for f in cursor:
if i == 0:
self.assertEqual(f, expect_row0)
i += 1
self.assertEqual(i, 2048)
cursor.execute("select * from aurora_data_api_test")
data = cursor.fetchall()
self.assertEqual(data[0], expect_row0)
self.assertEqual(data[-1][0], 2048)
self.assertEqual(data[-1][1], 'row2047')
if not self.using_mysql:
self.assertEqual(json.loads(data[-1][2]), {"x": 2047, "y": str(2047), "z": [2047, 2047 * 2047, 0]})
self.assertEqual(data[-1][-2], decimal.Decimal("2047.2047"))
self.assertEqual(len(data), 2048)
self.assertEqual(len(cursor.fetchall()), 0)
cursor.execute("select * from aurora_data_api_test")
i = 0
while True:
if not cursor.fetchone():
break
i += 1
self.assertEqual(i, 2048)
cursor.execute("select * from aurora_data_api_test")
while True:
fm = cursor.fetchmany(1001)
if not fm:
break
self.assertIn(len(fm), [1001, 46])
@unittest.skip("This test now fails because the API was changed to terminate and delete the transaction when the "
"data returned by the statement exceeds the limit, making automated recovery impossible.")
def test_pagination_backoff(self):
if self.using_mysql:
return
with aurora_data_api.connect(database=self.db_name) as conn, conn.cursor() as cur:
sql_template = "select concat({}) from aurora_data_api_test"
sql = sql_template.format(", ".join(["cast(doc as text)"] * 64))
cur.execute(sql)
self.assertEqual(len(cur.fetchall()), 2048)
concat_args = ", ".join(["cast(doc as text)"] * 100)
sql = sql_template.format(", ".join("concat({})".format(concat_args) for i in range(32)))
cur.execute(sql)
with self.assertRaisesRegex(conn._client.exceptions.BadRequestException,
"Database response exceeded size limit"):
cur.fetchall()
def test_postgres_exceptions(self):
if self.using_mysql:
return
with aurora_data_api.connect(database=self.db_name) as conn, conn.cursor() as cur:
table = "aurora_data_api_nonexistent_test_table"
with self.assertRaises(aurora_data_api.DatabaseError) as e:
sql = f"select * from {table}"
cur.execute(sql)
self.assertEqual(e.exception.args, (PostgreSQLErrorCodes.ER_UNDEF_TABLE,
f'relation "{table}" does not exist',
15))
def test_rowcount(self):
with aurora_data_api.connect(database=self.db_name) as conn, conn.cursor() as cur:
cur.execute("select * from aurora_data_api_test limit 8")
self.assertEqual(cur.rowcount, 8)
with aurora_data_api.connect(database=self.db_name) as conn, conn.cursor() as cur:
cur.execute("select * from aurora_data_api_test limit 9000")
self.assertEqual(cur.rowcount, 2048)
if self.using_mysql:
return
with aurora_data_api.connect(database=self.db_name) as conn, conn.cursor() as cur:
cur.executemany("INSERT INTO aurora_data_api_test(name, doc) VALUES (:name, CAST(:doc AS JSONB))", [{
"name": "rowcount{}".format(i),
"doc": json.dumps({"x": i, "y": str(i), "z": [i, i * i, i ** i if i < 512 else 0]})
} for i in range(8)])
cur.execute("UPDATE aurora_data_api_test SET doc = '{}' WHERE name like 'rowcount%'")
self.assertEqual(cur.rowcount, 8)
cur.execute("DELETE FROM aurora_data_api_test WHERE name like 'rowcount%'")
self.assertEqual(cur.rowcount, 8)
def test_continue_after_timeout(self):
if os.environ.get("TEST_CONTINUE_AFTER_TIMEOUT", "False") != "True":
self.skipTest("TEST_CONTINUE_AFTER_TIMEOUT env var is not 'True'")
if self.using_mysql:
self.skipTest("Not implemented for MySQL")
try:
with aurora_data_api.connect(database=self.db_name) as conn, conn.cursor() as cur:
with self.assertRaisesRegex(conn._client.exceptions.ClientError, "StatementTimeoutException"):
cur.execute(("INSERT INTO aurora_data_api_test(name) SELECT 'continue_after_timeout'"
"FROM (SELECT pg_sleep(50)) q"))
with self.assertRaisesRegex(aurora_data_api.DatabaseError, "current transaction is aborted"):
cur.execute("SELECT COUNT(*) FROM aurora_data_api_test WHERE name = 'continue_after_timeout'")
with aurora_data_api.connect(database=self.db_name) as conn, conn.cursor() as cur:
cur.execute("SELECT COUNT(*) FROM aurora_data_api_test WHERE name = 'continue_after_timeout'")
self.assertEqual(cur.fetchone(), (0,))
with aurora_data_api.connect(database=self.db_name,
continue_after_timeout=True) as conn, conn.cursor() as cur:
with self.assertRaisesRegex(conn._client.exceptions.ClientError, "StatementTimeoutException"):
cur.execute(("INSERT INTO aurora_data_api_test(name) SELECT 'continue_after_timeout' "
"FROM (SELECT pg_sleep(50)) q"))
cur.execute("SELECT COUNT(*) FROM aurora_data_api_test WHERE name = 'continue_after_timeout'")
self.assertEqual(cur.fetchone(), (1,))
finally:
with aurora_data_api.connect(database=self.db_name) as conn, conn.cursor() as cur:
cur.execute("DELETE FROM aurora_data_api_test WHERE name = 'continue_after_timeout'")
if __name__ == "__main__":
unittest.main()
| python |
"""Abfallplus sensor platform."""
from homeassistant import config_entries, core
import babel.dates
from homeassistant.components.sensor import (
SensorEntity,
SensorEntityDescription,
)
from .const import DOMAIN
async def async_setup_entry(
hass: core.HomeAssistant,
config_entry: config_entries.ConfigEntry,
async_add_entities,
):
"""Setup sensors from a config entry created in the integrations UI."""
api_handler = hass.data[DOMAIN][config_entry.entry_id]
sensors = []
for waster_type in api_handler.api.config["abfallarten"]:
sensors.append(
WasteSensor(
api_handler,
SensorEntityDescription(
key=waster_type["name"], name=waster_type["name"]
),
)
)
async_add_entities(sensors, update_before_add=True)
class WasteSensor(SensorEntity):
"""Representation of a Abfallsplus sensor."""
_attr_should_poll = False
def __init__(self, api_handler, description):
super().__init__()
self.api_handler = api_handler
self.entity_description = description
self._attr_name = description.name
self._attr_unique_id = (
self.api_handler.api.config["community"]["name"] + "_" + description.name
)
self._attributes: dict[str, str] = {}
@property
def icon(self):
"""Icon to use in the frontend, if any."""
return "mdi:trash-can"
@property
def extra_state_attributes(self):
"""Return the state attributes of the binary sensor."""
return self._attributes
async def async_update(self):
"""Get latest cached states from the device."""
if (
self.api_handler.data is not None
and len(self.api_handler.data[self._attr_name]) >= 2
):
date = self.api_handler.data[self._attr_name][0]
friendly_value = babel.dates.format_datetime(date,
"EEE d. MMM",
locale="de_DE")
self._attr_native_value = friendly_value
self._attributes = {
"übernächstes Mal": str(self.api_handler.data[self._attr_name][1])
}
def update_callback(self):
"""Schedule a state update."""
self.async_schedule_update_ha_state(True)
async def async_added_to_hass(self):
"""Add update callback after being added to hass."""
self.api_handler.add_update_listener(self.update_callback)
| python |
from ctapipe.core import Component
class IntensityFitter(Component):
"""
This is the base class from which all muon intensity,
impact parameter and ring width fitters should inherit from
"""
def fit(self, x, y, charge, center_x, center_y, radius, times=None):
"""
overwrite this method with your favourite muon intensity fitting
algorithm
Parameters
----------
x: array
vector of pixel x-coordinates as astropy quantities
y: array
vector of pixel y-coordinates as astropy quantities
charge:
array of pixel charges as astropy quantities
center_x:
previously fitted ring center position x as astropy quantity
center_y:
previously fitted ring center position y as astropy quantity
radius:
previously fitted ring radius as astropy quantity
times: array
optional vector of pixel DAQ times as astropy quantities
Returns
-------
impact_x, impact_y, size, efficiency
"""
pass
| python |
import os
import subprocess
from gen_tools import run_ftool, ftool_mp, run_ftool2
import argparse
import numpy as np
import time
from astropy.table import Table
import pandas as pd
def run_ftjoin_mp(dname, dname2, fnames, nproc):
ftool = "ftjoin"
arg_lists = []
for fname in fnames:
arg_list = [ftool]
fnew = dname2 + fname[:21]
f_name = dname + fname
arg_list += [f_name+'[ATTITUDE]',\
f_name+'[ACS_DATA]']
arg_list.append(fnew)
arg_list += ["TIME==TIME_", 'leftnameprefix=NONE',\
'rightnameprefix=NONE',\
'rightnamesuffix=_']
arg_lists.append(arg_list)
print("Opening pool of %d workers" %(nproc))
t0 = time.time()
p = mp.Pool(nproc, init_worker)
print(os.getpid())
print("active children: ", mp.active_children())
try:
p.map(run_ftool_mp, arg_lists, chunksize=10)
except KeyboardInterrupt:
print("active children: ", mp.active_children())
p.terminate()
p.join()
print("terminate, join")
print("active children: ", mp.active_children())
sys.exit()
print("active children: ", mp.active_children())
p.close()
p.join()
print("close, join")
print("active children: ", mp.active_children())
print("Finished in %.3f seconds" %(time.time()-t0))
def do_ray_trace(out_fname, att_fname, ra, dec, time, detmask, infile):
ftool = "batmaskwtimg"
arg_list = [out_fname, att_fname, str(ra), str(dec)]
arg_list += ["time=%.2f" %(time), "rebalance=NO",
"corrections=forward,unbalanced,flatfield",
"detmask="+detmask, "infile="+infile]
run_ftool(ftool, arg_list)
def do_ray_trace_ra_dec_list(out_fname, att_fname, ras, decs, time, detmask, infile):
ftool = "batmaskwtimg"
for i in range(len(ras)):
outf = out_fname + '_%.2f_%.2f.img' %(ras[i], decs[i])
arg_list = [outf, att_fname, str(ras[i]), str(decs[i])]
arg_list += ["time=%.2f" %(time), "rebalance=NO",
"corrections=forward,unbalanced,flatfield",
"detmask="+detmask, "infile="+infile]
#arg_list += ["time=%.2f" %(time), "rebalance=NO",
# "corrections=forward,unbalanced,flatfield",
# "infile="+infile]
run_ftool(ftool, arg_list)
def do_ray_trace_imxy_list(out_fname, att_fname, imxs, imys, time, detmask, infile):
ftool = "batmaskwtimg"
for i in range(len(imxs)):
outf = out_fname + '_%.5f_%.5f.img' %(imxs[i], imys[i])
arg_list = [outf, att_fname, str(imxs[i]), str(imys[i])]
arg_list += ["time=%.2f" %(time), "rebalance=NO",
"corrections=forward,unbalanced,flatfield",
"detmask="+detmask, "infile="+infile, 'coord_type=tanxy']
run_ftool(ftool, arg_list)
def do_footprint_imxy_tab(out_fname, att_fname, imxs, imys,\
detmask, infile, incat, detapp=False):
ftool = "batmaskwtimg"
#for i in xrange(len(imxs)):
outf = out_fname + '_%.5f_%.5f_%.5f_%.5f_.img'\
%(np.min(imxs), np.min(imys), np.max(imxs), np.max(imys))
if os.path.isfile(outf):
print("already made")
return
arg_list = [outf, att_fname, "0.0", "0.0"]
arg_list += ["outtype=NONZERO",
"detmask="+detmask, "infile="+infile, 'coord_type=tanxy',
"incatalog="+incat, "racol=IMX", "deccol=IMY",
"catnumcol=NONE", "chatter=1", "distfile=CALDB"]
if detapp:
arg_list.append("aperture=CALDB:DETECTION")
run_ftool(ftool, arg_list)
def do_ray_trace_imxy_tab(out_fname, att_fname, imxs, imys,\
detmask, infile, incat, detapp=False):
ftool = "batmaskwtimg"
#for i in xrange(len(imxs)):
outf = out_fname + '_%.5f_%.5f_%.5f_%.5f_.img'\
%(np.min(imxs), np.min(imys), np.max(imxs), np.max(imys))
if os.path.isfile(outf):
print("already made")
return
arg_list = [outf, att_fname, "0.0", "0.0"]
arg_list += ["rebalance=NO",
"corrections=forward,unbalanced,flatfield,subpixelate",
"detmask="+detmask, "infile="+infile, 'coord_type=tanxy',
"incatalog="+incat, "racol=IMX", "deccol=IMY",
"catnumcol=NONE", "chatter=1", "distfile=CALDB"]
if detapp:
arg_list.append("aperture=CALDB:DETECTION")
run_ftool(ftool, arg_list)
def mk_imxy_tab(imxs, imys, fname):
names = ['IMX', 'IMY', 'NAME']
grid_x, grid_y = np.meshgrid(imxs, imys, indexing='ij')
tab = Table()
tab['IMX'] = grid_x.ravel()
tab['IMY'] = grid_y.ravel()
names = np.array(['%.5f %.5f' %(tab['IMX'][i], tab['IMY'][i]) for i in range(len(tab))])
tab['NAME'] = names
print(len(tab), " positions to do")
tab.write(fname, overwrite=True)
def ev2pha(infile, outfile, tstart, tstop, ebins, detmask):
ftool = "batbinevt"
arg_list = [infile, outfile, 'PHA', '0', 'uniform', ebins]
arg_list += ['tstart='+str(tstart), 'tstop='+str(tstop), 'detmask='+detmask]
run_ftool(ftool, arg_list)
def pha_sys_err(infile, auxfile):
ftool = "batupdatephakw"
arg_list = [infile, auxfile]
run_ftool(ftool, arg_list)
ftool = "batphasyserr"
arg_list = [infile, "CALDB"]
run_ftool(ftool, arg_list)
def mk_small_evt(infile, outfile):
ftool = "fextract-events"
arg_list = [infile+"[pha=100:101]", outfile, "gti=GTI"]
run_ftool(ftool, arg_list)
def mk_rt_aux_file(infile, outfile, imx, imy, dmask, attfile, ra, dec):
ftool = "batmaskwtevt"
arg_list = [infile, attfile, str(ra), str(dec)]
arg_list += ["coord_type=sky",
"auxfile="+outfile, "clobber=True",\
"detmask="+dmask]
run_ftool(ftool, arg_list)
def mk_drm(pha, outfile, dapfile):
ftool = "batdrmgen"
arg_list = [pha, outfile, dapfile, "method=TABLE"]
run_ftool(ftool, arg_list)
def bateconvert(infile, calfile):
ftool = "bateconvert"
arg_list = ['infile='+infile, 'calfile='+calfile, 'residfile=CALDB']
run_ftool(ftool, arg_list)
def detmask(infile, outfile, dmask):
ftool = "batdetmask"
arg_list = [infile, outfile, 'detmask='+dmask]
run_ftool(ftool, arg_list)
def mk_bkg_mod(infile, outfile, detmask):
ftool = "batclean"
arg_list = [infile, outfile]
arg_list += ['incatalog=NONE', 'detmask='+detmask, 'srcclean=NO', 'outversion=bkgfit']
run_ftool(ftool, arg_list)
def mk_pc_img(infile, outfile, detmask, attfile):
ftool = "batfftimage"
arg_list = [infile, outfile]
arg_list += ['detmask='+detmask, 'attitude='+attfile, 'pcodemap=YES']
run_ftool(ftool, arg_list)
def cli():
#default_ebins = '15-40, 25-60, 50-80, 70-100, 90-135, 120-165, 150-195'
parser = argparse.ArgumentParser()
parser.add_argument('--infile', type=str,\
help="In File Name needed for batmaskwtimg",\
default="/storage/work/jjd330/local/bat_data/pha.pha")
parser.add_argument('--t0', type=float,\
help="Start time in MET seconds",\
default=4e8)
parser.add_argument('--imx0', type=float,\
help="imx low value",\
default=0.0)
parser.add_argument('--imy0', type=float,\
help="imy low value",\
default=0.0)
parser.add_argument('--imx1', type=float,\
help="imx high value",\
default=0.1)
parser.add_argument('--imy1', type=float,\
help="imy high value",\
default=0.1)
parser.add_argument('--rtstep', type=float,\
help="step size in imx/y for ray tracing",\
default=0.002)
parser.add_argument('--pcmin', type=float,\
help="Min Partial coding used",\
default=1e-2)
parser.add_argument('--imrng', type=float,\
help="range for imx/y around center point or all",\
default=0.02)
parser.add_argument('--rtdir', type=str,\
help="Directory to save ray traces to",\
default='/storage/home/jjd330/scratch/bat_data/ray_traces/')
parser.add_argument('--imxy_file', type=str,\
help="file with imxys to do",\
default=None)
parser.add_argument('--Njobs', type=int,\
help="Total number of jobs",\
default=1)
parser.add_argument('--job_id', type=int,\
help="Job ID",\
default=-1)
parser.add_argument('--detapp',\
help="Use the detecion aperture",\
action='store_true')
parser.add_argument('--footprint',\
help="Do footprints instead of maskwts",\
action='store_true')
args = parser.parse_args()
return args
def main(args):
t_0 = time.time()
rng = args.imrng
if args.imxy_file is not None:
df_imxy = pd.read_csv(args.imxy_file)
Npnts = len(df_imxy)
Npnts2do = 1 + Npnts/args.Njobs
i0 = args.job_id*Npnts2do
i1 = i0 + Npnts2do
if args.job_id < 0:
i0 = 0
i1 = Npnts
Npnts2do = Npnts
print("%d total to do" %(Npnts))
print("doing %d here" %(Npnts2do))
df = df_imxy[i0:i1]
i=0
for ind, row in df.iterrows():
imx0 = row['imx0']
imx1 = row['imx1']
imy0 = row['imy0']
imy1 = row['imy1']
imxs = np.linspace(imx0, imx1, int(rng/args.rtstep)+1)
imys = np.linspace(imy0, imy1, int(rng/args.rtstep)+1)
imxs = np.arange(imx0, imx1, args.rtstep)
if not np.isclose(imxs[-1], imx1):
imxs = np.append(imxs, [imx1])
imys = np.arange(imy0, imy1, args.rtstep)
if not np.isclose(imys[-1], imy1):
imys = np.append(imys, [imy1])
print("imxs")
print(imxs)
print("imys")
print(imys)
tab_fn = 'tab_%.5f_%.5f_%.5f_%.5f_.fits'\
%(np.min(imxs), np.min(imys), np.max(imxs), np.max(imys))
# make a catalog table to pass to batmaskwtimg
tab_fname = os.path.join(args.rtdir, tab_fn)
mk_imxy_tab(imxs, imys, tab_fname)
if args.footprint:
out_fname = os.path.join(args.rtdir, 'footprint')
do_footprint_imxy_tab(out_fname, "NONE", imxs, imys,\
"NONE", args.infile, tab_fname, detapp=args.detapp)
else:
out_fname = os.path.join(args.rtdir, 'fwd_ray_trace')
do_ray_trace_imxy_tab(out_fname, "NONE", imxs, imys,\
"NONE", args.infile, tab_fname, detapp=args.detapp)
print("Took %.2f seconds, %.2f minutes so far, done with %d of %d" %(time.time()-t_0,\
(time.time()-t_0)/60., i+1, Npnts2do))
i+=1
else:
nx_steps = int((args.imx1 - args.imx0)/rng) + 1
ny_steps = int((args.imy1 - args.imy0)/rng) + 1
print(nx_steps*ny_steps, " ray traces to make")
if not os.path.exists(args.rtdir):
os.makedirs(args.rtdir)
for i in range(nx_steps):
imx0 = args.imx0 + i*rng
imx1 = imx0 + rng
for j in range(ny_steps):
imy0 = args.imy0 + j*rng
imy1 = imy0 + rng
imxs = np.linspace(imx0, imx1, int(rng/args.rtstep)+1)
imys = np.linspace(imy0, imy1, int(rng/args.rtstep)+1)
imxs = np.arange(imx0, imx1, args.rtstep)
if not np.isclose(imxs[-1], imx1):
imxs = np.append(imxs, [imx1])
imys = np.arange(imy0, imy1, args.rtstep)
if not np.isclose(imys[-1], imy1):
imys = np.append(imys, [imy1])
print("imxs")
print(imxs)
print("imys")
print(imys)
tab_fn = 'tab_%.5f_%.5f_%.5f_%.5f_.fits'\
%(np.min(imxs), np.min(imys), np.max(imxs), np.max(imys))
# make a catalog table to pass to batmaskwtimg
tab_fname = os.path.join(args.rtdir, tab_fn)
mk_imxy_tab(imxs, imys, tab_fname)
if args.footprint:
out_fname = os.path.join(args.rtdir, 'footprint')
do_footprint_imxy_tab(out_fname, "NONE", imxs, imys,\
"NONE", args.infile, tab_fname, detapp=args.detapp)
else:
out_fname = os.path.join(args.rtdir, 'fwd_ray_trace')
do_ray_trace_imxy_tab(out_fname, "NONE", imxs, imys,\
"NONE", args.infile, tab_fname, detapp=args.detapp)
print("Took %.2f seconds, %.2f minutes so far, done with %d of %d" %(time.time()-t_0,\
(time.time()-t_0)/60., (i*ny_steps + j + 1), (nx_steps*ny_steps)))
print("Took %.2f seconds, %.2f minutes to do everything" %(time.time()-t_0, (time.time()-t_0)/60.))
if __name__ == '__main__':
args = cli()
main(args)
| python |
import os
import easypost
from dotenv import load_dotenv
# Retrieve a list of paginated records such as scanforms or shipments.
# Because EasyPost paginates lists of records at a max of 100 items, you may at times need to iterate the pages.
# This tool will combine all records between two dates and print their IDs and timestamps to console along with
# how many pages were retrieved. You can also filter the larger list fo records by passing a comma separated list
# of records IDs to the `FILTER` env variable. See usage example below for more info.
#
# Usage: EASYPOST_TEST_API_KEY=123 FILTER="sf_123,sf_456" START_DATE="2020-05-01T00:00:00Z" \
# END_DATE="2020-06-02T00:00:00Z" venv/bin/python retrieve_paginated_records.py
load_dotenv()
EASYPOST_TEST_API_KEY = os.getenv('EASYPOST_TEST_API_KEY')
START_DATE = os.getenv('START_DATE', '2020-05-01T00:00:00Z')
END_DATE = os.getenv('END_DATE', '2020-06-02T00:00:00Z')
PAGE_SIZE = os.getenv('PAGE_SIZE', 100) # The EasyPost API maxes out at 100 records per page
RECORDS_TO_FILTER = os.getenv('FILTER') # Provide a comma-separated string of record IDs to filter by
def main():
easypost.api_key = EASYPOST_TEST_API_KEY
all_records, num_of_pages = get_paginated_records()
for record in all_records:
formatted_records_to_filter = RECORDS_TO_FILTER.lower().split(',') if RECORDS_TO_FILTER else ''
if not RECORDS_TO_FILTER or (RECORDS_TO_FILTER and record.id in formatted_records_to_filter):
print(f'{record.id}: {record.created_at}')
print(f'Number of pages: {str(num_of_pages)}')
return all_records, num_of_pages
def get_paginated_records(all_records=[], last_record_id=None, num_of_pages=1):
# TODO: Make this dynamic, can be items like [ScanForm, Shipment]
records = easypost.ScanForm.all(
start_datetime=START_DATE,
end_datetime=END_DATE,
before_id=last_record_id,
page_size=PAGE_SIZE,
)
# TODO: Make this dynamic, can be items like ['scan_forms', 'shipments']
for record in records['scan_forms']:
all_records.append(record)
if records.has_more:
# TODO: Make this dynamic, can be items like [scan_forms, shipments]
last_record_id = records.scan_forms[-1].id
num_of_pages += 1
all_records, num_of_pages = get_paginated_records(all_records, last_record_id, num_of_pages)
return all_records, num_of_pages
if __name__ == '__main__':
main()
| python |
#!/usr/bin/env python
import os
import re
import plotly
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
import plotly.graph_objs as go
import pandas as pd
import numpy as np
from sklearn.datasets import load_wine
from shutil import copyfile
def loadWineDataSet():
data = load_wine()
df = pd.DataFrame(data.data, columns=data.feature_names)
c1 = pd.DataFrame(columns=data.feature_names)
c2 = pd.DataFrame(columns=data.feature_names)
c3 = pd.DataFrame(columns=data.feature_names)
for idx in range(len(df)):
if data.target[idx] == 0:
c1 = c1.append(df.iloc[idx])
#print(idx, df.iloc[idx])
if data.target[idx] == 1:
c2 = c2.append(df.iloc[idx])
#print(idx, df.iloc[idx])
if data.target[idx] == 2:
c3 = c3.append(df.iloc[idx])
return (c1,c2,c3)
def PlotFeatures(c1,c2,c3):
numplots=0
print("\n\n Message: Printing only 200 graph then stopping ......\n\n")
attr = len(c1.columns)
characteristics = c1.columns
featlist=characteristics.tolist()
#for hdx in range(0,attr):
# featlist[hdx] = re.sub(r"/","_",featlist[hdx])
if not os.path.exists('images1160'):
os.mkdir('images1160')
for idx in range(0,attr):
feat1 = characteristics[idx]
c1feat1 = c1.loc[:,feat1]
c2feat1 = c2.loc[:,feat1]
c3feat1 = c3.loc[:,feat1]
feat1 = re.sub(r"/","_",characteristics[idx])
for jdx in range(idx+1, attr):
feat2 = characteristics[jdx]
c1feat2 = c1.loc[:,feat2]
c2feat2 = c2.loc[:,feat2]
c3feat2 = c3.loc[:,feat2]
feat2 = re.sub(r"/","_",characteristics[jdx])
for kdx in range(jdx+1, attr):
feat3 = characteristics[kdx]
c1feat3 = c1.loc[:,feat3]
c2feat3 = c2.loc[:,feat3]
c3feat3 = c3.loc[:,feat3]
feat3 = re.sub(r"/","_",characteristics[kdx])
for ldx in range(kdx+1, attr):
feat4 = characteristics[ldx]
c1feat4 = c1.loc[:,feat4]
c2feat4 = c2.loc[:,feat4]
c3feat4 = c3.loc[:,feat4]
feat4 = re.sub(r"/","_",characteristics[ldx])
for mdx in range(ldx+1, attr):
feat5 = characteristics[mdx]
c1feat5 = c1.loc[:,feat5]
c2feat5 = c2.loc[:,feat5]
c3feat5 = c3.loc[:,feat5]
feat5 = re.sub(r"/","_",characteristics[mdx])
layout = go.Layout(
width=1600,
height=1200,
title = feat1 + " - " + feat2 + " - " + feat3 + " - " + feat4 + " - " + feat5,
xaxis=dict(
showgrid=True,
gridwidth=1,
title=feat1+","+feat2+","+feat3+","+feat4
),
yaxis=dict(
showgrid=True,
rangemode='tozero',
gridwidth=1,
title=feat2+","+feat3+","+feat4+","+feat5
)
)
trace1 = go.Scatter(x=c1feat1,y=c1feat2,mode = 'markers',name='c1, '+feat1+', '+feat2, marker={'symbol': 104, 'size': 8,'color':'#0000ff'})
trace2 = go.Scatter(x=c2feat1,y=c2feat2,mode = 'markers',name='c2, '+feat1+', '+feat2, marker={'symbol': 1, 'size': 8,'color':'#0000ff'})
trace3 = go.Scatter(x=c3feat1,y=c3feat2,mode = 'markers',name='c3, '+feat1+', '+feat2, marker={'symbol': 'star', 'size': 8,'color':'#0000ff'})
trace4 = go.Scatter(x=c1feat1,y=c1feat3,mode = 'markers',name='c1, '+feat1+', '+feat3, marker={'symbol': 104, 'size': 8,'color':'#ff2800'})
trace5 = go.Scatter(x=c2feat1,y=c2feat3,mode = 'markers',name='c2, '+feat1+', '+feat3, marker={'symbol': 1, 'size': 8,'color':'#ff2800'})
trace6 = go.Scatter(x=c3feat1,y=c3feat3,mode = 'markers',name='c3, '+feat1+', '+feat3, marker={'symbol': 'star', 'size': 8,'color':'#ff2800'})
trace7 = go.Scatter(x=c1feat1,y=c1feat4,mode = 'markers',name='c1, '+feat1+', '+feat4, marker={'symbol': 104, 'size': 8,'color':'#71bc78'})
trace8 = go.Scatter(x=c2feat1,y=c2feat4,mode = 'markers',name='c2, '+feat1+', '+feat4, marker={'symbol': 1, 'size': 8,'color':'#71bc78'})
trace9 = go.Scatter(x=c3feat1,y=c3feat4,mode = 'markers',name='c3, '+feat1+', '+feat4, marker={'symbol': 'star', 'size': 8,'color':'#71bc78'})
trace10 = go.Scatter(x=c1feat1,y=c1feat5,mode = 'markers',name='c1, '+feat1+', '+feat5, marker={'symbol': 104, 'size': 8,'color':'#ffbf00'})
trace11 = go.Scatter(x=c2feat1,y=c2feat5,mode = 'markers',name='c2, '+feat1+', '+feat5, marker={'symbol': 1, 'size': 8,'color':'#ffbf00'})
trace12 = go.Scatter(x=c3feat1,y=c3feat5,mode = 'markers',name='c3, '+feat1+', '+feat5, marker={'symbol': 'star', 'size': 8,'color':'#ffbf00'})
trace13 = go.Scatter(x=c1feat2,y=c1feat3,mode = 'markers',name='c1, '+feat2+', '+feat3, marker={'symbol': 104, 'size': 8,'color':'#ff1493'})
trace14 = go.Scatter(x=c2feat2,y=c2feat3,mode = 'markers',name='c2, '+feat2+', '+feat3, marker={'symbol': 1, 'size': 8,'color':'#ff1493'})
trace15 = go.Scatter(x=c3feat2,y=c3feat3,mode = 'markers',name='c3, '+feat2+', '+feat3, marker={'symbol': 'star', 'size': 8,'color':'#ff1493'})
trace16 = go.Scatter(x=c1feat2,y=c1feat4,mode = 'markers',name='c1, '+feat2+', '+feat4, marker={'symbol': 104, 'size': 8,'color':'#ccff00'})
trace17 = go.Scatter(x=c2feat2,y=c2feat4,mode = 'markers',name='c2, '+feat2+', '+feat4, marker={'symbol': 1, 'size': 8,'color':'#ccff00'})
trace18 = go.Scatter(x=c3feat2,y=c3feat4,mode = 'markers',name='c3, '+feat2+', '+feat4, marker={'symbol': 'star', 'size': 8,'color':'#ccff00'})
trace19 = go.Scatter(x=c1feat2,y=c1feat5,mode = 'markers',name='c1, '+feat2+', '+feat5, marker={'symbol': 104, 'size': 8,'color':'#ff00ff'})
trace20 = go.Scatter(x=c2feat2,y=c2feat5,mode = 'markers',name='c2, '+feat2+', '+feat5, marker={'symbol': 1, 'size': 8,'color':'#ff00ff'})
trace21 = go.Scatter(x=c3feat2,y=c3feat5,mode = 'markers',name='c3, '+feat2+', '+feat5, marker={'symbol': 'star', 'size': 8,'color':'#ff00ff'})
trace22 = go.Scatter(x=c1feat3,y=c1feat4,mode = 'markers',name='c1, '+feat3+', '+feat4, marker={'symbol': 104, 'size': 8,'color':'#a52a2a'})
trace23 = go.Scatter(x=c2feat3,y=c2feat4,mode = 'markers',name='c2, '+feat3+', '+feat4, marker={'symbol': 1, 'size': 8,'color':'#a52a2a'})
trace24 = go.Scatter(x=c3feat3,y=c3feat4,mode = 'markers',name='c3, '+feat3+', '+feat4, marker={'symbol': 'star', 'size': 8,'color':'#a52a2a'})
trace25 = go.Scatter(x=c1feat3,y=c1feat5,mode = 'markers',name='c1, '+feat3+', '+feat5, marker={'symbol': 104, 'size': 8,'color':'#738678'})
trace26 = go.Scatter(x=c2feat3,y=c2feat5,mode = 'markers',name='c2, '+feat3+', '+feat5, marker={'symbol': 1, 'size': 8,'color':'#738678'})
trace27 = go.Scatter(x=c3feat3,y=c3feat5,mode = 'markers',name='c3, '+feat3+', '+feat5, marker={'symbol': 'star', 'size': 8,'color':'#738678'})
trace28 = go.Scatter(x=c1feat4,y=c1feat5,mode = 'markers',name='c1, '+feat4+', '+feat5, marker={'symbol': 104, 'size': 8,'color':'#a020f0'})
trace29 = go.Scatter(x=c2feat4,y=c2feat5,mode = 'markers',name='c2, '+feat4+', '+feat5, marker={'symbol': 1, 'size': 8,'color':'#a020f0'})
trace30 = go.Scatter(x=c3feat4,y=c3feat5,mode = 'markers',name='c3, '+feat4+', '+feat5, marker={'symbol': 'star', 'size': 8,'color':'#a020f0'})
data = [trace1,trace2,trace3,trace4,trace5,trace6,trace7,trace8,trace9,trace10,trace11,trace12,trace13,trace14,trace15,
trace16,trace17,trace18,trace19,trace20,trace21,trace22,trace23,trace24,trace25,trace26,trace27,trace28,trace29,trace30]
fig = go.Figure(data=data,layout=layout)
plot(fig,auto_open=False)
filename = feat1+"_"+feat2+"_"+feat3+"_"+feat4+"_"+feat5
print(filename)
dload = os.path.expanduser('./')
save_dir = './'
#plot(fig, image_filename=filename, image='png', auto_open=False)
plotly.offline.plot(fig, filename=filename+'.html', auto_open=False)
#copyfile('{}/{}.png'.format(dload, filename),
# '{}/{}.png'.format(save_dir, filename))
numplots+=1
if (numplots==200):
print("\n message:....... Printed 200 graphs exiting.....\n",numplots)
exit()
def Wine():
c1,c2,c3 = loadWineDataSet()
PlotFeatures(c1,c2,c3)
print("\n* * * * * * * * * * ")
print("* THE END * ")
print("\n* * * * * * * * * * ")
Wine()
| python |
from telegram.ext import Updater
import random
from datetime import datetime
import requests
import pyowm
import re
import os
from flask import Flask, request
import logging
import apiai
import json
import re
from on_event.work.text import *
from on_event.errors import *
def press_f(update, context):
if(update.message.text == 'F'):
press_f_answer(update, context)
def weather(update, context):
if (update.message.text.lower().find("weather") >= 0) and (update.message.text.lower().find("\"") >= 0):
try:
result = re.search(
r'\"\w{2,}\"', str(update.message.text.lower()))
weather_answer(update, context, str(
result.group(0)[1:-1]).capitalize())
except:
init_errors(update, context, '0001')
def findWholeWord(w):
return re.compile(r'\b({0})\b'.format(w), flags=re.IGNORECASE).search
def other(update, context):
if(findWholeWord('bot tell')(update.message.text.lower())):
request = apiai.ApiAI(
'***id***').text_request()
request.lang = 'en'
request.session_id = '***'
request.query = update.message.text[len('Bot tell, '):]
responseJson = json.loads(request.getresponse().read().decode('utf-8'))
response = responseJson['result']['fulfillment']['speech']
if response:
update.message.reply_text(response)
def init(update, context):
press_f(update, context)
weather(update, context)
other(update, context)
| python |
import numpy as np
from unittest import TestCase
from aspire.source import SourceFilter
from aspire.source.simulation import Simulation
from aspire.utils.filters import RadialCTFFilter
from aspire.estimation.noise import WhiteNoiseEstimator
import os.path
DATA_DIR = os.path.join(os.path.dirname(__file__), 'saved_test_data')
class SimTestCase(TestCase):
def setUp(self):
self.sim = Simulation(
n=1024,
filters=SourceFilter(
[RadialCTFFilter(defocus=d) for d in np.linspace(1.5e4, 2.5e4, 7)],
n=1024
)
)
def tearDown(self):
pass
def testWhiteNoise(self):
noise_estimator = WhiteNoiseEstimator(self.sim, batchSize=512)
noise_variance = noise_estimator.estimate()
self.assertAlmostEqual(noise_variance, 0.00307627)
| python |
from adafruit_circuitplayground.express import cpx
while True:
# Left returns True. Right returns False.
cpx.red_led = cpx.switch
| python |
from collections import defaultdict
import logging
from typing import Dict
import ray
from horovod.ray.utils import map_blocking
from horovod.ray.worker import BaseHorovodWorker
logger = logging.getLogger(__name__)
def create_placement_group(resources_per_bundle: Dict[str, int],
num_bundles: int, pg_timeout: int,
pg_strategy: str):
bundles = [resources_per_bundle.copy() for _ in range(num_bundles)]
pg = ray.util.placement_group(bundles, strategy=pg_strategy)
logger.debug("Waiting for placement group to start.")
ready, _ = ray.wait([pg.ready()], timeout=pg_timeout)
if ready:
logger.debug("Placement group has started.")
else:
raise TimeoutError("Placement group creation timed out. Make sure "
"your cluster either has enough resources or use "
"an autoscaling cluster. Current resources "
"available: {}, resources requested by the "
"placement group: {}".format(
ray.available_resources(), pg.bundle_specs))
return pg, bundles
class BaseStrategy:
"""Base class for implementing different placement strategies."""
placement_group = None
workers = None
def create_workers(self):
raise NotImplementedError
@property
def num_workers(self):
raise NotImplementedError
@classmethod
def get_node_workers(cls, workers):
"""Returns list of one worker per node to use for NIC detection."""
# In some setups (i.e., Peloton), ray nodes may not have
# unique host names.
hostnames = map_blocking(lambda w: w.hostname.remote(), workers)
host_worker_map = {}
for hostname, worker in zip(hostnames, workers):
host_worker_map[hostname] = worker
return list(host_worker_map.values())
def shutdown(self):
if self.placement_group:
ray.util.remove_placement_group(self.placement_group)
self.workers = []
self.placement_group = None
class ColocatedStrategy(BaseStrategy):
"""Ensures that the workers are balanced across all hosts."""
def __init__(self, *, settings, num_hosts: int, num_workers_per_host: int,
use_gpu: bool, cpus_per_worker: int, gpus_per_worker: int):
self.settings = settings
self.num_hosts = num_hosts
self.num_workers_per_host = num_workers_per_host
self.use_gpu = use_gpu
self.cpus_per_worker = cpus_per_worker
self.gpus_per_worker = gpus_per_worker or 1
@property
def num_workers(self):
return self.num_hosts * self.num_workers_per_host
def _resources_per_host(self):
num_cpus = self.cpus_per_worker * self.num_workers_per_host
num_gpus = self.gpus_per_worker * self.num_workers_per_host * int(
self.use_gpu)
return dict(CPU=num_cpus, GPU=num_gpus)
def create_workers(self):
self.placement_group, bundles = create_placement_group(
resources_per_bundle=self._resources_per_host(),
num_bundles=self.num_hosts,
pg_timeout=self.settings.placement_group_timeout_s,
pg_strategy="STRICT_SPREAD")
# Placement group has started. Now create the workers.
self.workers = []
# STRICT_SPREAD guarantees each bundle is on a different node.
# Create num_workers_per_host workers per bundle, i.e. per machine.
for bundle_index in range(len(bundles)):
gpu_id_futures = []
curr_node_workers = []
remote_cls = ray.remote(BaseHorovodWorker)
for i in range(self.num_workers_per_host):
remote_cls_with_options = remote_cls.options(
num_cpus=self.cpus_per_worker,
num_gpus=self.gpus_per_worker * int(self.use_gpu),
placement_group=self.placement_group,
placement_group_bundle_index=bundle_index)
worker = remote_cls_with_options.remote(
world_rank=self.num_workers_per_host * bundle_index + i,
world_size=self.num_workers)
if self.use_gpu:
gpu_id_futures.append(worker.get_gpu_ids.remote())
self.workers.append(worker)
curr_node_workers.append(worker)
if len(gpu_id_futures) > 0:
# By setting CUDA VISIBLE DEVICES to ALL GPUs,
# CUDA will be able to detect adjacent devices and use IPC
# allowing for better performance.
gpu_ids = sum(ray.get(gpu_id_futures), [])
# Make sure that each worker on the node has unique device.
assert len(gpu_ids) == len(
set(gpu_ids)) == self.num_workers_per_host, gpu_ids
all_ids = ",".join([str(gpu_id) for gpu_id in gpu_ids])
futures = []
for worker in curr_node_workers:
futures.append(
worker.update_env_vars.remote({
"CUDA_VISIBLE_DEVICES":
all_ids
}))
ray.get(futures)
return self.workers, self.get_node_workers(self.workers)
class PackStrategy(BaseStrategy):
"""Packs workers together but does not guarantee balanced hosts."""
def __init__(self, *, settings, num_workers, use_gpu, cpus_per_worker,
gpus_per_worker):
self.settings = settings
self._num_workers = num_workers
self.cpus_per_worker = cpus_per_worker
self.gpus_per_worker = gpus_per_worker or 1
self.use_gpu = use_gpu
@property
def num_workers(self):
return self._num_workers
def resources_per_worker(self):
num_cpus = self.cpus_per_worker
num_gpus = self.gpus_per_worker * int(self.use_gpu)
return dict(CPU=num_cpus, GPU=num_gpus)
def create_workers(self):
self.placement_group, bundles = create_placement_group(
resources_per_bundle=self.resources_per_worker(),
num_bundles=self.num_workers,
pg_strategy="PACK",
pg_timeout=self.settings.placement_group_timeout_s)
# Placement group has started. Now create the workers.
self.workers = []
remote_cls = ray.remote(BaseHorovodWorker)
for bundle_index in range(len(bundles)):
remote_cls_with_options = remote_cls.options(
num_cpus=self.cpus_per_worker,
num_gpus=self.gpus_per_worker * int(self.use_gpu),
placement_group=self.placement_group,
placement_group_bundle_index=bundle_index)
worker = remote_cls_with_options.remote(
world_rank=bundle_index, world_size=self.num_workers)
self.workers.append(worker)
if self.use_gpu:
node_ids = ray.get(
[worker.node_id.remote() for worker in self.workers])
gpus = ray.get(
[worker.get_gpu_ids.remote() for worker in self.workers])
node_workers = defaultdict(list)
node_id_to_gpus = defaultdict(list)
for worker, node_id, worker_gpu_ids in zip(self.workers, node_ids,
gpus):
node_workers[node_id].append(worker)
node_id_to_gpus[node_id].extend(worker_gpu_ids)
futures = []
for node_id, gpu_ids in node_id_to_gpus.items():
all_ids = ",".join([str(gpu_id) for gpu_id in gpu_ids])
for worker in node_workers[node_id]:
futures.append(
worker.update_env_vars.remote({
"CUDA_VISIBLE_DEVICES":
all_ids
}))
ray.get(futures)
return self.workers, self.get_node_workers(self.workers)
| python |
from pathlib import Path
from django.conf import settings
from django.db.models import ImageField, FileField, Q
from django.contrib.contenttypes.models import ContentType
def move_media(*names, back=False):
"""Moves media files to or from a temporary directory."""
old, new = ('temp', '') if back else ('', 'temp')
media_root = Path(settings.MEDIA_ROOT)
for name in names:
old_path = media_root.joinpath(old, name)
if old_path.is_file():
new_path = media_root.joinpath(new, name)
try:
old_path.rename(new_path)
except FileNotFoundError:
new_path.parent.mkdir(parents=True)
old_path.rename(new_path)
def get_filefield_values(*ct_id):
"""Returns a list that contain queryset with values of the file fields."""
queryset_list = []
for i in ct_id:
model = ContentType.objects.get_for_id(i).model_class()
opts = getattr(model, '_meta')
fields = [f.attname for f in opts.get_fields() if (
isinstance(f, (ImageField, FileField)))]
if fields:
queryset_list.append(model.objects.values_list(*fields))
return queryset_list
def clean_media(*ct_id, dir_name=None):
"""
Cleans up media files whose names are not in a database.
Accepts content type id and directory for cleaning,
if the files are not in the database, they are moved to a deleted dir.
If the directory is not specified, the files existing in
the database are moved to a temp.
"""
media_root = Path(settings.MEDIA_ROOT)
queryset_list = get_filefield_values(*ct_id)
for queryset in queryset_list:
for names in queryset:
move_media(*names)
if dir_name is None:
return
deleted_path = media_root.joinpath('deleted', dir_name)
if not deleted_path.is_dir():
deleted_path.mkdir(parents=True)
for file in media_root.joinpath(dir_name).iterdir():
if file.is_file:
file.rename(deleted_path.joinpath(file.name))
for queryset in queryset_list:
for names in queryset:
move_media(*names, back=True)
def clean_shop_media():
"""Cleans up shop media files"""
ct_id = ContentType.objects.filter(
Q(model__endswith='product') | Q(model='specification'),
).values_list('id', flat=True)
clean_media(*ct_id, dir_name='shop')
| python |
# -*- coding: utf-8 -*-
from calysto.graphics import *
from calysto.display import display, clear_output
#image_width=512
image_width=0
canvas=None
color=None
rect=None
#初期化
def init(size, r, g, b):
global image_width
global canvas
global color
global rect
image_width=size
canvas=Canvas(size=(image_width, image_width))
color=Color(r, g, b)
rect=Rectangle(size=(image_width, image_width), fill=color, stroke=color)
#rect.fill(color)
# 線分を書く
def draw_line(p1_x, p1_y, p2_x, p2_y):
def conv(z):
return (image_width * z)
start=(conv(p1_x), image_width - conv(p1_y))
end=(conv(p2_x), image_width - conv(p2_y))
line=Line(start, end)
#line.extras["stroke"]=color
canvas.draw(line)
# キャンバスのクリア
def clear():
canvas.clear()
canvas.draw(rect)
# キャンバスへの反映
def update():
display(canvas)
| python |
#! /usr/bin/env python
################################################################################
# RelMon: a tool for automatic Release Comparison
# https://twiki.cern.ch/twiki/bin/view/CMSPublic/RelMon
#
#
#
# Danilo Piparo CERN - [email protected]
#
################################################################################
"""
Just a draft of the real program...It is very ugly still.
"""
from __future__ import print_function
from os.path import basename
from optparse import OptionParser
from re import search
from sys import exit
from urllib2 import Request,build_opener,urlopen
import os
if "RELMON_SA" in os.environ:
from authentication import X509CertOpen
from definitions import server
from utils import wget
else:
from Utilities.RelMon.authentication import X509CertOpen
from Utilities.RelMon.definitions import server
from Utilities.RelMon.utils import wget
def extract_list(page_html,the_server,display_url):
contents=[]
for line in page_html.split("<tr><td>")[1:]:
name=""
#link
link_start=line.find("href='")+6
link_end=line.find("'>")
#name
name_start=link_end+2
name_end=line.find("</a>")
if display_url:
contents.append(the_server+line[link_start:link_end])
else:
contents.append(line[name_start:name_end])
return contents
def get_page(url):
""" Get the web page listing the rootfiles. Use the X509 auth.
"""
opener=build_opener(X509CertOpen())
datareq = Request(url)
datareq.add_header('authenticated_wget', "The ultimate wgetter")
filename=basename(url)
return opener.open(datareq).read()
if __name__=="__main__":
parser = OptionParser(usage="usage: %prog [options] dirtolist")
parser.add_option("-d","--dev",
action="store_true",
dest="development",
default=False,
help="Select the development GUI instance.")
parser.add_option("--offline",
action="store_true",
dest="offline",
default=False,
help="Select the Offline GUI instance.")
parser.add_option("-o","--online",
action="store_true",
dest="online",
default=False,
help="Select the Online GUI instance.")
parser.add_option("-r","--relval",
action="store_true",
dest="relval",
default=True,
help="Select the RelVal GUI instance.")
parser.add_option("-u","--show_url",
action="store_true",
dest="show_url",
default=False,
help="Show the full URL of the file.")
parser.add_option("-g","--get",
action="store_true",
dest="get",
default=False,
help="Get the files.")
parser.add_option("-p","--path",
action="store",
dest="path",
default="",
help="The path to be matched before getting.")
(options, args) = parser.parse_args()
if not(options.development or options.offline or options.online or options.relval):
print("Select development or online instance!")
exit(-1)
lenargs=len(args)
if lenargs>1:
print("Please specify only one directory to list!")
exit(-1)
dirtolist=""
if lenargs==1:
dirtolist=args[0]
mode="relval"
if options.online:
mode="online"
if options.development:
mode="dev"
directory="%s/dqm/%s/data/browse/%s" %(server,mode,dirtolist)
print("peeping ",directory)
contents=extract_list(get_page(directory),server,options.show_url)
if len(contents)==0:
print("No contents found!")
for content in contents:
if not options.get and search(options.path,content):
print(content)
if options.get and options.show_url and len(options.path)>0 and search(options.path,content):
if not search('pre',options.path) and search('pre',content):
continue
bcontent=basename(content)
print("Getting %s" %bcontent)
wget(content)
print("Got %s!!" %bcontent)
| python |
# Copyright (c) 2013 Ian C. Good
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
"""Root package for |slimta| HTTP client and server libraries.
This package contains implementations of HTTP classes from :py:mod:`httplib`
using gevent sockets. These are provided to avoid the complete
re-implementation that ships in :mod:`gevent.httplib`, and to provide a more
similar interface to other slimta libraries that use SSL/TLS.
"""
from __future__ import absolute_import
from socket import error as socket_error
from gevent import socket
from slimta.util.pycompat import httplib, urlparse
__all__ = ['HTTPConnection', 'HTTPSConnection', 'get_connection']
class HTTPConnection(httplib.HTTPConnection):
"""Modified version of the :py:class:`httplib.HTTPConnection` class that
uses gevent sockets. This attempts to avoid the complete re-implementation
that ships in :mod:`gevent.httplib`.
"""
def __init__(self, host, port=None, *args, **kwargs):
httplib.HTTPConnection.__init__(self, host, port, *args, **kwargs)
self._create_connection = socket.create_connection
class HTTPSConnection(httplib.HTTPSConnection):
"""Modified version of the :py:class:`httplib.HTTPSConnection` class that
uses gevent sockets.
"""
def __init__(self, host, port=None, *args, **kwargs):
httplib.HTTPSConnection.__init__(self, host, port, *args, **kwargs)
self._create_connection = socket.create_connection
def close(self):
if self.sock:
try:
self.sock.unwrap()
except socket_error as e:
if e.errno != 0:
raise
httplib.HTTPSConnection.close(self)
def get_connection(url, context=None):
"""This convenience functions returns a :class:`HTTPConnection` or
:class:`HTTPSConnection` based on the information contained in URL.
:param url: URL string to create a connection for. Alternatively, passing
in the results of :py:func:`urlparse.urlsplit` works as well.
:param context: Used to wrap sockets with SSL encryption, when the URL
scheme is ``https``.
:type context: :py:class:`~ssl.SSLContext`
"""
if isinstance(url, (str, bytes)):
url = urlparse.urlsplit(url, 'http')
host = url.netloc or 'localhost'
if url.scheme == 'https':
conn = HTTPSConnection(host, context=context)
else:
conn = HTTPConnection(host)
return conn
# vim:et:fdm=marker:sts=4:sw=4:ts=4
| python |
# Copyright 2021 AIPlan4EU project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import upf
import itertools
import tarski.fstrips # type: ignore
from fractions import Fraction
from upf.exceptions import UPFProblemDefinitionError
from upf.environment import Environment
from collections import OrderedDict
from typing import Union, Dict
from tarski.syntax.formulas import Formula, is_and, is_or, is_neg, is_atom # type: ignore
from tarski.syntax.formulas import Tautology, Contradiction # type: ignore
from tarski.syntax.terms import Term, CompoundTerm, BuiltinPredicateSymbol # type: ignore
from tarski.syntax.terms import Constant, Variable, BuiltinFunctionSymbol # type: ignore
from tarski.fstrips.fstrips import AddEffect, DelEffect, FunctionalEffect # type: ignore
def convert_tarski_formula(env: Environment, fluents: Dict[str, 'upf.model.Fluent'],
objects: Dict[str, 'upf.model.Object'],
action_parameters: Dict[str, 'upf.model.ActionParameter'],
formula: Union[Formula, Term]) -> 'upf.model.FNode':
"""Converts a tarski formula in a upf expression."""
em = env.expression_manager
if is_and(formula):
children = [convert_tarski_formula(env, fluents, objects, action_parameters, f)
for f in formula.subformulas]
return em.And(*children)
elif is_or(formula):
children = [convert_tarski_formula(env, fluents, objects, action_parameters, f)
for f in formula.subformulas]
return em.Or(*children)
elif is_neg(formula):
assert len(formula.subformulas) == 1
return em.Not(convert_tarski_formula(env, fluents, objects, action_parameters,
formula.subformulas[0]))
elif is_atom(formula) or isinstance(formula, CompoundTerm):
children = [convert_tarski_formula(env, fluents, objects, action_parameters, f)
for f in formula.subterms]
if is_atom(formula):
symbol = formula.predicate.symbol
else:
symbol = formula.symbol.name
if symbol == BuiltinPredicateSymbol.EQ:
assert len(children) == 2
return em.Equals(children[0], children[1])
elif symbol == BuiltinPredicateSymbol.NE:
assert len(children) == 2
return em.Not(em.Equals(children[0], children[1]))
elif symbol == BuiltinPredicateSymbol.LT:
assert len(children) == 2
return em.LT(children[0], children[1])
elif symbol == BuiltinPredicateSymbol.LE:
assert len(children) == 2
return em.LE(children[0], children[1])
elif symbol == BuiltinPredicateSymbol.GT:
assert len(children) == 2
return em.GT(children[0], children[1])
elif symbol == BuiltinPredicateSymbol.GE:
assert len(children) == 2
return em.GE(children[0], children[1])
elif symbol == BuiltinFunctionSymbol.ADD:
assert len(children) == 2
return em.Plus(children[0], children[1])
elif symbol == BuiltinFunctionSymbol.SUB:
assert len(children) == 2
return em.Minus(children[0], children[1])
elif symbol == BuiltinFunctionSymbol.MUL:
assert len(children) == 2
return em.Times(children[0], children[1])
elif symbol == BuiltinFunctionSymbol.DIV:
assert len(children) == 2
return em.Div(children[0], children[1])
elif symbol in fluents:
return fluents[symbol](*children)
else:
raise UPFProblemDefinitionError(symbol + ' not supported!')
elif isinstance(formula, Constant):
if formula.sort.name == 'number':
return em.Real(Fraction(float(formula.name)))
elif formula.name in objects:
return em.ObjectExp(objects[formula.name])
else:
raise UPFProblemDefinitionError(symbol + ' not supported!')
elif isinstance(formula, Variable):
assert formula.symbol in action_parameters
return em.ParameterExp(action_parameters[formula.symbol])
elif isinstance(formula, Tautology):
return em.TRUE()
elif isinstance(formula, Contradiction):
return em.FALSE()
else:
raise UPFProblemDefinitionError(str(formula) + ' not supported!')
def convert_tarski_problem(env: Environment, tarski_problem: tarski.fstrips.Problem) -> 'upf.model.Problem':
"""Converts a tarski problem in a upf.Problem."""
em = env.expression_manager
tm = env.type_manager
lang = tarski_problem.language
problem = upf.model.Problem(tarski_problem.name)
# Convert types
types = {}
for t in lang.sorts:
types[str(t.name)] = tm.UserType(str(t.name))
# Convert predicates and functions
fluents = {}
for p in lang.predicates:
if str(p.name) in ['=', '!=', '<', '<=', '>', '>=']:
continue
signature = []
for t in p.sort:
signature.append(types[str(t.name)])
fluent = upf.model.Fluent(p.name, tm.BoolType(), signature)
fluents[fluent.name()] = fluent
problem.add_fluent(fluent)
for p in lang.functions:
if str(p.name) in ['ite', '@', '+', '-', '*', '/', '**', '%', 'sqrt']:
continue
signature = []
for t in p.domain:
signature.append(types[str(t.name)])
fluent = upf.model.Fluent(p.name, tm.RealType(), signature)
fluents[fluent.name()] = fluent
problem.add_fluent(fluent)
# Convert objects
objects = {}
for c in lang.constants():
o = upf.model.Object(str(c.name), types[str(c.sort.name)])
objects[o.name()] = o
problem.add_object(o)
# Convert actions
for a_name in tarski_problem.actions:
a = tarski_problem.get_action(a_name)
parameters = OrderedDict()
for p in a.parameters:
parameters[p.symbol] = types[p.sort.name]
action = upf.model.InstantaneousAction(a_name, parameters)
action_parameters = {}
for p in parameters.keys():
action_parameters[p] = action.parameter(p)
f = convert_tarski_formula(env, fluents, objects, action_parameters, a.precondition)
action.add_precondition(f)
for eff in a.effects:
if isinstance(eff, AddEffect):
f = convert_tarski_formula(env, fluents, objects, action_parameters, eff.atom)
action.add_effect(f, True)
elif isinstance(eff, DelEffect):
f = convert_tarski_formula(env, fluents, objects, action_parameters, eff.atom)
action.add_effect(f, False)
elif isinstance(eff, FunctionalEffect):
lhs = convert_tarski_formula(env, fluents, objects, action_parameters, eff.lhs)
rhs = convert_tarski_formula(env, fluents, objects, action_parameters, eff.rhs)
action.add_effect(lhs, rhs)
else:
raise UPFProblemDefinitionError(eff + ' not supported!')
problem.add_action(action)
# Set initial values
initial_values = {}
for fluent in fluents.values():
l = [problem.objects(t) for t in fluent.signature()]
if fluent.type().is_bool_type():
default_value = em.FALSE()
elif fluent.type().is_real_type():
default_value = em.Real(Fraction(0))
elif fluent.type().is_int_type():
default_value = em.Int(0)
if len(l) == 0:
initial_values[em.FluentExp(fluent)] = default_value
else:
for args in itertools.product(*l):
initial_values[fluent(*args)] = default_value
for i in tarski_problem.init.as_atoms():
if isinstance(i, tuple):
lhs = convert_tarski_formula(env, fluents, objects, {}, i[0])
rhs = convert_tarski_formula(env, fluents, objects, {}, i[1])
initial_values[lhs] = rhs
else:
f = convert_tarski_formula(env, fluents, objects, {}, i)
initial_values[f] = em.TRUE()
for lhs, rhs in initial_values.items():
problem.set_initial_value(lhs, rhs)
# Convert goals
problem.add_goal(convert_tarski_formula(env, fluents, objects, {}, tarski_problem.goal))
return problem
| python |
import wiringpi2 as wiringpi
import time
from time import sleep
import datetime
import sys
wiringpi.wiringPiSetup()
wiringpi.pullUpDnControl(16, 1) # Setup sensor input
wiringpi.pinMode(1, 3)
# Function for getting the current speed
def getSpeed():
currentTime = int(time.time())
currentTime = currentTime + 2
nextTime = -1
r = 0
while currentTime != nextTime:
if wiringpi.digitalRead(16):
off = False
while off == False:
if wiringpi.digitalRead(16) == False:
off = True
if off == True:
r = r + 1
nextTime = int(time.time())
r = r/4
distance = (r * (6.25 / 2)) / 63360 # (rotations * circumference) / inches in a mile
speed = distance * 3600
return speed
# Main part of the program
targetSpeed = float(sys.argv[1])
print(targetSpeed)
if (targetSpeed >= 2):
currentValue = int(12 * targetSpeed)
else:
currentValue = 20
while True:
action = False;
wiringpi.pwmWrite(1, currentValue)
currentSpeed = getSpeed()
print(currentSpeed)
if (currentSpeed < targetSpeed):
difference = targetSpeed - currentSpeed
if (difference > 3):
currentValue = currentValue + 10
elif (difference > 2):
currentValue = currentValue + 7
elif (difference > 1):
currentValue = currentValue + 2
else:
currentValue = currentValue + 1
elif (currentSpeed > targetSpeed):
difference = currentSpeed - targetSpeed
if (difference > 3):
currentValue = currentValue - 10
elif (difference > 2):
currentValue = currentValue - 7
elif (difference > 1):
currentValue = currentValue - 2
else:
currentValue = currentValue - 1 | python |
import time
import numpy
import matplotlib.pyplot as plt
from pyscf import gto, scf
import scipy
from scipy.optimize import minimize
import jax.numpy as jnp
from jax import grad, jit, random
from jax.config import config
config.update("jax_enable_x64", True)
import adscf
key = random.PRNGKey(0)
x = []
y = []
x_aug = []
y_aug = []
x_scf = []
y_scf = []
for i in range(5, 31):
R = 0.1 * i
print(f"interatomic distance: {R:.2f}")
mol = gto.Mole()
mol.charge = 0
mol.spin = 0
mol.build(atom = f'H 0.0 0.0 0.0; F 0.0 0.0 {R:.2f}',
basis ='STO-3G', unit='Angstrom')
calcEnergy, gradEnergy = adscf.calcEnergy_create(mol)
start = time.time()
# RHF energy calculation by PySCF
mf = scf.RHF(mol)
mf.scf()
elapsed_time = time.time() - start
print ("SCF: {:.3f} ms".format(elapsed_time * 1000))
e_scf = scf.hf.energy_tot(mf)
x_scf.append(R)
y_scf.append(e_scf)
# Curvilinear search using Cayley transformation
start = time.time()
# parameters
tau = 1.0
tau_m = 1e-10
tau_M = 1e10
rho = 1e-4
delta = 0.1
eta = 0.5
epsilon = 1e-6
max_iter = 5000
# 1. initialize X0
S = mol.intor_symmetric('int1e_ovlp') # overlap matrix
S64 = numpy.asarray(S, dtype=numpy.float64)
X_np = scipy.linalg.inv(scipy.linalg.sqrtm(S64))
X = jnp.asarray(X_np)
# 2. set C=f(X0) and Q0=1
C = calcEnergy(X)
Q = 1.0
# 3. calculate G0 and A0
G = gradEnergy(X)
A = G @ X.T @ S - S @ X @ G.T
# function to calculate Y(tau)
I = jnp.identity(len(S))
def Y_tau(tau, X, A):
return jnp.linalg.inv(I + 0.5 * tau * A @ S) @ (I - 0.5 * tau * A @ S) @ X
# main loop
for k in range(max_iter):
Y = Y_tau(tau, X, A)
A_norm = jnp.linalg.norm(A, "fro")
X_old, Q_old, G_old = X, Q, G
# 5
while calcEnergy(Y) > C - rho * tau * A_norm**2.0:
tau *= delta # 6
Y = Y_tau(tau, X, A)
# 8
X_new = Y
Q_new = eta * Q + 1.0
C = (eta * Q * C + calcEnergy(X_new)) / Q_new
# 9
G_new = gradEnergy(X_new)
A_new = G_new @ X_new.T @ S - S @ X_new @ G_new.T
# 10
Sk = X_new - X
Yk = G_new - G
if k % 2 == 0:
tau_k = jnp.trace(Sk.T @ Sk) / abs(jnp.trace(Sk.T @ Yk))
else:
tau_k = abs(jnp.trace(Sk.T @ Yk)) / jnp.trace(Yk.T @ Yk)
tau = max(min(tau_k, tau_M), tau_m)
# Update variables for next iteration
X, Q, G, A = X_new, Q_new, G_new, A_new
# Check loop condition (4)
cond = jnp.linalg.norm(A @ X)
if cond < epsilon:
break
elapsed_time = time.time() - start
print ("Curvilinear search: {:.3f} ms".format(elapsed_time*1000))
e = calcEnergy(X)+mol.energy_nuc()
print(f"total energy = {e}")
x.append(R)
y.append(e)
# augmented Lagrangian
@jit
def orthogonality(x):
C = jnp.reshape(x, [len(S), len(S)])
return jnp.linalg.norm(C.transpose()@S@C - jnp.identity(len(S)))
start = time.time()
x0 = random.uniform(key, (S.size,))
# 1
mu = 1.0
lam = 0.0
constraint = orthogonality(x0)
# 2
while constraint > 1e-6:
def target(x):
h = orthogonality(x)
return calcEnergy(x) + mu * h ** 2.0 + lam * h
# 3
res = minimize(jit(target), x0, jac=jit(grad(jit(target))), method="BFGS", options={'maxiter': 100})
x0 = res.x
constraint = orthogonality(x0)
# 4
lam += 2.0 * mu * constraint
# 5
mu *= 2.0
elapsed_time = time.time() - start
print ("Augmented: {:.3f} s".format(elapsed_time*1000))
energy = res.fun+mol.energy_nuc()
print(f"calculated energy = {energy}")
x_aug.append(R)
y_aug.append(energy)
p2 = plt.plot(x_scf, y_scf, marker="o")
p1 = plt.plot(x_aug, y_aug, marker="*")
p0 = plt.plot(x, y, marker="x")
plt.xlabel("interatomic distance (Å)", fontsize=16)
plt.ylabel("total energy (Eh)", fontsize=16)
plt.legend((p0[0], p1[0], p2[0]),
("Curvilinear search", "Augmented Lagrangian", "PySCF"),
loc='upper right')
plt.savefig("result.png", dpi=300)
| python |
# https://oj.leetcode.com/problems/word-ladder/
import heapq
class Solution:
# @param start, a string
# @param end, a string
# @param dict, a set of string
# @return an integer
def ladderLength(self, start, end, dict):
# BFS2
self.minLen = self.bfs2(start, end, dict)
# DFS
# self.minLen = 0
# self.createGraph(start, end, dict)
# self.dfs(end, start, [])
# BFS
# self.createGraph(start, end, dict)
# self.minLen = self.bfs(start, end)
# dijkstra
# self.createGraph(start, end, dict)
# self.minLen = self.dijkstra(start, end)
return self.minLen
def createGraph(self, start, end, dict):
words = list(dict) + [start, end]
self.graph = {}
for w1 in words:
self.graph[w1] = []
for w2 in words:
if w1 != w2 and self.hasOneDiff(w1, w2):
self.graph[w1].append(w2)
def hasOneDiff(self, w1, w2):
num = 0
for i in xrange(len(w1)):
if w1[i] != w2[i]:
num += 1
return num == 1
# Pass OJ!!
# Don't generate graph
def bfs2(self, start, end, dict):
letters = [chr(x) for x in xrange(ord('a'), ord('z')+1)]
dis, queue = {start: 1}, [start]
while len(queue) > 0:
top = queue.pop(0)
for i in xrange(len(top)):
for c in letters:
word = top[:i] + c + top[i+1:]
if word == top:
continue
if word == end:
return dis[top] + 1
if word in dict:
if word not in dis:
dis[word] = 0
if dis[word] == 0:
dis[word] = dis[top] + 1
queue.append(word)
return 0
# TLE
def dijkstra(self, start, end):
visited, heap = [], [(0, start)]
heapq.heapify(heap)
while len(heap) > 0:
top = heapq.heappop(heap)
adjacents = self.graph[top[1]]
if end in adjacents:
return top[0] + 1
for s in adjacents:
if s not in visited:
heapq.heappush(heap, (top[0] + 1, s))
visited.append(top[1])
return -1
# TLE
def bfs(self, start, end):
queue, visited = [(start, 0)], set()
while len(queue) > 0:
top = queue.pop(0)
children = self.graph[top[0]]
if end in children:
return top[1]+1
queue.extend([(x, top[1]+1) for x in children if x not in visited])
visited.add(top[0])
return -1
# TLE
def dfs(self, end, curr, path):
if self.minLen > 0 and len(path) >= self.minLen:
return
if curr in path:
return
path.append(curr)
children = self.graph[curr]
if end in children:
self.minLen = len(path) + 1
else:
for child in children:
self.dfs(end, child, path)
path.pop()
s = Solution()
print s.ladderLength("hit", "cog", ["hot","dot","dog","lot","log"])
print s.ladderLength("hot", "dog", ["hot","dog"])
| python |
#!/usr/bin/env python
import sys,socket,getopt,threading,subprocess
listen = False
command = False
upload = False
execute = ""
target = ""
upload_dest = ""
port = 0
def banner():
print "[***] NetCat p19 [***]"
print ""
def usage():
print " python NetCat.py -t target_host -p port "
print "-l --Listen on [host]:[port] for incoming connections "
print "-e --execute = file_to_run -execute a file "
print "-c --command -initialize a command shell "
print "-u --upload = destination -upload a file "
print "-t --target -p --port "
print "NetCat.py -t <target> -p 5555 -l -u=c:\\payload.exe "
print "echo 'ABCDEFGHI' | ./NetCat.py -t 192.168.11.12 -p 135 "
print "./NetCat.py -l -p <port> (listens on a port) "
print "./NetCat.py -t <target> -p 9001 -c (CTRL+D opens cmd shell) "
print "Press 'CTRL+D' to initalize shell after connecting "
def run_command(command): #trim the newline
command = command.rstrip() #run the command and get the output back
try:
output = subprocess.check_output(command,stderr=subprocess.STDOUT, shell = True)
except:
output = "Failed to execute command.\r\n"
return output #send output to the client
def client_handler(client_socket):
global upload
global execute
global command
if len(upload_dest): #check for upload
file_buffer = "" #read in all of the bytes and write to our destination
while True: #keep reading data until none is available
data = client_socket.recv(1024)
if not data:
break
else:
file_buffer += data #now we take these bytes and try to write them out
try:
file_descriptor = open(upload_dest,"wb")
file_descriptor.write(file_buffer)
file_descriptor.close()
client_socket.send("Woohoo! File saved to %s\r\n" % upload_dest)
except:
client_socket.send("You suck! Your file didn't copy to %s\r\n" % upload_dest)
if len(execute): #click for command execution
output = run_command(execute) #run the command
client_socket.send(output)
if command: #going into a loop if a command shell was requested
while True:
prompt = "<BHPNet:#> "
client_socket.send(prompt)
cmd_buffer = "" #now we receive until we ses a linefeed(enter key)
while "\n" not in cmd_buffer:
cmd_buffer += client_socket.recv(1024)
response = run_command(cmd_buffer) #send back the command output
client_socket.send(response) #send back the response
def server_loop():
global target
global port
if not len(target): #if no target is defined, we listen on all interfaces
target = "0.0.0.0"
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((target,port))
server.listen(5)
while True:
client_socket, addr = server.accept() #spin off a thread to handle our new client
client_thread = threading.Thread(target=client_handler, args=(client_socket,))
client_thread.start()
def client_sender(buffer):
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
client.connect((target, port)) #connect to our target host
if len(buffer):
client.send(buffer)
while True: #Wait for the data back
recv_len = 1
response = ""
while recv_len:
data = client.recv(4096)
recv_len = len(data)
response+= data
if recv_len < 4096:
break
print response,
buffer = raw_input("") #wait for more input
buffer += "\n"
client.send(buffer) #send it off
except:
print "[*] Exception! Exiting."
client.close() #tear down the connection
def main():
banner()
global listen
global port
global execute
global command
global upload_dest
global target
if not len(sys.argv[1:]):
usage()
try: #reads command line options
opts, args = getopt.getopt(sys.argv[1:], "hle:t:p:cu:",
["help","listen","execute","target","port","command","upload"])
except getopt.GetoptError as err:
print str(err)
usage()
for o,a in opts: #command options
if o in ("-h", "--help"):
usage()
elif o in ("-l", "--listen"):
listen = True
elif o in ("-e", "--execute"):
execute = a
elif o in ("-c", "--commandshell"):
command = True
elif o in ("-u", "--upload"):
upload_dest = a
elif o in ("-t", "--target"):
target = a
elif o in ("-p", "--port"):
port = int(a)
else:
assert False, "Unhandled Option"
if not listen and len(target) and port > 0: #listen or just send data from input
buffer = sys.stdin.read()
client_sender(buffer)
if listen:
server_loop()
if __name__ == "__main__":
main()
| python |
import json
import sys
# Enter the filename you want to process
file = sys.argv[1]
filename = f'{file}_changedFunctions.json'
print(f'Reading from filename {filename}')
with open(filename) as f:
init_database = json.load(f)
# Print total number of examples in dataset
print(f'Total number of functions (including all types of changes) = {len(init_database)}')
filtered_database = {}
count = 0
# Calculating the total number of examples with
# documentation changes
for i in init_database:
if init_database[i]["Doc"] == True and init_database[i]["Code"] == False:
count += 1
contents = i.split("_")
new_key = contents[0]
for con in range(2, len(contents)):
new_key += "_" + contents[con]
filtered_database[new_key] = init_database[i]
print(f'Total number of functions (with only documentation changes) = {count}')
D = {}
for i in filtered_database:
commit_id = i.split('_')[0]
if commit_id in D:
D[commit_id] += 1
else:
D[commit_id] = 1
print(f'Total number of commits to be processed = {len(D)}')
count1 = 0
for i in D:
count1 += D[i]
# Creating a JSON Dump in pretty format
init_database = json.dumps(init_database, sort_keys=True, indent=4)
filtered_database = json.dumps(filtered_database, sort_keys=True, indent=4)
# Writing Back to the JSON File
with open(filename, "w") as outfile:
outfile.write(init_database)
# Writing Back the filtered database
with open(f'{file}_changedFunctionsFiltered.json', "w") as outfile:
outfile.write(filtered_database)
| python |
import os
from io import BytesIO
import tarfile
from six.moves import urllib
import matplotlib
matplotlib.use('Agg')
from matplotlib import gridspec
from matplotlib import pyplot as plt
import numpy as np
from PIL import Image
import tensorflow as tf
flags = tf.app.flags
FLAGS = flags.FLAGS
# flags.DEFINE_string('modeldir', '/magic/segmentation/deeplab/datasets/SYS/models', 'The directory for models')
# flags.DEFINE_string('analyzedir', '/magic/segmentation/deeplab/datasets/SYS/models', 'The directory for analyze targets')
flags.DEFINE_string('target', '', 'Infer target filepath')
flags.DEFINE_string('modelpath', '', 'Tared model to use for infer')
flags.DEFINE_string('savedetailed', '', 'Detailed result save')
flags.DEFINE_string('save', '', 'Undetailed result save for next neural network')
class DeepLabModel(object):
"""Class to load deeplab model and run inference."""
INPUT_TENSOR_NAME = 'ImageTensor:0'
OUTPUT_TENSOR_NAME = 'SemanticPredictions:0'
INPUT_SIZE = 513
FROZEN_GRAPH_NAME = 'frozen_inference_graph'
def __init__(self, tarball_path):
"""Creates and loads pretrained deeplab model."""
self.graph = tf.Graph()
graph_def = None
# Extract frozen graph from tar archive.
tar_file = tarfile.open(tarball_path)
for tar_info in tar_file.getmembers():
if self.FROZEN_GRAPH_NAME in os.path.basename(tar_info.name):
file_handle = tar_file.extractfile(tar_info)
graph_def = tf.GraphDef.FromString(file_handle.read())
break
tar_file.close()
if graph_def is None:
raise RuntimeError('Cannot find inference graph in tar archive.')
with self.graph.as_default():
tf.import_graph_def(graph_def, name='')
self.sess = tf.Session(graph=self.graph)
def run(self, image):
"""Runs inference on a single image.
Args:
image: A PIL.Image object, raw input image.
Returns:
resized_image: RGB image resized from original input image.
seg_map: Segmentation map of `resized_image`.
"""
width, height = image.size
resize_ratio = 1.0 * self.INPUT_SIZE / max(width, height)
target_size = (int(resize_ratio * width), int(resize_ratio * height))
resized_image = image.convert('RGB').resize(target_size, Image.ANTIALIAS)
batch_seg_map = self.sess.run(
self.OUTPUT_TENSOR_NAME,
feed_dict={self.INPUT_TENSOR_NAME: [np.asarray(resized_image)]})
seg_map = batch_seg_map[0]
return resized_image, seg_map
# def create_pascal_label_colormap():
# """Creates a label colormap used in PASCAL VOC segmentation benchmark.
# Returns:
# A Colormap for visualizing segmentation results.
# """
# colormap = np.zeros((256, 3), dtype=int)
# ind = np.arange(256, dtype=int)
# for shift in reversed(range(8)):
# for channel in range(3):
# colormap[:, channel] |= ((ind >> channel) & 1) << shift
# ind >>= 3
# return colormap
def labelToColorImage(label):
"""Adds color defined by the dataset colormap to the label.
Args:
label: A 2D array with integer type, storing the segmentation label.
Returns:
result: A 2D array with floating type. The element of the array
is the color indexed by the corresponding element in the input label
to the PASCAL color map.
Raises:
ValueError: If label is not of rank 2 or its value is larger than color
map maximum entry.
"""
if label.ndim != 2:
raise ValueError('Expect 2-D input label')
colormap = np.asarray([
[0,0,0],
[255,0,0],
[255,0,218],
[114,0,255],
[0,5,255]
])
if np.max(label) >= len(colormap):
raise ValueError('label value too large.')
return colormap[label]
def visSegmentationDetailed(image, seg_map):
"""Visualizes input image, segmentation map and overlay view."""
plt.figure(figsize=(15, 5))
grid_spec = gridspec.GridSpec(1, 4, width_ratios=[6, 6, 6, 1])
plt.subplot(grid_spec[0])
plt.imshow(image)
plt.axis('off')
plt.title('input image')
plt.subplot(grid_spec[1])
seg_image = labelToColorImage(seg_map).astype(np.uint8)
plt.imshow(seg_image)
plt.axis('off')
plt.title('segmentation map')
plt.subplot(grid_spec[2])
plt.imshow(image)
plt.imshow(seg_image, alpha=0.7)
plt.axis('off')
plt.title('segmentation overlay')
unique_labels = np.unique(seg_map)
ax = plt.subplot(grid_spec[3])
plt.imshow(
FULL_COLOR_MAP[unique_labels].astype(np.uint8), interpolation='nearest')
ax.yaxis.tick_right()
plt.yticks(range(len(unique_labels)), LABEL_NAMES[unique_labels])
plt.xticks([], [])
ax.tick_params(width=0.0)
plt.grid('off')
plt.savefig(FLAGS.savedetailed, bbox_inches='tight')
def visSegmentation(seg_map):
fig = plt.figure()
# fig.patch.set_visible(False)
ax = fig.add_axes([0, 0, 1, 1])
ax.axis('off')
seg_image = labelToColorImage(seg_map).astype(np.uint8)
ax.imshow(seg_image)
with open(FLAGS.save, 'w') as outfile:
fig.canvas.print_png(outfile)
LABEL_NAMES = np.asarray([
'background', 'menu', 'sidebar', 'content', 'footer'
])
FULL_LABEL_MAP = np.arange(len(LABEL_NAMES)).reshape(len(LABEL_NAMES), 1)
FULL_COLOR_MAP = labelToColorImage(FULL_LABEL_MAP)
# model_path = os.path.join(FLAGS.modeldir, FLAGS.modelpath)
model_path = FLAGS.modelpath
MODEL = DeepLabModel(model_path)
print('model loaded successfully!')
def runVisualization(target_path):
"""Inferences DeepLab model and visualizes result."""
try:
original_im = Image.open(target_path)
except Exception:
print('image not found')
return
print('running deeplab on image %s...' % target_path)
resized_im, seg_map = MODEL.run(original_im)
# print(resized_im)
# print(seg_map
visSegmentation(seg_map)
visSegmentationDetailed(resized_im, seg_map)
# image_path = os.path.join(FLAGS.analyzedir, FLAGS.target)
image_path = FLAGS.target
print(image_path)
runVisualization(image_path)
| python |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
nodeenv
~~~~~~~
Node.js virtual environment
:copyright: (c) 2011 by Eugene Kalinin
:license: BSD, see LICENSE for more details.
"""
nodeenv_version = '0.3.5'
import sys
import os
import time
import logging
import optparse
import subprocess
import ConfigParser
join = os.path.join
abspath = os.path.abspath
# ---------------------------------------------------------
# Utils
def create_logger():
"""
Create logger for diagnostic
"""
# create logger
logger = logging.getLogger("nodeenv")
logger.setLevel(logging.INFO)
# monkey patch
def emit(self, record):
msg = self.format(record)
fs = "%s" if getattr(record, "continued", False) else "%s\n"
self.stream.write(fs % msg)
self.flush()
logging.StreamHandler.emit = emit
# create console handler and set level to debug
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
# create formatter
formatter = logging.Formatter(fmt="%(message)s")
# add formatter to ch
ch.setFormatter(formatter)
# add ch to logger
logger.addHandler(ch)
return logger
logger = create_logger()
def parse_args():
"""
Parses command line arguments
"""
parser = optparse.OptionParser(
version=nodeenv_version,
usage="%prog [OPTIONS] ENV_DIR")
parser.add_option('-n', '--node', dest='node',
metavar='NODE_VER', default=get_last_stable_node_version(),
help='The node.js version to use, e.g., '
'--node=0.4.3 will use the node-v0.4.3 '
'to create the new environment. The default is last stable version.')
parser.add_option('-j', '--jobs', dest='jobs', default=2,
help='Sets number of parallel commands at node.js compilation. '
'The default is 2 jobs.')
parser.add_option('-v', '--verbose',
action='store_true', dest='verbose', default=False,
help="Verbose mode")
parser.add_option('-q', '--quiet',
action='store_true', dest='quiet', default=False,
help="Quete mode")
parser.add_option('-r', '--requirement',
dest='requirements', default='', metavar='FILENAME',
help='Install all the packages listed in the given requirements file. '
'Not compatible with --without-npm option.')
parser.add_option('--prompt', dest='prompt',
help='Provides an alternative prompt prefix for this environment')
parser.add_option('-l', '--list', dest='list',
action='store_true', default=False,
help='Lists available node.js versions')
parser.add_option( '--without-ssl', dest='without_ssl',
action='store_true', default=False,
help='Build node.js without SSL support')
parser.add_option( '--debug', dest='debug',
action='store_true', default=False,
help='Build debug variant of the node.js')
parser.add_option( '--profile', dest='profile',
action='store_true', default=False,
help='Enable profiling for node.js')
parser.add_option( '--without-npm', dest='without_npm',
action='store_true', default=False,
help='Install npm in new virtual environment')
parser.add_option('--npm', dest='npm',
metavar='NODE_VER', default='latest',
help='The npm version to use, e.g., '
'--npm=0.3.18 will use the npm-0.3.18.tgz '
'tarball to install. The default is last available version.')
parser.add_option( '--no-npm-clean', dest='no_npm_clean',
action='store_true', default=False,
help='Skip the npm 0.x cleanup. Do cleanup by default.')
options, args = parser.parse_args()
if not options.list:
if not args:
print('You must provide a DEST_DIR')
parser.print_help()
sys.exit(2)
if len(args) > 1:
print('There must be only one argument: DEST_DIR (you gave %s)' % (
' '.join(args)))
parser.print_help()
sys.exit(2)
if options.requirements and options.without_npm:
print('These options are not compatible: --requirements, --without-npm')
parser.print_help()
sys.exit(2)
return options, args
def mkdir(path):
"""
Create directory
"""
if not os.path.exists(path):
logger.debug(' * Creating: %s ... ', path, extra=dict(continued=True))
os.makedirs(path)
logger.debug('done.')
else:
logger.debug(' * Directory %s already exists', path)
def writefile(dest, content, overwrite=True):
"""
Create file and write content in it
"""
if not os.path.exists(dest):
logger.debug(' * Writing %s ... ', dest, extra=dict(continued=True))
f = open(dest, 'wb')
f.write(content.encode('utf-8'))
f.close()
logger.debug('done.')
return
else:
f = open(dest, 'rb')
c = f.read()
f.close()
if c != content:
if not overwrite:
logger.notify(' * File %s exists with different content; not overwriting', dest)
return
logger.notify(' * Overwriting %s with new content', dest)
f = open(dest, 'wb')
f.write(content.encode('utf-8'))
f.close()
else:
logger.debug(' * Content %s already in place', dest)
def callit(cmd, show_stdout=True, in_shell=False,
cwd=None, extra_env=None):
"""
Execute cmd line in sub-shell
"""
all_output = []
cmd_parts = []
for part in cmd:
if len(part) > 45:
part = part[:20]+"..."+part[-20:]
if ' ' in part or '\n' in part or '"' in part or "'" in part:
part = '"%s"' % part.replace('"', '\\"')
cmd_parts.append(part)
cmd_desc = ' '.join(cmd_parts)
logger.debug(" ** Running command %s" % cmd_desc)
if in_shell:
cmd = ' '.join(cmd)
# output
if show_stdout:
stdout = None
else:
stdout = subprocess.PIPE
# env
if extra_env:
env = os.environ.copy()
if extra_env:
env.update(extra_env)
else:
env = None
# execute
try:
proc = subprocess.Popen(
cmd, stderr=subprocess.STDOUT, stdin=None, stdout=stdout,
cwd=cwd, env=env, shell=in_shell)
except Exception:
e = sys.exc_info()[1]
logger.fatal("Error %s while executing command %s" % (e, cmd_desc))
raise
if show_stdout:
stdout = proc.stdout
while stdout:
line = stdout.readline()
if not line:
break
line = line.rstrip()
logger.info(line)
else:
proc.communicate()
proc.wait()
# error handler
if proc.returncode:
raise OSError("Command %s failed with error code %s"
% (cmd_desc, proc.returncode))
return proc.returncode, all_output
# ---------------------------------------------------------
# Virtual environment functions
def install_node(env_dir, src_dir, opt):
"""
Download source code for node.js, unpack it
and install it in virtual environment.
"""
logger.info(' * Install node.js (%s) ' % opt.node,
extra=dict(continued=True))
node_name = 'node-v%s'%(opt.node)
tar_name = '%s.tar.gz'%(node_name)
node_url = 'http://nodejs.org/dist/%s'%(tar_name)
node_tar = join(src_dir, tar_name)
node_src_dir = join(src_dir, node_name)
env_dir = abspath(env_dir)
old_chdir = os.getcwd()
cmd = []
cmd.append('curl')
cmd.append('--silent')
cmd.append('-L')
cmd.append(node_url)
cmd.append('|')
cmd.append('tar')
cmd.append('xzf')
cmd.append('-')
cmd.append('-C')
cmd.append(src_dir)
callit(cmd, opt.verbose, True, env_dir)
logger.info('.', extra=dict(continued=True))
env = {'JOBS': str(opt.jobs) }
conf_cmd = []
conf_cmd.append('./configure')
conf_cmd.append('--prefix=%s'%(env_dir))
if opt.without_ssl:
conf_cmd.append('--without-ssl')
if opt.debug:
conf_cmd.append('--debug')
if opt.profile:
conf_cmd.append('--profile')
callit(conf_cmd , opt.verbose, True, node_src_dir, env)
logger.info('.', extra=dict(continued=True))
callit(['make'] , opt.verbose, True, node_src_dir, env)
logger.info('.', extra=dict(continued=True))
callit(['make install'] , opt.verbose, True, node_src_dir, env)
logger.info(' done.')
def install_npm(env_dir, src_dir, opt):
"""
Download source code for npm, unpack it
and install it in virtual environment.
"""
logger.info(' * Install npm.js (%s) ... ' % opt.npm,
extra=dict(continued=True))
cmd = ['. %s && curl %s | clean=%s npm_install=%s bash && deactivate'%(
join(env_dir, 'bin', 'activate'),
'http://npmjs.org/install.sh',
'no' if opt.no_npm_clean else 'yes',
opt.npm)]
callit(cmd, opt.verbose, True)
logger.info('done.')
def install_packages(env_dir, opt):
"""
Install node.js packages via npm
"""
logger.info(' * Install node.js packages ... ',
extra=dict(continued=True))
packages = [ package.replace('\n', '') for package in
open(opt.requirements).readlines() ]
activate_path = join(env_dir, 'bin', 'activate')
for package in packages:
callit(cmd=['. '+ activate_path +
' && ' + 'npm install ' + package +
' && ' + 'npm activate ' + package],
show_stdout=opt.verbose, in_shell=True)
logger.info('done.')
def install_activate(env_dir, opt):
"""
Install virtual environment activation script
"""
files = {'activate': ACTIVATE_SH}
bin_dir = join(env_dir, 'bin')
prompt = opt.prompt or '(%s)' % os.path.basename(os.path.abspath(env_dir))
if opt.npm == 'latest' or opt.npm[0] == '1':
freeze_cmd = "npm ls -g | grep -o -e '\w*@[[:digit:]]\.[[:digit:]]\.[[:digit:]]' "
else:
freeze_cmd = "npm list installed active | cut -d ' ' -f 1"
for name, content in files.items():
file_path = join(bin_dir, name)
content = content.replace('__VIRTUAL_PROMPT__', prompt)
content = content.replace('__VIRTUAL_ENV__', os.path.abspath(env_dir))
content = content.replace('__BIN_NAME__', os.path.basename(bin_dir))
content = content.replace('__FREEZE_CMD__', freeze_cmd)
writefile(file_path, content)
os.chmod(file_path, 0755)
def create_environment(env_dir, opt):
"""
Creates a new environment in ``env_dir``.
"""
if os.path.exists(env_dir):
logger.info(' * Environment is allready exists: %s', env_dir)
sys.exit(2)
src_dir = abspath(join(env_dir, 'src'))
mkdir(src_dir)
save_env_options(env_dir, opt)
install_node(env_dir, src_dir, opt)
# activate script install must be
# before npm install, npm use activate
# for install
install_activate(env_dir, opt)
if not opt.without_npm:
install_npm(env_dir, src_dir, opt)
if opt.requirements:
install_packages(env_dir, opt)
def print_node_versions():
"""
Prints into stdout all available node.js versions
"""
p = subprocess.Popen(
"curl -s http://nodejs.org/dist/ | "
"egrep -o '[0-9]+\.[0-9]+\.[0-9]+' | "
"sort -u -k 1,1n -k 2,2n -k 3,3n -t . ",
shell=True, stdout=subprocess.PIPE)
#out, err = p.communicate()
pos = 0
rowx = []
while 1:
row = p.stdout.readline()
pos += 1
if not row:
logger.info('\t'.join(rowx))
break
if pos%8 == 0:
logger.info('\t'.join(rowx))
rowx =[]
else:
rowx.append(row.replace('\n', ''))
def get_last_stable_node_version():
"""
Return last stable node.js version
"""
p = subprocess.Popen(
"curl -s http://nodejs.org/dist/ | "
"egrep -o '[0-9]+\.[2468]+\.[0-9]+' | "
"sort -u -k 1,1n -k 2,2n -k 3,3n -t . | "
"tail -n1",
shell=True, stdout=subprocess.PIPE)
return p.stdout.readline().replace("\n", "")
def save_env_options(env_dir, opt, file_path='install.cfg'):
"""
Save command line options into config file
"""
section_name = 'options'
config = ConfigParser.RawConfigParser()
config.add_section(section_name)
for o, v in opt.__dict__.items():
config.set(section_name, o, v)
with open(join(env_dir, file_path), 'wb') as configfile:
config.write(configfile)
def main():
"""
Entry point
"""
opt, args = parse_args()
if opt.list:
print_node_versions()
else:
env_dir = args[0]
if opt.quiet:
logger.setLevel(logging.CRITICAL)
create_environment(env_dir, opt)
# ---------------------------------------------------------
# Shell scripts content
ACTIVATE_SH = """
# This file must be used with "source bin/activate" *from bash*
# you cannot run it directly
deactivate () {
# reset old environment variables
if [ -n "$_OLD_VIRTUAL_PATH" ] ; then
PATH="$_OLD_VIRTUAL_PATH"
export PATH
unset _OLD_VIRTUAL_PATH
fi
# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "$BASH" -o -n "$ZSH_VERSION" ] ; then
hash -r
fi
if [ -n "$_OLD_VIRTUAL_PS1" ] ; then
PS1="$_OLD_VIRTUAL_PS1"
export PS1
unset _OLD_VIRTUAL_PS1
fi
unset VIRTUAL_ENV
if [ ! "$1" = "nondestructive" ] ; then
# Self destruct!
unset -f deactivate
fi
}
freeze () {
if [ -z "$@" ]; then
__FREEZE_CMD__
else
__FREEZE_CMD__ > $@
fi
}
# unset irrelavent variables
deactivate nondestructive
VIRTUAL_ENV="__VIRTUAL_ENV__"
export VIRTUAL_ENV
_OLD_VIRTUAL_PATH="$PATH"
PATH="$VIRTUAL_ENV/__BIN_NAME__:$PATH"
export PATH
if [ -z "$VIRTUAL_ENV_DISABLE_PROMPT" ] ; then
_OLD_VIRTUAL_PS1="$PS1"
if [ "x__VIRTUAL_PROMPT__" != x ] ; then
PS1="__VIRTUAL_PROMPT__$PS1"
else
if [ "`basename \"$VIRTUAL_ENV\"`" = "__" ] ; then
# special case for Aspen magic directories
# see http://www.zetadev.com/software/aspen/
PS1="[`basename \`dirname \"$VIRTUAL_ENV\"\``] $PS1"
else
PS1="(`basename \"$VIRTUAL_ENV\"`)$PS1"
fi
fi
export PS1
fi
# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "$BASH" -o -n "$ZSH_VERSION" ] ; then
hash -r
fi
"""
if __name__ == '__main__':
main()
| python |
#
# Copyright (c) 2017, Massachusetts Institute of Technology All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
from MDSplus import mdsExceptions, Device
class RFXWAVESETUP(Device):
"""Generic Wavefor configuration mdsplus device"""
parts=[{'path':':COMMENT','type':'text'}]
for i in range(1,7):
parts.append({'path':'.WAVE_%d'%(i),'type':'structure'})
parts.append({'path':'.WAVE_%d:COMMENT'%(i),'type':'text'})
parts.append({'path':'.WAVE_%d:WAVE'%(i),'type':'signal', 'options':'compress_on_put'})
parts.append({'path':'.WAVE_%d:MIN_X'%(i),'type':'numeric', 'value':0})
parts.append({'path':'.WAVE_%d:MAX_X'%(i),'type':'numeric', 'value':1})
parts.append({'path':'.WAVE_%d:MIN_Y'%(i),'type':'numeric', 'value':0})
parts.append({'path':'.WAVE_%d:MAX_Y'%(i),'type':'numeric', 'value':10})
| python |
#!/usr/bin/env python
from setuptools import setup, find_packages
try:
README = open('README.rst').read()
except:
README = None
try:
REQUIREMENTS = open('requirements.txt').read()
except:
REQUIREMENTS = None
setup(
name='spotify2piratebay',
version="0.1",
description='Download your Spotify music using the Pirate Bay',
long_description=README,
install_requires=REQUIREMENTS,
author='Mathijs de Bruin',
author_email='[email protected]',
url='http://github.com/dokterbob/spotify2piratebay/',
packages=find_packages(),
include_package_data=True,
classifiers=[
'Development Status :: 3 - Alpha',
'Environment :: Console',
'Intended Audience :: Developers',
'License :: Public Domain',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Topic :: Utilities'
],
entry_points={
'console_scripts': [
'spotify2piratebay = spotify2piratebay.runner:main',
],
},
)
| python |
from django.urls import include, path
from django.contrib import admin
from config import views
urlpatterns = [
path('admin/', admin.site.urls),
path('health/', views.health),
path('', include('engine.urls', namespace="engine")),
]
| python |
import transmogrifier.models as timdex
from transmogrifier.helpers import generate_citation, parse_xml_records
def test_generate_citation_with_required_fields_only():
extracted_data = {
"title": "A Very Important Paper",
"source_link": "https://example.com/paper",
}
assert (
generate_citation(extracted_data)
== "A Very Important Paper. https://example.com/paper"
)
def test_generate_citation_includes_only_expected_contributors():
extracted_data = {
"title": "A Very Important Paper",
"source_link": "https://example.com/paper",
"contributors": [
timdex.Contributor(value="Contributor with no kind"),
timdex.Contributor(
value="Contributor with excluded kind", kind="Illustrator"
),
timdex.Contributor(value="Contributor One", kind="Author"),
timdex.Contributor(value="Contributor Two", kind="Creator"),
],
}
assert (
generate_citation(extracted_data)
== "Contributor One, Contributor Two. A Very Important Paper. "
"https://example.com/paper"
)
def test_generate_citation_includes_only_publication_date():
extracted_data = {
"title": "A Very Important Paper",
"source_link": "https://example.com/paper",
"dates": [
timdex.Date(value="Date with no kind"),
timdex.Date(value="Not a publication date", kind="Collection date"),
timdex.Date(value="2022-01-01", kind="Publication date"),
],
}
assert (
generate_citation(extracted_data)
== "A Very Important Paper. 2022-01-01. https://example.com/paper"
)
def test_generate_citation_handles_publication_date_with_no_value():
extracted_data = {
"title": "A Very Important Paper",
"source_link": "https://example.com/paper",
"dates": [timdex.Date(kind="Publication date")],
}
assert (
generate_citation(extracted_data)
== "A Very Important Paper. https://example.com/paper"
)
def test_generate_citation_with_creator_and_publication_date():
extracted_data = {
"title": "A Very Important Paper",
"source_link": "https://example.com/paper",
"contributors": [timdex.Contributor(kind="author", value="Smith, Susie Q.")],
"dates": [timdex.Date(kind="Publication date", value="2022")],
}
assert (
generate_citation(extracted_data)
== "Smith, Susie Q. (2022): A Very Important Paper. https://example.com/paper"
)
def test_generate_citation_with_creator_no_publication_date():
extracted_data = {
"title": "A Very Important Paper",
"source_link": "https://example.com/paper",
"contributors": [timdex.Contributor(kind="author", value="Smith, Susie Q.")],
}
assert (
generate_citation(extracted_data)
== "Smith, Susie Q. A Very Important Paper. https://example.com/paper"
)
def test_generate_citation_with_publication_date_no_creator():
extracted_data = {
"title": "A Very Important Paper",
"source_link": "https://example.com/paper",
"dates": [timdex.Date(kind="Publication date", value="2022")],
}
assert (
generate_citation(extracted_data)
== "A Very Important Paper. 2022. https://example.com/paper"
)
def test_generate_citation_with_no_publisher():
extracted_data = {
"title": "A Very Important Paper",
"source_link": "https://example.com/paper",
"content_type": ["Article"],
"contributors": [timdex.Contributor(kind="author", value="Smith, Susie Q.")],
"dates": [timdex.Date(kind="Publication date", value="2022")],
}
assert (
generate_citation(extracted_data)
== "Smith, Susie Q. (2022): A Very Important Paper. Article. "
"https://example.com/paper"
)
def test_generate_citation_includes_only_first_publisher():
extracted_data = {
"title": "A Very Important Paper",
"source_link": "https://example.com/paper",
"contributors": [timdex.Contributor(kind="author", value="Smith, Susie Q.")],
"dates": [timdex.Date(kind="Publication date", value="2022")],
"publication_information": [
"Massachusetts Institute of Technology",
"Additional publication information",
],
}
assert (
generate_citation(extracted_data)
== "Smith, Susie Q. (2022): A Very Important Paper. Massachusetts Institute of "
"Technology. https://example.com/paper"
)
def test_generate_citation_with_no_resource_type():
extracted_data = {
"title": "A Very Important Paper",
"source_link": "https://example.com/paper",
"contributors": [timdex.Contributor(kind="author", value="Smith, Susie Q.")],
"dates": [timdex.Date(kind="Publication date", value="2022")],
"publication_information": ["Massachusetts Institute of Technology"],
}
assert (
generate_citation(extracted_data)
== "Smith, Susie Q. (2022): A Very Important Paper. Massachusetts Institute of "
"Technology. https://example.com/paper"
)
def test_generate_citation_includes_all_resource_types():
extracted_data = {
"title": "A Very Important Paper",
"source_link": "https://example.com/paper",
"content_type": ["Article", "Paper"],
"contributors": [timdex.Contributor(kind="author", value="Smith, Susie Q.")],
"dates": [timdex.Date(kind="Publication date", value="2022")],
"publication_information": ["Massachusetts Institute of Technology"],
}
assert (
generate_citation(extracted_data)
== "Smith, Susie Q. (2022): A Very Important Paper. Massachusetts Institute of "
"Technology. Article, Paper. https://example.com/paper"
)
def test_generate_citation_with_all_fields():
extracted_data = {
"title": "A Very Important Paper",
"source_link": "https://example.com/paper",
"content_type": ["Article"],
"contributors": [
timdex.Contributor(kind="author", value="Smith, Susie Q."),
timdex.Contributor(kind="creator", value="Jones, John J."),
],
"dates": [timdex.Date(kind="Publication date", value="2022")],
"publication_information": ["Massachusetts Institute of Technology"],
}
assert (
generate_citation(extracted_data)
== "Smith, Susie Q., Jones, John J. (2022): A Very Important Paper. "
"Massachusetts Institute of Technology. Article. https://example.com/paper"
)
def test_parse_xml_records_returns_record_iterator():
records = parse_xml_records("tests/fixtures/datacite/datacite_records.xml")
assert len(list(records)) == 38
| python |
def findRanges(nums):
sol = []
if len(nums) == 0 or len(nums) == 1:
return nums
# temp = nums
# [temp.append(x) for x in nums if x not in temp]
i,j = 0,1
prev, cur = nums[i],nums[j]
while j < len(nums):
if prev+1 == cur or prev == cur:
prev = cur
else:
sol.append([nums[i],prev])
i = j
prev = cur
j += 1
if j < len(nums):
cur = nums[j]
sol.append([nums[i],prev])
return sol
print(findRanges([0, 1, 2, 5, 7, 8, 9, 9, 10, 11, 15]))
# ['0->2', '5->5', '7->11', '15->15'] | python |
import torch
def select_optimizer(model, config):
optimizer = None
if config["optimizer"] == "SGD":
optimizer = torch.optim.SGD(model.parameters(), lr=config["learning_rate"])
elif config["optimizer"] == "Adam":
optimizer = torch.optim.Adam(model.parameters(), lr=config["learning_rate"])
elif config["optimizer"] == "Adadelta":
optimizer = torch.optim.Adadelta(model.parameters(), lr=config["learning_rate"])
elif config["optimizer"] == "Adagrad":
optimizer = torch.optim.Adagrad(model.parameters(), lr=config["learning_rate"])
elif config["optimizer"] == "Adamax":
optimizer = torch.optim.Adamax(model.parameters(), lr=config["learning_rate"])
elif config["optimizer"] == "AdamW":
optimizer = torch.optim.AdamW(model.parameters(), lr=config["learning_rate"])
elif config["optimizer"] == "LBFGS":
optimizer = torch.optim.LBFGS(model.parameters(), lr=config["learning_rate"])
elif config["optimizer"] == "SparseAdam":
optimizer = torch.optim.SparseAdam(
model.parameters(), lr=config["learning_rate"]
)
elif config["optimizer"] == "RMSProp":
optimizer = torch.optim.RMSProp(model.parameters(), lr=config["learning_rate"])
else:
raise NameError("The string used to identify the optimizer is NOT recognized")
return optimizer
| python |
#!/usr/bin/env python
import numpy as np
import math
import random
import time
# This was created to separate make_data and the model and the solver
rnd = np.random
#rnd.seed(0)
#This version is changed according the JMetal
def make_data(U1,V1,K1,N1,Psi_u1,Psi_u2,Phi_u1,Phi_u2,B_u1,B_u2,r_u1,tau_v1,tau_v2,sigma_v1,sigma_v2,b_v1,b_v2,L_v1,R_v1):
#Slice1N( U1, V1, K1, N1, dmaxv1, dminv1, Bmaxu1!, Bminu1!, bmaxuv1, bminuv1, UpSpi1, UpPhi1, upSpimax1, upSpimin1, upPhimax1, upPhimin1, uptaumax1, uptaumin1, upsigmamax1, upsigmamin1, Lv1, ru1, ru2,ru3,rv1,rv2,rv3, q1,I1)));
mec = U1 #U number of MECs
U,V,E,Psi_u,Phi_u,B_u,r_u,tau_v,sigma_v,b_v,L_v,R_v= {},{},{},{},{},{},{},{},{},{},{},{},{},{}
#xmec = rnd.rand(mec)*100
#ymec = rnd.rand(mec)*100
dp = V1 #V number of demand points
U = [u for u in range(mec)] # the set of MECs
V = [v for v in range(dp)] # the set of demand points
C_u =[]
#xdp = rnd.rand(dp)*100
#ydp = rnd.rand(dp)*100
K = K1 #number of redundancy
N = N1 #N Number of demand points sharing a backup slice
#PMEC = {u: (xmec[u],ymec[u]) for u in range(U1) }
#PDP = {v: (xdp[v],ydp[v]) for v in range(V1)}
# Psi_u MEC CPU capacity in MIPS
Psi_u = [rnd.randint(Psi_u1, Psi_u2) for u in range(U1)]
# Phi_u MEC RAM capacity in GB 6 GB -> 48000 Megabit
Phi_u = [rnd.randint(Phi_u1, Phi_u2) for u in range(U1)]
#MIPSfactor = PCI / CP / 3600
#CP: the number of processors: 25 for a 2964-725.
#PCI: Processor Capacity Index.
#B_u MEC total bandwidth capacity in Mbps
B_u = [rnd.randint(B_u1, B_u2) for u in range(U1)]
#b_v Bandwidth consumed by the demand point v in Mbps
#b_v = [ random.randint(b_v1, b_v2) for v in range(V1)]
#C = {(i,j):np.hypot(xc[i]-xc[j],yc[i]-yc[j])for i,j in E} # Euclidean Distance
#b_v = {(i,j):random.randint(b_v1, b_v2) for i,j in E}
#L_v Bound on the latency requirement of the demand point v in ms
L_v = [ L_v1 for v in range(V1)]
R_v = [ R_v1 for v in range(V1)]
#r_u Failure probability of the MEC u \in U
r_u = [r_u1 for u in range(U1)]
#tau_v Processing demand of the demand point v in MIPS
tau_v = [rnd.randint(tau_v1, tau_v2) for v in range(V1)]
#sigma_v Memory demand of the demand point v in GB = x8000 MBit
sigma_v = [rnd.randint(sigma_v1, sigma_v2) for v in range(V1)]
#C_u Maximum possible number of slices in the MEC u
C_u1 = {u: (Psi_u[u])/min(tau_v[v] for v in range(V1) ) for u in range(U1) }
C_u2 = {u: (Phi_u[u])/min(sigma_v[v] for v in range(V1) ) for u in range(U1) }
C_u = [int(math.ceil(min(C_u1[u],C_u2[u]))) for u in range(U1)]
#C_ui = {(u,i) for u in range(U1) for i in range (C_u[u]) }
#C_uik = {(u,i,k) for u in range(U1) for i in range (C_u[u]) for k in range(K) }
E = {(u,v,i,k) for u in U for v in V for i in range(C_u[u])for k in range(K)} # The set of edges
b = {}
for v in V:
b[v] = rnd.randint(b_v1, b_v2)
b_v = {(u,v,i,k):b[v] for u,v,i,k in E}
#Cu= #number of slcies=Vms
#U1,V1,K1,N1,Psi_u1,Phi_u1,B_u1,r_u1,tau_v1,tau_v2,sigma_v1,sigma_v2,b_v1,b_v2,L_v1,R_v1
#return xmec,ymec,xdp,ydp,U,V,K,N,E,C_u,Psi_u,Phi_u,B_u,r_u,tau_v,sigma_v,b_v,L_v,R_v,C_ui,C_uik,PMEC,PDP
return U,V,K,N,E,C_u,Psi_u,Phi_u,B_u,r_u,tau_v,sigma_v,b_v,L_v,R_v | python |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created in September 2020
@author: karliskanders
Functions and classes for generating and analysing career transition recommendations
"""
import pandas as pd
import numpy as np
import pickle
from time import time
import yaml
import os
from ast import literal_eval
from sklearn.preprocessing import normalize
from scipy.spatial.distance import cdist, cosine
from scipy.stats import wilcoxon
from collections import defaultdict
import mapping_career_causeways
import mapping_career_causeways.compare_nodes_utils as compare_nodes_utils
import mapping_career_causeways.load_data_utils as load_data
from mapping_career_causeways.scripts import pickle_large_files
find_closest = compare_nodes_utils.find_closest
useful_paths = mapping_career_causeways.Paths()
data = load_data.Data()
sim = load_data.Similarities()
# Import default skills description embeddings
embeddings = np.load(f'{useful_paths.data_dir}interim/embeddings/embeddings_skills_description_SBERT.npy')
### SET UP DEFAULT TRANSITION FILTERING CRITERIA ###
with open(f'{useful_paths.codebase_dir}configs/default_transition_params.yaml', 'r') as f:
def_transition_params = yaml.load(f, Loader=yaml.FullLoader)
# Viability: Similarity threshold for viable transitions (default = 0.3)
MIN_VIABLE_DEF = def_transition_params['MIN_VIABLE']
# Viability: Similarity threshold for highly viable transitions (default = 0.4)
HIGHLY_VIABLE_DEF = def_transition_params['HIGHLY_VIABLE']
# Viability: Max absolute difference in job zones (default = 1)
MAX_JOB_ZONE_DIF_DEF = def_transition_params['MAX_JOB_ZONE_DIF']
# Desirability: Threshold for differences in earnings (default = 0.75)
MIN_EARNINGS_RATIO_DEF = def_transition_params['MIN_EARNINGS_RATIO']
def occupations_to_check(id_to_check):
"""
Helper function for selecting a list of occupations
Parameters
----------
id_to_check (list of int, or str or None):
List of integers corresponding to occupation IDs, or a string for a shorthand
reference to a predefined set of occupations.
"""
if (type(id_to_check)==type(None)) or (id_to_check=='report'):
id_to_check = data.report_occ_ids
elif id_to_check == 'top':
id_to_check = data.top_occ_ids
elif id_to_check == 'all':
id_to_check = data.occ.id.to_list()
return id_to_check
def find_most_similar(
occ = None,
similarity_measure='combined',
n=15,
destination_ids='report',
transpose=False):
"""
Helper function for finding the most similar occupations that a worker in
the specified occupation could transition to.
Parameters
----------
occ (int or str):
Either the occupation ID (int) or preferred label (str)
similarity_measure (str):
One of the following: 'combined', 'essential_skills', 'optional_skills',
'work_activities', 'work_context'
n (int):
Number of the top-most similar occupations to return
destination_ids (list of int, or str):
List of admissible destination occupations, specified by a list occupation IDs or
a string for a shorthand reference to a predefined set of occupations
transpose (boolean):
If True, it will transpose the similarity matrix and the results will
show the most similar occupations that could transition into the specified occupation
(NB: The skills and combined similarity matrices are asymmetric)
Returns
-------
df (pandas.DataFrame):
A dataframe with the following fields: 'id', 'preferred_label' and 'similarity'
"""
occ_id = data.occ_title_to_id(occ)
destination_ids = occupations_to_check(destination_ids)
sim_matrix = sim.select_similarity_matrix(similarity_measure)
if transpose:
sim_matrix = sim_matrix.T
df = find_closest(occ_id, sim_matrix, data.occ[['id', 'preferred_label']])
df = df[df.id.isin(destination_ids)].iloc[0:n]
return df
def get_transitions(
origin_ids = None,
MIN_VIABLE = MIN_VIABLE_DEF,
HIGHLY_VIABLE = HIGHLY_VIABLE_DEF,
MAX_JOB_ZONE_DIF = MAX_JOB_ZONE_DIF_DEF,
MIN_EARNINGS_RATIO = MIN_EARNINGS_RATIO_DEF,
destination_ids = None,
verbose=False, less_information=False):
"""
Function to find viable, desirable and safe transitions according to the specified filters;
NB: This function outputs only transitions whose occupation similarity is above MIN_VIABLE threshold
Parameters
----------
origin_ids (list of int):
List of origin occupation IDs, for which to check the transitions. If None,
we only check the subset of occupations analysed in the report
MIN_VIABLE (float):
Similarity threshold for viable transitions (default = 0.3)
HIGHLY_VIABLE (float):
Similarity threshold for highly viable transitions (default = 0.4)
MAX_JOB_ZONE_DIF (int):
Max absolute difference in job zones (default = 1)
MIN_EARNINGS_RATIO (float):
Threshold for differences in earnings (default = 0.75)
destination_ids (list of int):
List of permissible destination occupation IDs. If None, we check only
the occupations subset analysed in the report
Returns
-------
trans_df (pandas.DataFrame):
A pandas dataframe with transitions and various descriptors and indicators.
See https://github.com/nestauk/mapping-career-causeways/tree/main/supplementary_online_data/transitions/transitions_tables/
for descriptions for each of the columns.
"""
columns = initialise_transition_table_columns()
origin_ids = occupations_to_check(origin_ids)
destination_ids = occupations_to_check(destination_ids)
# For each occupation in consideration...
if verbose: print('Finding all transitions...', end=' ')
t_now = time()
for j, j_id in enumerate(origin_ids):
# Find the most similar occupations
df = find_closest(j_id, sim.W_combined, data.occ[['id']])
# Filter out self
df = df[df.id!=j_id]
# Filter out occupations that we're not supposed to check
df = df[df.id.isin(destination_ids)]
# Filter out non-viable transitions
df = df[df.similarity > MIN_VIABLE]
# Viable IDs
viable_ids = df.id.to_list()
# Collect data about each transition from j_id to viable_ids
columns = transition_data_processing(
columns, j_id, viable_ids,
MIN_VIABLE,
HIGHLY_VIABLE,
MAX_JOB_ZONE_DIF,
MIN_EARNINGS_RATIO)
if verbose: print(f'Done!\nThis took {(time()-t_now):.2f} seconds.')
trans_df = pd.DataFrame(data=columns)
# Add filtering variables
trans_df = transition_data_filtering(trans_df, MIN_VIABLE, HIGHLY_VIABLE)
if less_information:
return trans_df[[
'origin_id',
'origin_label',
'destination_id',
'destination_label',
'similarity',
'is_viable',
'is_desirable',
'is_safe_desirable',
'is_strictly_safe_desirable'
]].reset_index(drop=True)
else:
return trans_df.reset_index(drop=True)
def initialise_transition_table_columns():
columns = {
'origin_id': [],
'origin_label': [],
'destination_id': [],
'destination_label': [],
'similarity': [],
'is_jobzone_ok': [],
'is_earnings_ok': [],
'is_not_high_risk': [],
'is_safer': [],
'is_strictly_safe': [],
'job_zone_dif': [],
'earnings_ratio': [],
'risk_dif': [],
'prop_dif': [],
'W_skills': [],
'W_work': [],
'W_essential_skills': [],
'W_optional_skills': [],
'W_activities': [],
'W_work_context': []
}
return columns
def transition_data_processing(
columns, j_id, viable_ids,
MIN_VIABLE = MIN_VIABLE_DEF,
HIGHLY_VIABLE = HIGHLY_VIABLE_DEF,
MAX_JOB_ZONE_DIF = MAX_JOB_ZONE_DIF_DEF,
MIN_EARNINGS_RATIO = MIN_EARNINGS_RATIO_DEF):
"""
Used by get_transitions() and get_transition_data();
Adds various descriptors for the transitions from j_id (int)
to a set of viable_ids (list of int) that will be further used
to filter viable, desirable and safe transitions.
"""
N = len(viable_ids)
origin_job_zone = data.occ.loc[j_id].job_zone
origin_earnings = data.occ.loc[j_id].annual_earnings
origin_risk = data.occ.loc[j_id].risk
origin_prevalence = data.occ.loc[j_id].prevalence
origin_label = data.occ.loc[j_id].risk_category
job_zone_dif = origin_job_zone - data.occ.loc[viable_ids].job_zone
earnings_ratio = data.occ.loc[viable_ids].annual_earnings / origin_earnings
risk_dif = origin_risk - data.occ.loc[viable_ids].risk
prevalence_dif = data.occ.loc[viable_ids].prevalence - origin_prevalence
# Job Zone difference not larger than MAX_JOB_ZONE_DIF
is_jobzone_ok = np.abs(job_zone_dif) <= MAX_JOB_ZONE_DIF
# Earnings at destination larger than MIN_EARNINGS_RATIO
is_earnings_ok = earnings_ratio > MIN_EARNINGS_RATIO
# Destination is not a high risk occupation
is_not_high_risk = (data.occ.loc[viable_ids].risk_category != 'High risk')
# Destination has a smaller risk and a larger prevalence of bottleneck tasks
is_safer = (risk_dif > 0) & (prevalence_dif > 0)
# Combine both safety filters
is_strictly_safe = is_safer & is_not_high_risk
# Summarise similarities
W_skills = 0.5*sim.W_essential[j_id, viable_ids] + 0.5*sim.W_all_to_essential[j_id, viable_ids]
W_work = 0.5*sim.W_activities[j_id, viable_ids] + 0.5*sim.W_work_context[j_id, viable_ids]
# Save the row data
columns['origin_id'] += [j_id] * N
columns['origin_label'] += [data.occ.loc[j_id].preferred_label] * N
columns['destination_id'] += viable_ids
columns['destination_label'] += data.occ.loc[viable_ids].preferred_label.to_list()
columns['similarity'] += list(sim.W_combined[j_id, viable_ids])
columns['is_jobzone_ok'] += list(is_jobzone_ok)
columns['is_earnings_ok'] += list(is_earnings_ok)
columns['is_not_high_risk'] += list(is_not_high_risk)
columns['is_safer'] += list(is_safer)
columns['is_strictly_safe'] += list(is_strictly_safe)
columns['job_zone_dif'] += list(job_zone_dif)
columns['earnings_ratio'] += list(earnings_ratio)
columns['risk_dif'] += list(risk_dif)
columns['prop_dif'] += list(prevalence_dif)
columns['W_skills'] += list(W_skills)
columns['W_work'] += list(W_work)
columns['W_essential_skills'] += list(sim.W_essential[j_id, viable_ids])
columns['W_optional_skills'] += list(sim.W_all_to_essential[j_id, viable_ids])
columns['W_activities'] += list(sim.W_activities[j_id, viable_ids])
columns['W_work_context'] += list(sim.W_work_context[j_id, viable_ids])
return columns
def transition_data_filtering(trans_df, MIN_VIABLE, HIGHLY_VIABLE):
"""
Adds filtering variables to the transitions dataframe trans_df (pandas.DataFrame)
to indicate transitions that are viable, desirable and safe.
"""
trans_df['sim_category'] = ''
trans_df.loc[trans_df.similarity <= HIGHLY_VIABLE, 'sim_category'] = 'min_viable'
trans_df.loc[trans_df.similarity > HIGHLY_VIABLE, 'sim_category'] = 'highly_viable'
trans_df.loc[trans_df.similarity <= MIN_VIABLE, 'sim_category'] = 'not_viable'
trans_df['is_viable'] = trans_df['is_jobzone_ok'] & (trans_df['sim_category'] != 'not_viable')
trans_df['is_desirable'] = trans_df['is_viable'] & trans_df['is_earnings_ok']
trans_df['is_safe_desirable'] = trans_df['is_desirable'] & trans_df['is_not_high_risk']
trans_df['is_strictly_safe_desirable'] = trans_df['is_desirable'] & trans_df['is_strictly_safe']
return trans_df
def get_transition_data(
transition_pairs,
MIN_VIABLE = MIN_VIABLE_DEF,
HIGHLY_VIABLE = HIGHLY_VIABLE_DEF,
MAX_JOB_ZONE_DIF = MAX_JOB_ZONE_DIF_DEF,
MIN_EARNINGS_RATIO = MIN_EARNINGS_RATIO_DEF,
verbose=False):
"""
Compiles transition data for each transition pair; final output table follows the same
format as the output of get_transitions()
Parameters
----------
transition_pairs (list of tuples):
Pairs of transitions for which to generate a table with various descriptors
and viability, desirability and safety indicators.
...
Returns
-------
trans_df (pandas.DataFrame):
A pandas dataframe with transitions and various descriptors and indicators.
See https://github.com/nestauk/mapping-career-causeways/tree/main/supplementary_online_data/transitions/transitions_tables/
for descriptions for each of the columns.
"""
columns = initialise_transition_table_columns()
if verbose: print('Finding data for all transitions...', end=' ')
t_now = time()
transition_pair_dict = defaultdict(list)
for pair in transition_pairs:
transition_pair_dict[pair[0]].append(pair[1])
# For each transition pair in consideration...
for j_id in list(transition_pair_dict.keys()):
viable_ids = transition_pair_dict[j_id]
columns = transition_data_processing(
columns, j_id, viable_ids,
MIN_VIABLE,
HIGHLY_VIABLE,
MAX_JOB_ZONE_DIF,
MIN_EARNINGS_RATIO)
if verbose: print(f'Done!\nThis took {(time()-t_now):.2f} seconds.')
trans_df = pd.DataFrame(data=columns)
trans_df = transition_data_filtering(trans_df, MIN_VIABLE, HIGHLY_VIABLE)
return trans_df.reset_index(drop=True)
def create_filtering_matrices(
origin_ids = None,
MIN_VIABLE = MIN_VIABLE_DEF,
HIGHLY_VIABLE = HIGHLY_VIABLE_DEF,
MAX_JOB_ZONE_DIF = MAX_JOB_ZONE_DIF_DEF,
MIN_EARNINGS_RATIO = MIN_EARNINGS_RATIO_DEF,
destination_ids = None,
export_path = None):
"""
Creates boolean matrices for tagging transitions as 'safe', 'desirable', 'viable'
'highly viable' and combinations of these.
These boolean matrices are later used for analysing the number of different
types of transitions for each occupation.
Parameters
----------
origin_ids (list of int):
List of origin occupation IDs, for which to check the transitions. If None,
we only check the subset of occupations analysed in the report
MIN_VIABLE (float):
Similarity threshold for viable transitions (default = 0.3)
HIGHLY_VIABLE (float):
Similarity threshold for highly viable transitions (default = 0.4)
MAX_JOB_ZONE_DIF (int):
Max absolute difference in job zones (default = 1)
MIN_EARNINGS_RATIO (float):
Threshold for differences in earnings (default = 0.75)
destination_ids (list of int):
List of permissible destination occupation IDs. If None, we check only
the occupations subset analysed in the report
"""
# Select the occupations to check
origin_ids = occupations_to_check(origin_ids)
destination_ids = occupations_to_check(destination_ids)
# Select the similarities corresponding to the specified occupations
W_combined_select = sim.W_combined[origin_ids, :].copy()
W_combined_select = W_combined_select[:, destination_ids]
# Filter matrices
N = len(origin_ids)
N2 = len(destination_ids)
# Boolean natrices to indicate...
# ...compatibility of job zones
F_jobzone = np.zeros((N,N2)).astype(bool)
# ...compatability of earnings
F_earnings = np.zeros((N,N2)).astype(bool)
# ...reduction of risk and increase of the prevalence of bottleneck tasks
F_safer = np.zeros((N,N2)).astype(bool)
# ...that destination is not of high risk
F_not_high_risk = np.zeros((N,N2)).astype(bool)
# ...that the transition is not to self
F_not_self = np.zeros((N,N2)).astype(bool)
print('Creating filtering matrices...', end=' ')
t_now = time()
# Brute force approach (for each transition...)
for i in range(N):
row_i = data.occ.iloc[origin_ids[i]]
for j in range(N2):
row_j = data.occ.iloc[destination_ids[j]]
is_jobzone_ok = np.abs(row_i.job_zone - row_j.job_zone) <= MAX_JOB_ZONE_DIF
is_earnings_ok = (row_j.annual_earnings / row_i.annual_earnings) > MIN_EARNINGS_RATIO
is_safer = (row_i.risk > row_j.risk) & (row_i.prevalence < row_j.prevalence)
is_not_high_risk = (row_j.risk_category != 'High risk')
F_jobzone[i][j] = is_jobzone_ok
F_earnings[i][j] = is_earnings_ok
F_not_high_risk[i][j] = is_not_high_risk
F_safer[i][j] = is_safer
F_not_self[i][j] = row_i.id != row_j.id
print(f'Done!\nThis took {(time()-t_now):.2f} seconds.')
# Matrices indicating viable and highly viable transitions
F_viable = F_jobzone & (W_combined_select > MIN_VIABLE)
F_highly_viable = F_jobzone & (W_combined_select > HIGHLY_VIABLE)
F_min_viable = F_jobzone & (W_combined_select > MIN_VIABLE) & (W_combined_select <= HIGHLY_VIABLE)
# Matrix indicating desirable transitions
F_desirable = F_viable & F_earnings
# Matrix indicating safe transitions
F_strictly_safe = F_safer & F_not_high_risk
# Matrices indicating safe and desirable transitions
F_safe_desirable = F_desirable & F_not_high_risk # 1st definition
F_strictly_safe_desirable = F_desirable & F_strictly_safe # 2nd (stricter) definition
# Export filtering matrices
filter_matrices = {
'F_viable': F_viable,
'F_min_viable': F_min_viable,
'F_highly_viable': F_highly_viable,
'F_desirable': F_desirable,
'F_jobzone': F_jobzone,
'F_earnings': F_earnings,
'F_not_high_risk': F_not_high_risk,
'F_safer': F_safer,
'F_strictly_safe': F_strictly_safe,
'F_not_self': F_not_self,
'F_safe_desirable': F_safe_desirable,
'F_strictly_safe_desirable': F_strictly_safe_desirable,
}
# Remove transitions to self
for key in list(filter_matrices.keys()):
filter_matrices[key] = filter_matrices[key] & F_not_self
filter_matrices['origin_ids'] = origin_ids
filter_matrices['destination_ids'] = destination_ids
# Export filtering matrices
if export_path is not None:
if os.path.exists(export_path) == False:
pickle.dump(filter_matrices, open(export_path, 'wb'))
print(f'Filtering matrices saved at {export_path}')
else:
print('File already exists! (not saved)')
return filter_matrices
def show_skills_overlap(
job_i,
job_j,
data=data, sim=sim,
embeddings=embeddings,
skills_match = 'optional', # either 'optional' or 'essential'
matching_method='one_to_one',
verbose=True,
rounding=True):
"""
NLP-adjusted overlap of skill sets between occupations job_i and job_j
"""
job_i = data.occ_title_to_id(job_i)
job_j = data.occ_title_to_id(job_j)
if verbose: print(f"from {data.occ.loc[job_i].preferred_label} (id {job_i}) to {data.occ.loc[job_j].preferred_label} (id {job_j})")
# Create the input dataframe in the required format
if skills_match == 'optional':
node_to_items_ = pd.concat([data.node_to_all_items.loc[[job_i]],
data.node_to_essential_items.loc[[job_j]]])
w = sim.W_all_to_essential[job_i, job_j]
elif skills_match == 'essential':
node_to_items_ = pd.concat([data.node_to_essential_items.loc[[job_i]],
data.node_to_essential_items.loc[[job_j]]])
w = sim.W_essential[job_i, job_j]
# Check for empty arrays
assert((data.node_to_essential_items.loc[[job_j]].items_list.values[0]) != 0)
# Compare occupations
df, score = compare_nodes_utils.two_node_comparison(
node_to_items_, job_i, job_j,
data.skills[['id','preferred_label']],
embeddings,
metric='cosine',
matching_method=matching_method,
symmetric=False,
rounding=rounding)
N_matched = len(df)
# Tidy up the dataframe
df.rename(columns={
'id_x': 'origin_skill_id',
'preferred_label_x': 'origin_skill',
'id_y': 'destination_skill_id',
'preferred_label_y': 'destination_skill',
'similarity': 'score',
'similarity_raw': 'similarity'}, inplace=True)
df = df[['origin_skill_id', 'origin_skill',
'destination_skill_id', 'destination_skill',
'similarity', 'score']]
# Add leftover skills from the destination occupation
all_destination_skills = data.occupation_to_skills[
(data.occupation_to_skills.occupation_id==job_j) &
(data.occupation_to_skills.importance=='Essential')].skill_id.to_list()
skills_to_add = set(all_destination_skills).difference(set(df.destination_skill_id))
if len(skills_to_add) != 0:
append_df = {
'origin_skill_id':[],
'origin_skill':[],
'destination_skill_id':[],
'destination_skill':[],
'similarity':[],
'score':[]
}
for s in skills_to_add:
append_df['origin_skill_id'].append('-')
append_df['origin_skill'].append('-')
append_df['destination_skill_id'].append(s)
append_df['destination_skill'].append(data.skills.loc[s].preferred_label)
append_df['similarity'].append(0)
append_df['score'].append(0)
df = df.append(pd.DataFrame(data=append_df), ignore_index=True)
if verbose:
print('--------')
#print(f'{N_matched}/{len(data.node_to_essential_items.loc[[job_j]].items_list.values[0])} destination skills matched')
print(f'NLP-adjusted overlap = {w:.2f} (total combined similarity: {sim.W_combined[job_i, job_j]:.2f})')
return df
class CompareFeatures():
"""
Class to inspect feature vector differences between occupations
"""
def __init__(self, data_folder=useful_paths.data_dir):
### Import work context vectors ###
self.work_context_vectors = np.load(data_folder + 'interim/work_context_features/ESCO_work_context_vectors.npy')
self.work_context_features = pd.read_csv(data_folder + 'processed/work_context_vector_features.csv')
self.work_context_features['category'] = self.work_context_features.element_id.apply(lambda x: int(x[4]))
# Add work context feature category label
def categorise(x):
if x == 1: return 'interpersonal'
if x == 2: return 'physical'
if x == 3: return 'structural'
self.work_context_features['category'] = self.work_context_features['category'].apply(lambda x: categorise(x))
### Import ESCO skills category vectors ###
self.esco_vectors_1 = np.load(data_folder + 'interim/work_activity_features/esco_hierarchy_vectors_level_1.npy')
self.esco_features_1 = pickle.load(open(data_folder + 'interim/work_activity_features/esco_hierarchy_codes_level_1.pickle', 'rb'))
self.esco_features_1 = data.concepts[data.concepts.code.isin(self.esco_features_1)][['code','title']].sort_values('code').copy()
self.esco_vectors_2 = np.load(data_folder + 'interim/work_activity_features/esco_hierarchy_vectors_level_2.npy')
self.esco_features_2 = pickle.load(open(data_folder + 'interim/work_activity_features/esco_hierarchy_codes_level_2.pickle', 'rb'))
self.esco_features_2 = data.concepts[data.concepts.code.isin(self.esco_features_2)][['code','title']].sort_values('code').copy()
self.esco_vectors_3 = np.load(data_folder + 'interim/work_activity_features/esco_hierarchy_vectors_level_3.npy')
self.esco_features_3 = pickle.load(open(data_folder + 'interim/work_activity_features/esco_hierarchy_codes_level_3.pickle', 'rb'))
self.esco_features_3 = data.concepts[data.concepts.code.isin(self.esco_features_3)][['code','title']].sort_values('code').copy()
def select_esco_level(self, level=2):
""" Selects the level of ESCO hierarchy; if level=None, uses work context features instead """
if level==1:
self.vectors = self.esco_vectors_1
self.features = self.esco_features_1
elif level==2:
self.vectors = self.esco_vectors_2
self.features = self.esco_features_2
elif level==3:
self.vectors = self.esco_vectors_3
self.features = self.esco_features_3
elif level is None:
self.vectors = self.work_context_vectors
self.features = self.work_context_features
def get_feature_differences(self, origin_id, destination_id, esco_level=2):
"""
Useful for checking what are the biggest differences between the two occupations
Parameters
----------
origin_id (int):
Origin occupation's integer ID
destination_id (int):
Destination occupation's integer ID
esco_level (int or boolean):
ESCO hierarchy level (normally use level 2); if esco_level is None, uses work context vectors
"""
self.select_esco_level(esco_level)
# Calculate vector deltas and add category labels
delta_vector = self.vectors[destination_id] - self.vectors[origin_id]
df = self.features.copy()
df['origin'] = self.vectors[origin_id]
df['destination'] = self.vectors[destination_id]
df['dif'] = delta_vector
df['dif_abs'] = np.abs(delta_vector)
return df.sort_values('dif_abs', ascending=False)
def most_impactful_features(self, origin_id, destination_id, esco_level=2):
"""
Useful for checking what makes both occupations similar; calculates 'impact'
which relates to how much an element contributes to similarity
Parameters
----------
origin_id (int):
Origin occupation's integer ID
destination_id (int):
Destination occupation's integer ID
esco_level (int or boolean):
ESCO hierarchy level (normally use level 2); if esco_level is None, uses work context vectors
"""
self.select_esco_level(esco_level)
original_destination_vector = self.vectors[destination_id,:]
origin_vector = normalize(self.vectors[origin_id,:].reshape(1,-1))
original_sim = cosine(normalize(original_destination_vector.reshape(1,-1)), origin_vector)
impacts = []
for j in range(len(original_destination_vector)):
new_vector = original_destination_vector.copy()
new_vector[j] = 0
new_vector = normalize(new_vector.reshape(1,-1))
impact = original_sim - cosine(new_vector, origin_vector)
impacts.append(-impact)
df = self.features.copy()
df['impact'] = impacts
return df.sort_values('impact', ascending=False)
class SkillsGaps():
"""
Class for characterising prevalent skills gaps for a collection of transitions
"""
def __init__(self, trans_to_analyse, verbose=True):
"""
trans_to_analyse (pandas.DataFrame):
Table with transitions, with columns 'origin_id' and 'destination_id'
indicating the occupations involved in the transition.
"""
self.trans_to_analyse = trans_to_analyse
self.get_skills_scores(verbose=verbose)
self.skill_similarities_all = None
self._skills_gaps = None
self.cluster_gaps = None
@property
def skills_gaps(self):
if self._skills_gaps is None:
self._skills_gaps = self.get_skills_gaps()
return self._skills_gaps
def get_skills_scores(self, verbose=True):
"""
Compare skillsets using NLP-adjusted overlap across all transitions
in self.trans_to_analyse, and save the matching scores for each skill from each comparison
"""
## List of lists (a list for each transition)
# Skills IDs for all transitions
self.destination_skills_id_ALL = []
self.origin_skills_id_ALL = []
# All matching scores
self.destination_skills_id_score_ALL = []
self.origin_skills_id_score_ALL = []
# All semantic similarity values (not used in the final analysis)
self.destination_skills_id_sim_ALL = []
self.origin_skills_id_sim_ALL = []
t = time()
for j, row in self.trans_to_analyse.iterrows():
# Get job IDs
job_i = row.origin_id
job_j = row.destination_id
# Create the input dataframe in the required format
df = show_skills_overlap(job_i, job_j, verbose=False)
###### DESTINATION SKILLS ######
# Save the skill IDs and similarity values
self.destination_skills_id_ALL.append(df.destination_skill_id.to_list())
self.destination_skills_id_score_ALL.append(df.score.to_list())
self.destination_skills_id_sim_ALL.append(df.similarity.to_list())
###### ORIGIN SKILLS ######
# Exclude unmatched destination skill rows
origin_skills = df[df.origin_skill_id.apply(lambda x: type(x)!=str)]
# Extract the origin skill IDs, matching scores and similarity values
self.origin_skills_id_ALL.append(origin_skills.origin_skill_id.to_list())
self.origin_skills_id_score_ALL.append(origin_skills.score.to_list())
self.origin_skills_id_sim_ALL.append(origin_skills.similarity.to_list())
t_elapsed = time() - t
if verbose: print(f'Time elapsed: {t_elapsed :.2f} sec ({t_elapsed/len(self.trans_to_analyse): .3f} per transition)')
def setup(self, transition_indices=None, skills_type='destination', skill_items=None):
"""
Parameters:
----------
transition_indices (list of int)
Transitions that we wish to analyse (will correspond to the row indices of 'trans_to_analyse')
skills_type (str):
Sets up which skills are we checking ('destination' vs 'origin'; normally use 'destination')
skills_items (str):
Optionally can specify whether to only analyse gaps for specific ESCO skills pillar categories:
skills ('S'), knowledge ('K') or attitudes ('A')
"""
# Store the analysis parameters
if type(transition_indices)==type(None):
self.transition_indices = range(0, len(self.trans_to_analyse))
else:
self.transition_indices = transition_indices
self.skills_type = skills_type
# Number of transitions we have
self.n_trans = len(self.transition_indices)
# Get all skills occurrences and matching scores
self.skill_similarities_all = self.merge_lists()
# Select only specific skill items (either 'K' for knowledge, 'S' for skills or 'A' for attitude)
if skill_items is None:
pass
else:
df = self.skill_similarities_all.merge(data.skills[['id','skill_category']], left_on='skills_id', right_on='id', how='left')
self.skill_similarities_all = self.skill_similarities_all[df.skill_category.isin(skill_items)]
self._skills_gaps = self.get_skills_gaps()
def prevalent_skills_gaps(self, top_x=10, percentile=False):
"""
Show the most prevalent skills gaps
top_x (int):
Determines if the analysis outputs the top-most top_x prevalent skills
(if percentile is False) or the top percentile of most prevalent skills
(if percentile is True). Normally, use top_x=90 or 95 if percentile=True
percentile (boolean):
Determines how top_x is interpreted
"""
# Return the top most prevalent skills
return self.get_most_prevalent_gaps(self.skills_gaps, top_x=top_x, percentile=percentile)
def prevalent_cluster_gaps(self, level='level_3', top_x=10, percentile=False):
"""
Show the most prevalent skills gaps, aggregated at the level of ESCO skills categories
Parameters
----------
level (str or int):
Determines which level (1, 2 or 3) of ESCO skills hierarchy we are using to
aggregate the skills gaps
top_x (int):
Determines if the function outputs the top-most top_x prevalent skills
(if percentile is False) or the top percentile of most prevalent skills
(if percentile is True). Normally, use top_x=90 or 95 if percentile=True
percentile (boolean):
Determines how top_x is interpreted
"""
if level in [1,2,3]:
level = 'level_' + str(level)
self.cluster_gaps = self.get_cluster_gaps(level)
prevalent_clusters = self.get_most_prevalent_gaps(self.cluster_gaps, top_x=top_x, percentile=percentile)
return self.most_prevalent_cluster_skills(prevalent_clusters)
def merge_lists(self):
"""
Creates dataframe with all skills occurrences, their matched similarities and scores.
It is possible to analyse a subset of all supplied transitions, by specifying
the row indices of 'trans_to_analyse' table using 'transition_indices'
"""
# Merge lists
list_skills = []
list_score = []
list_similarity = []
for i in self.transition_indices:
if self.skills_type=='destination':
list_skills += self.destination_skills_id_ALL[i]
list_score += self.destination_skills_id_score_ALL[i]
list_similarity += self.destination_skills_id_sim_ALL[i]
elif self.skills_type=='origin':
list_skills += self.origin_skills_id_ALL[i]
list_score += self.origin_skills_id_score_ALL[i]
list_similarity += self.origin_skills_id_sim_ALL[i]
skill_similarities_all = pd.DataFrame(data={
'skills_id': list_skills,
'score': list_score,
'similarity': list_similarity})
# If a skill was not matched, then set it to 0
skill_similarities_all.loc[skill_similarities_all.score.isnull(), 'score'] = 0
return skill_similarities_all
def count_and_agg_scores(self, skill_similarities_all, groupby_column):
""" Aggregates scores for each skill or cluster (depending on groupby_column) """
# Counts
skill_counts = skill_similarities_all.groupby(groupby_column).count()
# Mean similarity
skill_similarities = skill_similarities_all.groupby(groupby_column).mean()
# Create the dataframe
skill_similarities['counts'] = skill_counts['score']
skill_similarities['stdev'] = skill_similarities_all.groupby(groupby_column).std()['score']
skill_similarities.reset_index(inplace=True)
return skill_similarities
def get_skills_gaps(self):
""" Agregates scores for skills """
# Aggregate scores
skill_similarities = self.count_and_agg_scores(self.skill_similarities_all, 'skills_id')
skill_similarities['prevalence'] = skill_similarities['counts'] / self.n_trans
# Add information about skills
skill_similarities = skill_similarities.merge(
data.skills[['id', 'preferred_label', 'level_1', 'level_2', 'level_3']],
left_on='skills_id', right_on='id', how='left')
# Clean up the dataframe
skill_similarities = self.clean_up_df(skill_similarities)
skill_similarities = skill_similarities[['id', 'preferred_label', 'level_1', 'level_2', 'level_3', 'counts', 'prevalence', 'score' , 'stdev']]
return skill_similarities
def get_cluster_gaps(self, level='level_1'):
""" Agregates scores for ESCO skills clusters """
# Save the level of analysis
self.level = level
# Add skills cluster information
skill_similarities_all_clust = self.skill_similarities_all.merge(data.skills[[
'id', 'preferred_label', 'level_1', 'level_2', 'level_3', 'code']], left_on='skills_id', right_on='id')
# Aggregate scores
skill_similarities = self.count_and_agg_scores(skill_similarities_all_clust, level)
skill_similarities['prevalence'] = skill_similarities['counts'] / self.n_trans
# Add skills cluster title
skill_similarities = skill_similarities.merge(data.concepts[['code','title']], left_on=level, right_on='code')
# Clean up the dataframe
skill_similarities = self.clean_up_df(skill_similarities)
skill_similarities = skill_similarities[['code', 'title', 'counts', 'prevalence', 'score', 'stdev']]
return skill_similarities
def clean_up_df(self, df):
""" Clean up the dataframe for presentation """
df.prevalence = df.prevalence.round(3)
df.similarity = df.similarity.round(3)
df.reset_index(drop=True, inplace=True)
return df
def get_most_prevalent_gaps(self, skills_gaps, top_x=10, percentile=False):
""" Select only the most prevalent skills """
if percentile:
df = skills_gaps[skills_gaps.prevalence > np.percentile(skills_gaps.prevalence, top_x)]
df = df.sort_values('score', ascending=False)
return df
else:
return skills_gaps.sort_values('prevalence', ascending=False).head(top_x).sort_values('score', ascending=False)
def most_prevalent_cluster_skills(self, prevalent_clusters, top_n=3):
""" For each cluster, find top_n most prevalent skills and add to the dataframe """
x = []
for j, row in prevalent_clusters.iterrows():
dff = self.skills_gaps[self.skills_gaps[self.level]==row.code]
dff = dff.sort_values('prevalence', ascending=False).iloc[0:top_n]
xx = []
# Add matching scores
for jj, rrow in dff.iterrows():
xx.append(f'{rrow.preferred_label} ({np.round(rrow.score,2)})')
x.append(', '.join(xx))
prevalent_clusters_ = prevalent_clusters.copy()
prevalent_clusters_['skills'] = x
return prevalent_clusters_
class Upskilling():
"""
Tests upskilling by adding new ESCO skills to occupations' skillsets and
re-evaluating viable transitions
"""
def __init__(self,
origin_ids='report',
new_skillsets=[None],
destination_ids='report',
verbose=False,
load_data_path=False,
):
"""
Parameters
----------
origin_ids (list of int, or str):
Origin occupation integer identifiers
new_skillsets (list of int, or a list of lists):
List of the new skills IDs (or combinations of skills) to be tested;
can feature mixed single skills and combinations e.g. [1, [1000, 23], 3]
destination_ids (list of int, or str):
Destination occupation integer identifiers
"""
self.verbose = verbose
# List of perturbed matrices
self.new_W_combined = None
# Upskilling analysis results
self.upskilling_effects = None
if load_data_path:
self.load_data_path = load_data_path
result_dict = self.load_results()
self.new_W_combined = result_dict['new_W_combined']
origin_ids = result_dict['origin_ids']
destination_ids = result_dict['destination_ids']
new_skillsets = result_dict['new_skillsets']
if 'upskilling_effects' in list(result_dict.keys()):
self.upskilling_effects = result_dict['upskilling_effects']
# Origin and destination occupations
self.origin_ids = occupations_to_check(origin_ids)
self.destination_ids = occupations_to_check(destination_ids)
# Prep a list of lists of skills (allowing us to add multiple skill combinations)
self.list_of_new_skills = [skill if type(skill)==list else [skill] for skill in new_skillsets]
self.n_origin_occupations = len(self.origin_ids)
self.n_destination_occupations = len(self.destination_ids)
self.n_new_skills = len(self.list_of_new_skills)
# Dictionaries mapping matrix element indices to the original occupation IDs
self.origin_ids_to_row_indices = dict(zip(self.origin_ids, list(range(len(self.origin_ids)))))
self.destination_ids_to_col_indices = dict(zip(self.destination_ids, list(range(len(self.destination_ids)))))
self.row_indices_to_origin_ids = dict(zip(list(range(len(self.origin_ids))),self.origin_ids))
self.col_indices_to_destination_ids = dict(zip(list(range(len(self.destination_ids))),self.destination_ids))
## Required variables for re-calculating similarities (Note: should eventually do further refactoring) ##
# Variables for recalculating work activity feature vector similarity
activity_vector_dir = f'{useful_paths.data_dir}interim/work_activity_features/'
self.element_codes_2 = np.array(pickle.load(open(f'{activity_vector_dir}esco_hierarchy_codes_level_2.pickle', 'rb')))
self.normalisation_params = pickle.load(open(f'{activity_vector_dir}esco_hierarchy_norm_params.pickle', 'rb'))
self.occupation_vectors_level_2_abs = np.load(f'{activity_vector_dir}esco_hierarchy_vectors_level_2_abs.npy')
self.occupation_vectors_level_2 = np.load(f'{activity_vector_dir}esco_hierarchy_vectors_level_2.npy')
# Variables including work context similarities into the combined measure
esco_to_work_context_vector = pd.read_csv(useful_paths.data_dir + 'interim/work_context_features/occupations_work_context_vector.csv')
esco_with_work_context = esco_to_work_context_vector[esco_to_work_context_vector.has_vector==True].id.to_list()
occ_no_work_context = set(data.occupations.id.to_list()).difference(set(esco_with_work_context))
self.origin_indices_no_work_context = self.indices_of_specified_elements(self.origin_ids, occ_no_work_context)
self.destination_indices_no_work_context = self.indices_of_specified_elements(self.destination_ids, occ_no_work_context)
# Parameters for combining the different similarity measures
with open(f'{useful_paths.codebase_dir}configs/default_combined_similarity_params.yaml', 'r') as f:
self.combining_params = yaml.load(f, Loader=yaml.FullLoader)
@staticmethod
def indices_of_specified_elements(list_of_ids, list_of_specified_ids):
""" Outputs indices of elements in list_of_ids which are also in the list_of_specified_ids """
indices = []
for j, element_j in enumerate(list_of_ids):
if element_j in list_of_specified_ids:
indices.append(j)
return indices
def effectiveness(self,
safe_definition='default',
significance_test_tolerance=False,
select_origin_ids=None,
select_destination_ids=None):
"""
Summarise the effectiveness of the tested skills across the specified transitions
(by default, characterise across all transitions)
"""
if self.upskilling_effects is None:
self.new_transitions()
# Compile a table with summary stats for each skill
skills_analysis_results = []
for n, new_skill in enumerate(self.list_of_new_skills):
upskilling_dict = self.upskilling_effects[n]
analysis_dict = {}
analysis_dict['new_skill'] = upskilling_dict['new_skill']
analysis_dict['new_skill_label'] = upskilling_dict['new_skill_label']
# Analyse novel transitions
transition_df = upskilling_dict['transition_table']
transition_df = transition_df[transition_df.is_new]
# Select only the transition destinations of interest
if select_destination_ids is not None:
selected_transition_df = transition_df[transition_df.destination_id.isin(select_destination_ids)]
else:
selected_transition_df = transition_df
# Select safe and desirable
if safe_definition=='default':
selected_transition_df = selected_transition_df[selected_transition_df.is_safe_desirable]
elif safe_definition=='strict':
selected_transition_df = selected_transition_df[selected_transition_df.is_strictly_safe_desirable]
elif safe_definition==None:
selected_transition_df = selected_transition_df[selected_transition_df.is_desirable]
df = self.count_transitions(selected_transition_df)
if select_origin_ids is not None:
df = df[df.origin_id.isin(select_origin_ids)]
analysis_dict['n_mean'] = df.counts.mean()
analysis_dict['n_median'] = df.counts.median()
if significance_test_tolerance is not False:
analysis_dict['p_value'] = wilcoxon(df.counts.to_list(), correction=True).pvalue
analysis_dict['is_significant'] = analysis_dict['p_value'] < significance_test_tolerance
skills_analysis_results.append(analysis_dict)
skills_analysis_df = pd.DataFrame(data=skills_analysis_results)
skills_analysis_df = self.clean_up_df(skills_analysis_df)
return skills_analysis_df.sort_values('n_mean', ascending=False)
@staticmethod
def clean_up_list(old_list):
new_list = []
contains_combinations = False
for x in old_list:
if len(x) == 1:
new_list.append(x[0])
else:
new_list.append(x)
contains_combinations = True
return new_list, contains_combinations
@staticmethod
def add_skills_categories(df):
df = data.add_field_to_skill(df, 'new_skill', 'level_1')
df = df.merge(data.concepts[['code', 'title']], left_on='level_1', right_on='code', how='left').drop('code', axis=1).rename(columns={'title': 'ESCO skill category'})
df = data.add_field_to_skill(df, 'new_skill', 'level_2')
df = df.merge(data.concepts[['code', 'title']], left_on='level_2', right_on='code', how='left').drop('code', axis=1).rename(columns={'title': 'ESCO skill subcategory'})
return df
def clean_up_df(self, df):
df.new_skill, contains_combinations = self.clean_up_list(df.new_skill.to_list())
df.new_skill_label, _ = self.clean_up_list(df.new_skill_label.to_list())
if not contains_combinations: df = self.add_skills_categories(df)
return df
def new_transitions(self,
MIN_VIABLE = MIN_VIABLE_DEF,
HIGHLY_VIABLE = HIGHLY_VIABLE_DEF,
MAX_JOB_ZONE_DIF = MAX_JOB_ZONE_DIF_DEF,
MIN_EARNINGS_RATIO = MIN_EARNINGS_RATIO_DEF):
"""
Evaluates the new transitions after upskilling
"""
if self.new_W_combined is None:
self.recalculate_similarities()
W_combined_baseline = sim.W_combined[self.origin_ids,:].copy()
W_combined_baseline = W_combined_baseline[:, self.destination_ids]
self.upskilling_effects = []
for n, new_skill in enumerate(self.list_of_new_skills):
W_new_combined = self.new_W_combined[n]
# Get new transitions above similarity threshold
viable_transitions = np.where((W_new_combined > MIN_VIABLE) & (W_combined_baseline <= MIN_VIABLE))
# Get new transition similarities
new_similarities = W_new_combined[viable_transitions]
# Fetch other data about the transition
transition_pairs_indices = [(viable_transitions[0][x], viable_transitions[1][x]) for x in range(len(viable_transitions[0]))]
transition_pairs_ids = [(self.row_indices_to_origin_ids[i], self.col_indices_to_destination_ids[j]) for i, j in transition_pairs_indices]
transition_df = get_transition_data(transition_pairs_ids, verbose=self.verbose)
# Organise the dataframe
transition_df = transition_df.drop(['W_skills', 'W_work', 'W_essential_skills', 'W_optional_skills', 'W_activities', 'W_work_context'], axis=1)
transition_df['baseline_viable'] = transition_df['is_viable'].copy()
# Find the novel transitions
transition_df['new_similarity'] = new_similarities
transition_df['is_viable'] = (transition_df['new_similarity']>MIN_VIABLE) & transition_df['is_jobzone_ok']
transition_df['is_desirable'] = transition_df['is_viable'] & transition_df['is_earnings_ok']
transition_df['is_safe_desirable'] = transition_df['is_desirable'] & transition_df['is_not_high_risk']
transition_df['is_strictly_safe_desirable'] = transition_df['is_desirable'] & transition_df['is_strictly_safe']
# Flag for brand new viable transitions
transition_df['is_new'] = transition_df['is_viable'] & (transition_df['baseline_viable'] == False)
# Count new safe and desirable transitions for each occupation
counts_safe_desirable = self.count_transitions(transition_df[transition_df.is_new & transition_df.is_safe_desirable])
counts_strictly_safe_desirable = self.count_transitions(transition_df[transition_df.is_new & transition_df.is_strictly_safe_desirable])
# List of new transition destinations for each occupation
new_transitions = []
for job_i in self.origin_ids:
df = transition_df[transition_df.origin_id==job_i]
job_i_trans = {'origin_id': job_i,
'origin_label': job_i,
'destination_id': [],
'destination_label': []}
if len(df) != 0:
for j, row in df.iterrows():
job_i_trans['destination_label'].append(row.destination_label)
job_i_trans['destination_id'].append(row.destination_id)
new_transitions.append(job_i_trans)
# Store all the information about effects of adding the skills
self.upskilling_effects.append(
{
'new_skill': new_skill,
'new_skill_label': [data.skills.loc[s].preferred_label for s in new_skill],
'new_transitions': new_transitions,
'counts_new_safe_desirable': counts_safe_desirable,
'counts_new_strictly_safe_desirable': counts_strictly_safe_desirable,
'transition_table': transition_df}
)
def recalculate_similarities(self, load_data=False):
""" Recalculates all similarities and combines them """
# Recalculate all skills and work activity similarities with the new sets of skills
self.new_W_essential_skills = self.recalculate_skills_similarities(skills_match = 'essential')
self.new_W_optional_skills = self.recalculate_skills_similarities(skills_match = 'optional')
self.new_W_activities = self.recalculate_work_activity_similarities()
# Get work context similarities (don't need to be recalculated)
self.W_work_context = self.fetch_work_context_similarities()
# For each set of skills, combine the new similarity matrices
self.new_W_combined = []
for n, new_skills in enumerate(self.list_of_new_skills):
# Calculate the new combined, perturbed similarity matrix
W_combined = self.combine_similarity_measures(
self.new_W_essential_skills[n],
self.new_W_optional_skills[n],
self.new_W_activities[n],
self.W_work_context,
self.combining_params
)
self.new_W_combined.append(W_combined)
def combine_similarity_measures(self, W_essential, W_optional, W_activities, W_context, params):
""" Calculates the combined similarity measure, according to parameters in params """
# Combined similarity matrix
W_combined = (params['p_essential_skills'] * W_essential) + (params['p_optional_skills'] * W_optional) + (params['p_work_activities'] * W_activities) + (params['p_work_context'] * W_context)
# Adjust for cases where work context doesn't exist for either origin or destination occupation
p_essential_skills_x = params['p_essential_skills']/(1-params['p_work_context'])
p_optional_skills_x = params['p_optional_skills']/(1-params['p_work_context'])
p_work_activities_x = params['p_work_activities']/(1-params['p_work_context'])
for i in self.origin_indices_no_work_context:
for j in range(len(W_combined)):
W_combined[i][j] = (p_essential_skills_x * W_essential[i][j]) + (p_optional_skills_x * W_optional[i][j]) + (p_work_activities_x * W_activities[i][j])
for i in range(len(W_combined)):
for j in self.destination_indices_no_work_context:
W_combined[i][j] = (p_essential_skills_x * W_essential[i][j]) + (p_optional_skills_x * W_optional[i][j]) + (p_work_activities_x * W_activities[i][j])
return W_combined
def recalculate_skills_similarities(self, skills_match = 'optional'):
"""
Add skills to occupations' skillsets and recalculate NLP-adjusted overlaps
"""
if self.verbose: print(f'Recalculating {skills_match} skills similarities...')
# Origin occupations' skills lists
if skills_match == 'optional':
origin_node_to_items = data.node_to_all_items.loc[self.origin_ids].copy()
elif skills_match == 'essential':
origin_node_to_items = data.node_to_essential_items.loc[self.origin_ids].copy()
origin_node_to_items.sector = 'origin'
# Adjust IDs of the origin items
origin_node_to_items = self.adjust_node_ids(origin_node_to_items)
# Destination occupations' skills lists (always the 'essential' skills only)
destination_node_to_items = data.node_to_essential_items.loc[self.destination_ids].copy()
destination_node_to_items.sector = 'destination'
# Adjust IDs of the destination items
destination_node_to_items = self.adjust_node_ids(destination_node_to_items, id_offset = self.n_origin_occupations)
# List with all perturbed similarity matrices
list_of_new_W = []
# Go through each new skill in question and test them out!
for new_skills in self.list_of_new_skills:
if self.verbose: print(f'Adding skill(s) {new_skills} to origin occupations.')
# Add skills items to each origin occupation's skills list
perturbed_origin_node_to_items = origin_node_to_items.copy()
new_items_list = [] # New skills lists
for job_i, row in perturbed_origin_node_to_items.iterrows():
# Original skillset of the origin occupation
original_skillset = set(row.items_list)
# Add the set of new skills
new_skillset = original_skillset.union(set(new_skills))
new_items_list.append(str(sorted(list(new_skillset))))
# Update the origin skills lists
perturbed_origin_node_to_items.items_list = new_items_list
# Re-evaluate all items lists so that they are treated as lists
perturbed_origin_node_to_items.items_list = perturbed_origin_node_to_items.items_list.apply(lambda x: literal_eval(x))
# Combine both origin and destination lists of skills
node_to_items = pd.concat([perturbed_origin_node_to_items, destination_node_to_items]).reset_index(drop=True)
with np.errstate(divide='ignore'): # suppress the warning, due to the one occupation without essential skills
# Perform the comparison!
Comp = compare_nodes_utils.CompareSectors(
node_to_items,
embeddings,
combos=[('origin','destination')],
metric='cosine',
symmetric=False,
verbose=False)
t = time()
if self.verbose: print('Running comparisons...', end=' ')
Comp.run_comparisons(dump=False)
Comp.collect_comparisons()
t_elapsed = time()-t
if self.verbose: print(f'Done in {t_elapsed:.0f} seconds!')
# Processing the outputs (select only the relevant edges, starting from origin occupations)
W = Comp.D
i_edges = [edge[0] for edge in Comp.real_edge_list]
origin_edges = np.array(Comp.real_edge_list)[np.where(np.array(i_edges)<self.n_origin_occupations)[0]]
W_perturbed = np.zeros((self.n_origin_occupations,self.n_destination_occupations))
for edge in origin_edges:
W_perturbed[edge[0], edge[1]-self.n_origin_occupations] = W[edge[0],edge[1]]
# Take care of nulls (might appear if destination occupation had no essential skills)
W_perturbed[np.isinf(W_perturbed)] = 0
# Store the new, perturbed similarity matrix
list_of_new_W.append(W_perturbed)
return list_of_new_W
@staticmethod
def adjust_node_ids(node_to_items, id_offset=0):
""" Helper function for self.recalculate_skills_similarities() """
node_to_items['original_id'] = node_to_items.id.copy()
node_to_items['id'] = np.array(list(range(0, len(node_to_items)))) + id_offset
node_to_items.reset_index(drop=True)
return node_to_items
def recalculate_work_activity_similarities(self):
"""
Recalculates similarity between work activity vectors
"""
t = time()
if self.verbose: print('Recalculating work activity feature vector alignments...', end=' ')
# List with all perturbed similarity matrices
list_of_new_W = []
# Go through each new set of skills in question and test them out!
for new_skills in self.list_of_new_skills:
# Re-calculated similarities
W_perturbed = np.zeros((self.n_origin_occupations,self.n_destination_occupations))
# For each origin occupation
for i, job_i in enumerate(self.origin_ids):
# Existing work activity feature vector
new_feature_vector = self.occupation_vectors_level_2_abs[job_i].copy()
origin_skillset = data.node_to_essential_items.loc[[job_i]].items_list.values[0]
# For each single skill in the new set of skills
for new_skill_id in new_skills:
# Find the skill's hierarchy code
skill_code = data.skills.loc[new_skill_id].level_2
# Check if the skill is already in the skill set
if new_skill_id in origin_skillset:
pass
# Check if the skill is a knowledge or attitude item (these are not included in the measure)
elif skill_code[0] in ['K', 'A']:
pass
# Add the skill to the job_i feature vector
else:
# Find the element number for the skill
element_id = np.where(self.element_codes_2==skill_code)[0][0]
# Increment the element by one
new_feature_vector[element_id] += 1
# Create a new normalised feature vector
new_feature_vector = new_feature_vector.reshape(1,-1)
new_feature_vector_norm = normalize(new_feature_vector)
# Re-calculate the similarity
new_d = cdist(new_feature_vector_norm, self.occupation_vectors_level_2[self.destination_ids,:], 'euclidean')
new_d = (new_d - self.normalisation_params['d_MIN_LEVEL2'])/(self.normalisation_params['d_MAX_LEVEL2']-self.normalisation_params['d_MIN_LEVEL2'])
new_similarities = 1-new_d # Vector of the new similarities
# Store the similarities in the perturbed similarity matrix
for j, new_sim in enumerate(new_similarities[0,:]):
W_perturbed[i, j] = new_sim
W_perturbed[np.isinf(W_perturbed)] = 0 # just in case
# Store the new, perturbed similarity matrix
list_of_new_W.append(W_perturbed)
t_elapsed = time()-t
if self.verbose: print(f'Done in {t_elapsed:.0f} seconds!')
return list_of_new_W
def fetch_work_context_similarities(self):
W_work_context = sim.W_work_context[self.origin_ids, :].copy()
W_work_context = W_work_context[:, self.destination_ids]
return W_work_context
def count_transitions(self, transition_df):
# Numbers for each occupation
df = transition_df.groupby('origin_id').agg({'destination_id': 'count'}).reset_index().rename(columns={'destination_id': 'counts'})
# Add occupations without any new transitions
df_ids = pd.DataFrame(data={'origin_id': self.origin_ids})
df_ids = df_ids.merge(df, how='left')
df_ids.loc[df_ids.counts.isnull(), 'counts'] = 0
return df_ids
def dump_results(self, filename='upskilling_results.pickle', dir=f'{useful_paths.data_dir}interim/upskilling_analysis/'):
"""
Dumps the recalculated, perturbed skills matrices for later reuse
"""
if self.verbose: print(f'Dumping in {dir+filename}')
result_dict = {
'origin_ids': self.origin_ids,
'destination_ids': self.destination_ids,
'new_skillsets': self.list_of_new_skills,
'new_W_combined': self.new_W_combined,
'upskilling_effects': self.upskilling_effects
}
pickle_large_files.pickle_dump(result_dict, dir+filename)
def load_results(self):
"""
Loads pre-computed perturbed skills matrices
"""
if self.verbose: print(f'Loading data form {self.load_data_path}')
return pickle_large_files.pickle_load(self.load_data_path)
def get_flow_matrix(trans_clust, level):
""" Number of transitions between clusters (e.g. sectors and sub-sectors) """
n_clust = len(np.unique(data.occ[level]))
flow_matrix = np.zeros((n_clust, n_clust))
for j, row in trans_clust.iterrows():
clust_origin = row['origin_' + level]
clust_destination = row['destination_' + level]
flow_matrix[clust_origin, clust_destination] += 1
return flow_matrix
def normalise_rows(A):
A = A.copy()
for j in range(len(A)):
A[j,:] = A[j,:] / np.sum(A[j,:])
return A
| python |
from setuptools import setup
setup(name='docx-mailmerge-conted',
version='0.5.1',
description='Performs a Mail Merge on docx (Microsoft Office Word) files',
long_description=open('README.rst').read(),
classifiers=[
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Topic :: Text Processing',
],
author='Tim Nyborg',
author_email='[email protected]',
url='http://github.com/timnyborg/docx-mailmerge',
license='MIT',
py_modules=['mailmerge'],
zip_safe=False,
install_requires=['lxml']
)
| python |
# This python script scrapes data from the scanA.csv and
# scanB.csv files created by the python_cbc_building module
# and stores this scraped data in the SMAP archiver.
#
import os
from string import *
import time
from pytz import timezone
from smap import driver, util
# SMAP heading
smapHeading = "ORNL/cbc"
# Data will be scraped from whichever of these files has the
# most recent write
fileA = "scanA.csv"
fileB = "scanB.csv"
fileHandle = None
# Structure to hold most recent data scraped for a thermostat
class Thermostat:
timestamp = None
temp = None
upper_temp_limit = None
lower_temp_limit = None
addr = None
mode = None
# Map from zone address to Thermostat object for that address
zoneInfo = dict()
# Get the most recently updated file, or return None
# if neither file exists
def select_most_recent_file():
mA = None
mB = None
try:
mA = os.path.getmtime(fileA)
except OSError:
pass
try:
mB = os.path.getmtime(fileB)
except OSError:
pass
if mA == None and mB == None:
return None
if mA == None and mB != None:
return fileB
if mA != None and mB == None:
return fileA
if mA > mB:
return fileA
return fileB
def scrape():
global fileHandle
count = 0
which = select_most_recent_file()
if which == None:
return
if fileHandle == None or fileHandle.name != which:
fileHandle = open(which,"rb",0)
# Reset the end of file indicator
fileHandle.seek(fileHandle.tell())
# Go through the file line by line updating the thermostat
# data as we go
for line in fileHandle:
words = line.split(",")
count = count + 1
if len(words) > 12:
newData = Thermostat()
newData.timestamp = words[0]
newData.addr = words[2]
newData.temp = words[4]
newData.mode = words[6]
if newData.mode == 'idle':
newData.mode = 0
elif newData.mode == 'heat1':
newData.mode = 1
elif newData.mode == 'heat2':
newData.mode = 2
elif newData.mode == 'cool1':
newData.mode = -1
elif newData.mode == 'cool2':
newData.mode = -2
else:
newData.mode = 999
newData.lower_temp_limit = words[10]
newData.upper_temp_limit = words[12]
zoneInfo[newData.addr] = newData
print(("Processed ",count," new lines in file ",fileHandle.name,
fileHandle.tell()))
class cbc_archiver(driver.SmapDriver):
def setup(self, opts):
# Scrape data until we have seen all four zones
while len(zoneInfo) < 4:
scrape()
# Register a timeseries for each zone
print("Adding subjects...")
self.add_timeseries(smapHeading+"/peak_power_reduction",'%',data_type='double',timezone='US/Eastern')
for data in list(zoneInfo.values()):
name = smapHeading+"/zone/"+data.addr
self.add_timeseries(name+'/temp', 'F', data_type='double', timezone='US/Eastern')
self.add_timeseries(name+'/mode', '', data_type='long', timezone='US/Eastern')
self.add_timeseries(name+'/lower_temp_limit', 'F', data_type='double', timezone='US/Eastern')
self.add_timeseries(name+'/upper_temp_limit', 'F', data_type='double', timezone='US/Eastern')
print("done!")
def start(self):
util.periodicSequentialCall(self.read).start(60)
def read(self):
# Look for new data
scrape()
# Record the new data
timestamp = 0
operating = 0.0
would_operate = 0.0
max_operate = 0.0
peak_power_reduction = 0.0
for data in list(zoneInfo.values()):
max_operate = max_operate + 1.0
if data.mode != 0:
operating = operating+1.0
if float(data.temp) < float(data.lower_temp_limit) or float(data.temp) > float(data.upper_temp_limit):
would_operate = would_operate+1.0
name = smapHeading+"/zone/"+data.addr
timestamp = time.mktime(time.strptime(data.timestamp,"%Y-%m-%d %H:%M:%S"))
self.add(name+'/temp',timestamp,float(data.temp))
self.add(name+'/mode',timestamp,int(data.mode))
self.add(name+'/lower_temp_limit',timestamp,float(data.lower_temp_limit))
self.add(name+'/upper_temp_limit',timestamp,float(data.upper_temp_limit))
if would_operate > 0.0:
peak_power_reduction = 1.0-operating/would_operate
self.add(smapHeading+"/peak_power_reduction",timestamp,peak_power_reduction)
| python |
# Copyright 2021-2022 NVIDIA Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from __future__ import annotations
from typing import TYPE_CHECKING, Any, Optional, TypeVar, Union
import numpy as np
from . import Future, legion
from .operation import AutoTask, Copy, ManualTask, Reduce
from .resource import ResourceScope
from .types import TypeSystem
if TYPE_CHECKING:
import numpy.typing as npt
from pyarrow import DataType
from . import ArgumentMap, Rect
from ._legion.util import Dispatchable
from .communicator import Communicator
from .legate import Library
from .runtime import Runtime
from .shape import Shape
from .store import RegionField, Store
T = TypeVar("T")
class Context:
def __init__(
self,
runtime: Runtime,
library: Library,
inherit_core_types: bool = True,
) -> None:
"""
A Context is a named scope for Legion resources used in a Legate
library. A Context is created when the library is registered
for the first time to the Legate runtime, and it must be passed
when the library registers or makes accesses to its Legion resources.
Resources that are scoped locally to each library include
task ids, projection and sharding functor ids, and reduction operator
ids.
"""
self._runtime = runtime
self._library = library
self._type_system = TypeSystem(inherit_core_types)
config = library.get_resource_configuration()
name = library.get_name().encode("utf-8")
lg_runtime = self._runtime.legion_runtime
def _create_scope(
api: Any, category: str, max_counts: int
) -> ResourceScope:
base = (
api(lg_runtime, name, max_counts) if max_counts > 0 else None
)
return ResourceScope(self, base, category)
self._task_scope = _create_scope(
legion.legion_runtime_generate_library_task_ids,
"task",
config.max_tasks,
)
self._mapper_scope = _create_scope(
legion.legion_runtime_generate_library_mapper_ids,
"mapper",
config.max_mappers,
)
self._redop_scope = _create_scope(
legion.legion_runtime_generate_library_reduction_ids,
"reduction op",
config.max_reduction_ops,
)
self._proj_scope = _create_scope(
legion.legion_runtime_generate_library_projection_ids,
"Projection functor",
config.max_projections,
)
self._shard_scope = _create_scope(
legion.legion_runtime_generate_library_sharding_ids,
"sharding functor",
config.max_shardings,
)
self._unique_op_id = 0
def destroy(self) -> None:
self._library.destroy()
@property
def runtime(self) -> Runtime:
return self._runtime
@property
def library(self) -> Library:
return self._library
@property
def core_library(self) -> Any:
return self._runtime.core_library
@property
def first_mapper_id(self) -> Union[int, None]:
return self._mapper_scope._base
@property
def first_redop_id(self) -> Union[int, None]:
return self._redop_scope._base
@property
def first_shard_id(self) -> Union[int, None]:
return self._shard_scope._base
@property
def empty_argmap(self) -> ArgumentMap:
return self._runtime.empty_argmap
@property
def type_system(self) -> TypeSystem:
return self._type_system
def get_task_id(self, task_id: int) -> int:
return self._task_scope.translate(task_id)
@property
def mapper_id(self) -> int:
return self.get_mapper_id(0)
def get_mapper_id(self, mapper_id: int) -> int:
return self._mapper_scope.translate(mapper_id)
def get_reduction_op_id(self, redop_id: int) -> int:
return self._redop_scope.translate(redop_id)
def get_projection_id(self, proj_id: int) -> int:
if proj_id == 0:
return proj_id
else:
return self._proj_scope.translate(proj_id)
def get_sharding_id(self, shard_id: int) -> int:
return self._shard_scope.translate(shard_id)
def get_tunable(
self, tunable_id: int, dtype: DataType, mapper_id: int = 0
) -> npt.NDArray[Any]:
dt = np.dtype(dtype.to_pandas_dtype())
mapper_id = self.get_mapper_id(mapper_id)
fut = Future(
legion.legion_runtime_select_tunable_value(
self._runtime.legion_runtime,
self._runtime.legion_context,
tunable_id,
mapper_id,
0,
)
)
buf = fut.get_buffer(dt.itemsize)
return np.frombuffer(buf, dtype=dt)[0]
def get_unique_op_id(self) -> int:
return self._runtime.get_unique_op_id()
def create_task(
self,
task_id: int,
mapper_id: int = 0,
manual: Optional[bool] = False,
launch_domain: Optional[Rect] = None,
) -> Union[AutoTask, ManualTask]:
unique_op_id = self.get_unique_op_id()
if not manual:
return AutoTask(self, task_id, mapper_id, unique_op_id)
else:
if launch_domain is None:
raise RuntimeError(
"Launch domain must be specified for "
"manual parallelization"
)
return ManualTask(
self,
task_id,
launch_domain,
mapper_id,
unique_op_id,
)
def create_copy(self, mapper_id: int = 0) -> Copy:
return Copy(self, mapper_id)
def dispatch(self, op: Dispatchable[T]) -> T:
return self._runtime.dispatch(op)
def dispatch_single(self, op: Dispatchable[T]) -> T:
return self._runtime.dispatch_single(op)
def create_store(
self,
ty: Any,
shape: Optional[Shape] = None,
storage: Optional[Union[RegionField, Future]] = None,
optimize_scalar: bool = False,
ndim: Optional[int] = None,
) -> Store:
dtype = self.type_system[ty]
return self._runtime.create_store(
dtype,
shape=shape,
data=storage,
optimize_scalar=optimize_scalar,
ndim=ndim,
)
def get_nccl_communicator(self) -> Communicator:
return self._runtime.get_nccl_communicator()
def issue_execution_fence(self, block: bool = False) -> None:
self._runtime.issue_execution_fence(block=block)
def tree_reduce(
self, task_id: int, store: Store, mapper_id: int = 0, radix: int = 4
) -> Store:
result = self.create_store(store.type)
unique_op_id = self.get_unique_op_id()
# Make sure we flush the scheduling window, as we will bypass
# the partitioner below
self.runtime.flush_scheduling_window()
# A single Reduce operation is mapepd to a whole reduction tree
task = Reduce(self, task_id, radix, mapper_id, unique_op_id)
task.add_input(store)
task.add_output(result)
task.execute()
return result
| python |
# -*- coding: utf-8 -*-
# --------------------------------------------------------
# RefineDet in PyTorch
# Written by Dongdong Wang
# Official and original Caffe implementation is at
# https://github.com/sfzhang15/RefineDet
# --------------------------------------------------------
import sys
import torch
import torch.nn as nn
from torch.autograd import Variable
import torch.nn.functional as functional
from libs.utils.box_utils import decode, nms
import pdb
sys.dont_write_bytecode = True
class Detect(nn.Module):
"""At test time, Detect is the final layer of RefineDet.
Decode location preds, apply non-maximum suppression to location predictions
based on conf scores and threshold to a top_k number of output predictions
for both confidence score and locations.
"""
def __init__(self, num_classes, odm_variance,
top_k_pre_class, top_k, detect_conf_thresh, nms_thresh):
"""
:param num_classes: number of classes.
:param variance:
:param top_k_pre_class: keep the top k for nms in each class.
:param top_k: keep the top k of detection results.
:param detect_conf_thresh: keep detections whoes confidence is big.
:param nms_thresh:
"""
super(Detect, self).__init__()
self.num_classes = num_classes
self.top_k_per_class = top_k_pre_class
self.keep_top_k = top_k
# Parameters used in nms.
self.detect_conf_thresh = detect_conf_thresh
self.nms_thresh = nms_thresh
self.variance = odm_variance
def forward(self, odm_predictions, refined_anchors,
ignore_flags_refined_anchor):
"""
:param odm_predictions:
0).odm_loc_data: (tensor) location predictions from loc layers of ODM
Shape: (batch_size, num_anchors, 4)
1).odm_conf_data: (tensor) confidence predictions from conf layers of ODM
Shape: (batch_size, num_anchors, num_classes)
:param refined_anchors: (batch_size, num_anchors, 4)
:param ignore_flags_refined_anchor: (batch_size, num_anchors),
1 means an igored negative anchor, otherwise reserved.
"""
# pdb.set_trace()
loc_data = odm_predictions[0].data
score_data = functional.softmax(odm_predictions[1].detach(),
dim=-1).data
# Output
num = refined_anchors.size(0)
output = torch.zeros(num, self.num_classes, self.top_k_per_class,
5).type_as(loc_data)
# select
# For each image, keep keep_top_k,
# retain top_k per class for nms.
for idx in range(num):
# Decoded odm bbox prediction to get boxes
all_boxes = decode(loc_data[idx], refined_anchors[idx],
self.variance)
# Ignore predictions whose positive scores are small.
# pdb.set_trace()
flag = ignore_flags_refined_anchor[idx].data < 1
box_flag = flag.unsqueeze(flag.dim()).expand_as(all_boxes)
conf_flag = flag.unsqueeze(flag.dim()).expand_as(score_data[idx])
select_boxes = all_boxes[box_flag].view(-1, 4)
# ?
select_scores = score_data[idx][conf_flag].view(
-1, self.num_classes).transpose(1, 0)
# NMS per class
for icl in range(1, self.num_classes):
c_mask = select_scores[icl].gt(self.detect_conf_thresh)
# pdb.set_trace()
# print(type(c_mask))
scores = select_scores[icl][c_mask]
if len(scores) == 0:
continue
l_mask = c_mask.unsqueeze(1).expand_as(select_boxes)
boxes = select_boxes[l_mask].view(-1, 4)
# idx of highest scoring and non-overlapping boxes per class
ids, count = nms(boxes, scores, self.nms_thresh,
self.top_k_per_class)
output[idx, icl, :count] = \
torch.cat((scores[ids[:count]].unsqueeze(1),
boxes[ids[:count]]), 1)
# Sort each image,
# But since fill_ function is used, this is useless.
# pdb.set_trace()
flt = output.contiguous().view(num, -1, 5)
_, idx = flt[:, :, 0].sort(1, descending=True)
_, rank = idx.sort(1)
return flt.view(num, self.num_classes, self.top_k_per_class, 5)
| python |
# *****************************************************************************
# Copyright 2004-2008 Steve Menard
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# *****************************************************************************
import jpype
from jpype import JException, java, JProxy, JClass
from jpype.types import *
import traceback
import common
def throwIOException():
raise java.io.IOException("Test throw")
def throwByJavaException():
JClass('jpype.exc.ExceptionTest').throwIOException()
class ExceptionTestCase(common.JPypeTestCase):
def testExceptionThrown(self):
ext = JClass('jpype.exc.ExceptionTest')
try:
ext.throwRuntime()
self.fail()
except JException as ex:
self.assertIs(type(ex), java.lang.RuntimeException)
self.assertEqual('Foo', ex.message())
trace = ex.stacktrace()
self.assertTrue(str(trace).startswith(
'java.lang.RuntimeException: Foo'))
def testExceptionByJavaClass(self):
ext = JClass('jpype.exc.ExceptionTest')
try:
ext.throwRuntime()
self.fail()
except java.lang.RuntimeException as ex:
self.assertIs(type(ex), java.lang.RuntimeException)
self.assertEqual('Foo', ex.message())
trace = ex.stacktrace()
self.assertTrue(str(trace).startswith(
'java.lang.RuntimeException: Foo'))
def testThrowException(self):
exthrow = JClass('jpype.exc.ExceptionThrower')
extest = JClass('jpype.exc.ExceptionTest')
d = {"throwIOException": throwIOException, }
p = JProxy(exthrow, dict=d)
self.assertTrue(extest.delegateThrow(p))
def testThrowException3(self):
exthrow = JClass('jpype.exc.ExceptionThrower')
extest = JClass('jpype.exc.ExceptionTest')
d = {"throwIOException": throwByJavaException, }
p = JProxy(exthrow, dict=d)
self.assertTrue(extest.delegateThrow(p))
# This test is problematic as __name__ is a class property not an object property
# def testExceptionPYEXCName(self):
# e = self.jpype.exc.ChildTestException()
# name = "jpype.exc.ChildTestException"
# self.assertEqual(name, e.__name__)
def testExceptionInstanceof(self):
e = self.jpype.exc.ChildTestException()
self.assertIsInstance(e, self.jpype.exc.ParentTestException)
def testExceptionPYEXCInstanceof(self):
e = self.jpype.exc.ChildTestException
self.assertTrue(issubclass(e, self.jpype.exc.ParentTestException))
def testThrowChildExceptionFromCatchJExceptionParentClass(self):
try:
self.jpype.exc.ExceptionTest.throwChildTestException()
self.fail()
except self.jpype.exc.ParentTestException as ex:
self.assertIsInstance(ex, self.jpype.exc.ChildTestException)
def testCause(self):
cls = jpype.JClass("jpype.exc.ExceptionTest")
try:
cls.throwChain()
except Exception as ex:
ex1 = ex
self.assertEqual(str(ex1.__cause__), "Java Exception")
frame = ex1.__cause__.__traceback__
expected = [
'jpype.exc.ExceptionTest.throwChain',
'jpype.exc.ExceptionTest.method1',
'jpype.exc.ExceptionTest.method2',
]
i = 0
while (frame):
self.assertEqual(frame.tb_frame.f_code.co_name, expected[i])
frame = frame.tb_next
i += 1
def testIndexError(self):
with self.assertRaises(IndexError):
raise java.lang.IndexOutOfBoundsException("From Java")
def testValueError(self):
js = JObject(None, JString)
with self.assertRaises(ValueError):
js.substring(0)
def testExcCtor(self):
WE = jpype.JClass("jpype.exc.WierdException")
with self.assertRaises(WE):
WE.testThrow()
try:
WE.testThrow()
except Exception as ex:
ex1 = ex
self.assertEqual(ex1.args, ("Got it",))
def testExcCauseChained1(self):
import jpype.imports
try:
from org.jpype.fail import BadInitializer
except Exception as ex:
ex1 = ex
self.assertIsInstance(ex1, ImportError)
self.assertIsInstance(ex1.__cause__, JClass(
"java.lang.ExceptionInInitializerError"))
self.assertIsInstance(ex1.__cause__.__cause__, JClass(
"java.lang.ArrayIndexOutOfBoundsException"))
self.assertTrue(ex1.__cause__.__traceback__ is not None)
self.assertTrue(ex1.__cause__.__cause__.__traceback__ is not None)
def testExcCauseChained2(self):
try:
JClass('org.jpype.fail.BadInitializer2')
except Exception as ex:
ex1 = ex
self.assertIsInstance(ex1, JClass(
'java.lang.ExceptionInInitializerError'))
self.assertIsInstance(ex1.__cause__.__cause__, JClass(
"java.lang.ArrayIndexOutOfBoundsException"))
self.assertTrue(ex1.__cause__.__traceback__ is not None)
self.assertTrue(ex1.__cause__.__cause__.__traceback__ is not None)
def testExpandStacktrace(self):
Th = jpype.JClass('java.lang.Throwable')
null = jpype.JObject(None, Th)
# The next line should not fail
Th._expandStacktrace(null)
| python |
# lista = [2, 4, 2, 2, 3, 3, 1]
def remove_repetidos(lista):
lista_aux = []
for element in lista:
if element not in lista_aux:
lista_aux.append(element)
return sorted(lista_aux)
# print(remove_repetidos(lista))
| python |
FTX_MAX_REQUESTS_RESET = "FTX_MAX_REQUESTS_RESET"
FTX_TOTAL_REQUESTS = "FTX_TOTAL_REQUESTS"
API_URL = "https://ftx.com/api"
MAX_RESULTS = 200
MIN_ELAPSED_PER_REQUEST = 1 / 30.0 # 30 req/s
# For MOVE
BTC = "BTC"
BTCMOVE = "BTC-MOVE"
| python |
import uuid
from django.conf import settings
from django.contrib.auth.hashers import make_password, check_password
from django.contrib.auth.models import (User)
from django.utils.module_loading import import_module
from authy_me.models import AuthenticatorModel
def is_int(s):
"""
Checks if the content is of type int or not.
Parameters
----------
s: int
Input should be integer type.
Returns
-------
bool: bool
Returns True is the input is of type integer else returns False.
"""
try:
int(s)
return True
except ValueError:
return False
def has_2fa(request):
"""
Checks if `AuthenticatorModel` is associated with `User` model.
Returns
-------
content: bool
Returns True is if `AuthenticatorModel` is associated with `User` else returns False.
"""
content = True
try:
user = User.objects.get(username=request.user)
except User.DoesNotExist:
content = False
return content
try:
user_auth = user.auth_user.get(user_id=request.user)
except AuthenticatorModel.DoesNotExist:
content = False
return content
return content
def get_user_from_sid(session_key):
"""
Returns users id bassed on the session.
Parameters
----------
session_key: str
User session key.
Returns
-------
uid: int
Users id.
"""
django_session_engine = import_module(settings.SESSION_ENGINE)
session = django_session_engine.SessionStore(session_key)
uid = session.get('_auth_user_id')
return uid
def get_uuid_json():
"""
Returns a JSON string of 10 UUID's.
Returns
-------
content: dict
A dictionary.
"""
content = {"uuid": []}
for i in range(10):
content['uuid'].append(str(uuid.uuid4())[:13])
return content
def generate_password(pwd, salt=None):
"""
Generates a new password based on salt.
Parameters
----------
salt : str
Alpha-numeric string.
Returns
-------
hashed_password: str
Hashed password.
"""
hashed_password = make_password(pwd, salt)
return hashed_password
def check_hashed_password(password, hash_value):
"""
Checks the hashed password with original password.
Parameters
----------
password: str
Original password.
hash_value: str
Hashed password.
Returns
-------
yea_or_ney: bool
Yes or no.
"""
yea_or_nay = check_password(password, hash_value)
return yea_or_nay
| python |
# Original code from: https://github.com/m4jidRafiei/Decision-Tree-Python-
#
# Modified by a student to return the Digraph object instead of rendering it automatically.
# Modified to avoid error of mis-identification of graphviz nodes. Although I used a random
# generation and probabilistic cosmic rays might introduce equal IDs nevertheless.
from random import random
import math
from collections import deque
from graphviz import Digraph
class Node(object):
def __init__(self):
self.value = None
self.next = None
self.childs = None
self.name = ""
# Simple class of Decision Tree
# Aimed for who want to learn Decision Tree, so it is not optimized
class DecisionTree(object):
def __init__(self, sample, attributes, labels, criterion):
self.sample = sample
self.attributes = attributes
self.labels = labels
self.labelCodes = None
self.labelCodesCount = None
self.initLabelCodes()
self.criterion = criterion
# print(self.labelCodes)
self.gini = None
self.entropy = None
self.root = None
if(self.criterion == "gini"):
self.gini = self.getGini([x for x in range(len(self.labels))])
else:
self.entropy = self.getEntropy([x for x in range(len(self.labels))])
def initLabelCodes(self):
self.labelCodes = []
self.labelCodesCount = []
for l in self.labels:
if l not in self.labelCodes:
self.labelCodes.append(l)
self.labelCodesCount.append(0)
self.labelCodesCount[self.labelCodes.index(l)] += 1
def getLabelCodeId(self, sampleId):
return self.labelCodes.index(self.labels[sampleId])
def getAttributeValues(self, sampleIds, attributeId):
vals = []
for sid in sampleIds:
val = self.sample[sid][attributeId]
if val not in vals:
vals.append(val)
# print(vals)
return vals
def getEntropy(self, sampleIds):
entropy = 0
labelCount = [0] * len(self.labelCodes)
for sid in sampleIds:
labelCount[self.getLabelCodeId(sid)] += 1
# print("-ge", labelCount)
for lv in labelCount:
# print(lv)
if lv != 0:
entropy += -lv/len(sampleIds) * math.log(lv/len(sampleIds), 2)
else:
entropy += 0
return entropy
def getGini(self, sampleIds):
gini = 0
labelCount = [0] * len(self.labelCodes)
for sid in sampleIds:
labelCount[self.getLabelCodeId(sid)] += 1
# print("-ge", labelCount)
for lv in labelCount:
# print(lv)
if lv != 0:
gini += (lv/len(sampleIds)) ** 2
else:
gini += 0
return 1 - gini
def getDominantLabel(self, sampleIds):
labelCodesCount = [0] * len(self.labelCodes)
for sid in sampleIds:
labelCodesCount[self.labelCodes.index(self.labels[sid])] += 1
return self.labelCodes[labelCodesCount.index(max(labelCodesCount))]
def getInformationGain(self, sampleIds, attributeId):
gain = self.getEntropy(sampleIds)
attributeVals = []
attributeValsCount = []
attributeValsIds = []
for sid in sampleIds:
val = self.sample[sid][attributeId]
if val not in attributeVals:
attributeVals.append(val)
attributeValsCount.append(0)
attributeValsIds.append([])
vid = attributeVals.index(val)
attributeValsCount[vid] += 1
attributeValsIds[vid].append(sid)
# print("-gig", self.attributes[attributeId])
for vc, vids in zip(attributeValsCount, attributeValsIds):
# print("-gig", vids)
gain -= (vc/len(sampleIds)) * self.getEntropy(vids)
return gain
def getInformationGainGini(self, sampleIds, attributeId):
gain = self.getGini(sampleIds)
attributeVals = []
attributeValsCount = []
attributeValsIds = []
for sid in sampleIds:
val = self.sample[sid][attributeId]
if val not in attributeVals:
attributeVals.append(val)
attributeValsCount.append(0)
attributeValsIds.append([])
vid = attributeVals.index(val)
attributeValsCount[vid] += 1
attributeValsIds[vid].append(sid)
# print("-gig", self.attributes[attributeId])
for vc, vids in zip(attributeValsCount, attributeValsIds):
# print("-gig", vids)
gain -= (vc/len(sampleIds)) * self.getGini(vids)
return gain
def getAttributeMaxInformationGain(self, sampleIds, attributeIds):
attributesEntropy = [0] * len(attributeIds)
for i, attId in zip(range(len(attributeIds)), attributeIds):
attributesEntropy[i] = self.getInformationGain(sampleIds, attId)
maxId = attributeIds[attributesEntropy.index(max(attributesEntropy))]
try:
maxvalue = attributesEntropy[maxId]
except:
maxvalue = 0
return self.attributes[maxId], maxId, maxvalue
def getAttributeMaxInformationGainGini(self, sampleIds, attributeIds):
attributesEntropy = [0] * len(attributeIds)
for i, attId in zip(range(len(attributeIds)), attributeIds):
attributesEntropy[i] = self.getInformationGainGini(sampleIds, attId)
maxId = attributeIds[attributesEntropy.index(max(attributesEntropy))]
try:
maxvalue = attributesEntropy[maxId]
except:
maxvalue = 0
return self.attributes[maxId], maxId, maxvalue
def isSingleLabeled(self, sampleIds):
label = self.labels[sampleIds[0]]
for sid in sampleIds:
if self.labels[sid] != label:
return False
return True
def getLabel(self, sampleId):
return self.labels[sampleId]
def id3(self,gain_threshold, minimum_samples):
sampleIds = [x for x in range(len(self.sample))]
attributeIds = [x for x in range(len(self.attributes))]
self.root = self.id3Recv(sampleIds, attributeIds, self.root, gain_threshold, minimum_samples)
def id3Recv(self, sampleIds, attributeIds, root, gain_threshold, minimum_samples):
root = Node() # Initialize current root
if self.isSingleLabeled(sampleIds):
root.value = self.labels[sampleIds[0]]
return root
# print(attributeIds)
if len(attributeIds) == 0:
root.value = self.getDominantLabel(sampleIds)
return root
if(self.criterion == "gini"):
bestAttrName, bestAttrId, bestValue = self.getAttributeMaxInformationGainGini(sampleIds, attributeIds)
else:
bestAttrName, bestAttrId, bestValue = self.getAttributeMaxInformationGain(sampleIds, attributeIds)
# print(bestAttrName)
#if(bestValue > 0):
#print("Best gain -> " + bestAttrName + "::" + str(bestValue) + "\n" )
root.value = bestAttrName
root.childs = [] # Create list of children
if(bestValue < gain_threshold):
Dominantlabel = self.getDominantLabel(sampleIds)
root.value = Dominantlabel
return root
if(len(sampleIds) < minimum_samples):
Dominantlabel = self.getDominantLabel(sampleIds)
root.value = Dominantlabel
return root
for value in self.getAttributeValues(sampleIds, bestAttrId):
# print(value)
child = Node()
child.value = value
root.childs.append(child) # Append new child node to current root
childSampleIds = []
for sid in sampleIds:
if self.sample[sid][bestAttrId] == value:
childSampleIds.append(sid)
if len(childSampleIds) == 0:
child.next = self.getDominantLabel(sampleIds)
else:
# print(bestAttrName, bestAttrId)
# print(attributeIds)
if len(attributeIds) > 0 and bestAttrId in attributeIds:
toRemove = attributeIds.index(bestAttrId)
attributeIds.pop(toRemove)
child.next = self.id3Recv(childSampleIds, attributeIds.copy(), child.next, gain_threshold, minimum_samples)
return root
def print_visualTree(self, render=True):
dot = Digraph(comment='Decision Tree')
if self.root:
self.root.name = "root"
roots = deque()
roots.append(self.root)
counter = 0
while len(roots) > 0:
root = roots.popleft()
# print(root.value)
dot.node(root.name, root.value)
if root.childs:
for child in root.childs:
counter += 1
# print('({})'.format(child.value))
child.name = str(random())
dot.node(child.name, child.value)
dot.edge(root.name,child.name)
if(child.next.childs):
child.next.name = str(random())
dot.node(child.next.name, child.next.value)
dot.edge(child.name,child.next.name)
roots.append(child.next)
else:
child.next.name = str(random())
dot.node(child.next.name, child.next.value)
dot.edge(child.name,child.next.name)
elif root.next:
dot.node(root.next, root.next)
dot.edge(root.value,root.next)
# print(root.next)
# print(dot.source)
if render :
try:
dot.render('output/visualTree.gv', view=True)
except:
print("You either have not installed the 'dot' to visualize the decision tree or the reulted .pdf file is open!")
return dot
| python |
#Roman numerals are: [i v x l c d m]
def stringer (x):
number_string = str(x)
if number_string[0] /= 0:
a = number_string[0];
elif
continue:
if number_string[1] /= 0:
b = number_string[1];
elif
continue:
if number_string[2] /= 0:
c = number_string[2];
elif
continue:
if number_string[3] /= 0:
d = number_string[3];
elif
continue:
a_list = [ "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"]
b_list = [ "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"]
c_list = [ "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"]
d_list = [ "M", "MM", "MMM"]
x = int(input("Your Number(up to 3999): "))
stringer(x)
print (d_list[d-1] + c_list[c-1] + b_list[b-1] + a_list[a-1] )
| python |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Generates a scoring function from worm data that can be fed a time and
distance gap to predict connected worm tracks.
"""
from __future__ import (
absolute_import, division, print_function, unicode_literals)
import six
from six.moves import (zip, filter, map, reduce, input, range)
import numpy as np
import scipy.stats as sps
import scipy.interpolate as spi
#import matplotlib.pyplot as plt
from .core import OneGoodBlobException
KDE_SAMPLES = 1000 #: Default number of samples to take along KDE distribution
class DisplacementScorer(object):
def __init__(self, displacements, *args, **kwargs):
self.kde_fit(displacements, *args, **kwargs)
#self.show()
def kde_fit(self, displacements, bandwidth=None, subsample=None,
samples=KDE_SAMPLES):
# if subsample is None:
# subsample = 1
if displacements.shape[0] == 1:
raise OneGoodBlobException()
#self.distance_domain = 0, np.percentile(displacements[-1], 95)
if isinstance(displacements, np.ma.MaskedArray):
self.distance_domain = 0, displacements.compressed().max()
else:
self.distance_domain = 0, displacements.max()
# -1 on the shape because we're given the useless first frame (all 0's)
self.frame_gap_domain = 1, displacements.shape[1] - 1
distances = np.linspace(*self.distance_domain, num=samples)
frame_gaps = np.arange(self.frame_gap_domain[0],
self.frame_gap_domain[1] + 1, step=subsample)
self.scores = np.empty((frame_gaps.size, distances.size))
#for i, dist in enumerate(displacements.T[1:]):
for i, fgap in enumerate(frame_gaps):
dist = displacements[:,fgap]
if isinstance(dist, np.ma.MaskedArray):
dist = dist.compressed()
self.scores[i] = sps.gaussian_kde(dist, bw_method=bandwidth)(distances)
self.score_interp = spi.RectBivariateSpline(frame_gaps, distances, self.scores)
# def show(self):
# fig, ax = plt.subplots()
# #colormap = plt.cm.gist_ncar
# #ax.set_color_cycle([colormap(i) for i in
# # np.linspace(0, 0.9, len(self.displacements))])
# #for row in self.displacements:
# # plt.plot(row)
# dgap = np.linspace(*self.distance_domain, num=400)
# fgap = np.linspace(*self.frame_gap_domain, num=400)
# #fgap_v, dgap_v = np.meshgrid(fgap, dgap, squeeze=True)
# #import pdb;pdb.set_trace()
# score = self(fgap, dgap)
# ax.imshow(score)
# #print(score)
# #plt.show()
def __call__(self, fgap, dgap):
"""
Interface to the interpolater.
"""
result = self.score_interp(fgap, dgap)
return np.clip(result, 1e-100, 1e100, out=result)
| python |
import unittest
import os
import v1
from fs import TestApi
class V1FormatEntryTest(unittest.TestCase):
def setUp(self):
self.fs = TestApi(cwd = '/a/b/c')
def test_with_absolute_path(self):
entry = v1.format_entry('vdir', '/root/some/path:one/dir', self.fs)
self.assertEqual(entry, ('/root/some/path', 'one/dir'))
def test_with_user_home(self):
entry = v1.format_entry('vdir', '~/my/root:one/dir', self.fs)
self.assertEqual(entry, (f"{self.fs.home}/my/root", 'one/dir'))
def test_with_relative_path(self):
entry = v1.format_entry('vdir', 'd:other', self.fs)
self.assertEqual(entry, ('/a/b/c/vdir/d', 'other'))
def test_with_rewinding_path(self):
entry = v1.format_entry('vdir', '../../and/up/again:other', self.fs)
self.assertEqual(entry, ('/a/b/and/up/again', 'other'))
def test_with_leading_base(self):
entry = v1.format_entry('to/vdir', '../path:target', self.fs)
self.assertEqual(entry, ('/a/b/c/to/path', 'target'))
def test_with_rewinding_base(self):
entry = v1.format_entry('../vdir', '../path:target', self.fs)
self.assertEqual(entry, ('/a/b/path', 'target'))
class V1BuildEntryTest(unittest.TestCase):
def setUp(self):
home = '/home/user'
self.fs = TestApi(home = home, cwd = home)
def test_for_simple_entry(self):
structure = [('/a/b/dir', 'f1')]
v1.build_entries('path/to/vdir', structure, self.fs)
self.assertEqual(
set(self.fs.created_links),
set([('/a/b/dir/f1', 'path/to/vdir/f1')]))
def test_for_not_entry(self):
entries = ['a', 'b', 'not-this', 'c']
self.fs._set_entries('/path', entries)
for e in entries:
self.fs._set_dir(f"/path/{e}")
structure = [('/path', '!not-this')]
v1.build_entries('to/vdir', structure, self.fs)
self.assertEqual(
set(self.fs.created_links),
set([
('/path/a', 'to/vdir/a'),
('/path/b', 'to/vdir/b'),
('/path/c', 'to/vdir/c')
]))
def test_with_structure_to_build(self):
structure = [('/root', 'var/log/syslog')]
v1.build_entries('the/vdir', structure, self.fs)
self.assertEqual(
self.fs.created_dirs,
[
'the/vdir/var',
'the/vdir/var/log'
])
self.assertEqual(
list(self.fs.created_links),
[('/root/var/log/syslog', 'the/vdir/var/log/syslog')])
def test_for_many_entries(self):
entries = ['a', 'not-this', 'b']
self.fs._set_entries('/root', entries)
for e in entries:
self.fs._set_dir(f"/root/{e}")
structure = [
('/a/b/dir', 'f1'),
('/my/home/has/dir', 'f2'),
('/root', '!not-this')
]
v1.build_entries('path/to/vdir', structure, self.fs)
self.assertEqual(
set(self.fs.created_links),
set([
('/a/b/dir/f1', 'path/to/vdir/f1'),
('/my/home/has/dir/f2', 'path/to/vdir/f2'),
('/root/a', 'path/to/vdir/a'),
('/root/b', 'path/to/vdir/b')
]))
def test_with_existing_entry(self):
self.fs._set_file('path/to/vdir/f1')
structure = [('/a/b/dir', 'f1')]
v1.build_entries('path/to/vdir', structure, self.fs)
self.assertEqual(list(self.fs.created_links), [])
class V1Test(unittest.TestCase):
def test_integration(self):
fs = TestApi(home = '/home/charlie', cwd = '/usr')
entries = ['a', 'b', 'not-this']
fs._set_entries('/root', entries)
for e in entries:
fs._set_dir(f"/root/{e}")
for e in ['/home/charlie/dir/f1', '/usr/other/f2', '/root/a', '/root/b']:
fs._set_dir(os.path.dirname(e))
fs._set_dir(e)
structure = [
'~/dir:f1',
'../other:f2',
'/root:!not-this'
]
v1.process_structure('vdir', structure, fs)
self.assertEqual(
set(fs.created_links),
set([
('/home/charlie/dir/f1', 'vdir/f1'),
('/usr/other/f2', 'vdir/f2'),
('/root/a', 'vdir/a'),
('/root/b', 'vdir/b')
]))
if __name__ == '__main__':
unittest.main()
| python |
from __future__ import absolute_import, division, print_function
import datetime
import os
import shutil
class Logger(object):
def __init__(self):
self.file = None
self.buffer = ''
def __del__(self):
if self.file is not None:
self.file.close()
def set_log_file(self, filename):
assert self.file is None
self.file = open(filename, 'wt')
if self.buffer is not None:
self.file.write(self.buffer)
self.buffer = None
def write(self, *args):
now = datetime.datetime.now()
dtstr = now.strftime('%Y-%m-%d %H:%M:%S')
t_msg = '[%s]' % dtstr + ' %s' % ' '.join(map(str, args))
print(t_msg)
if self.file is not None:
self.file.write(t_msg + '\n')
else:
self.buffer += t_msg
def flush(self):
if self.file is not None:
self.file.flush()
logger = Logger()
def safe_rm_mkdir(dir):
if os.path.exists(dir):
shutil.rmtree(dir)
os.mkdir(dir)
def safe_mkdir(dir):
if not os.path.exists(dir):
os.mkdir(dir) | python |
from kivy.uix.button import Button
from streetlite.panel.sequence.sequence import Sequence
class SequenceButton(Button):
def __init__(self, start, end, **kwargs):
super().__init__(**kwargs)
is_default = self.text == "Default"
self.sequence = Sequence(is_default, start, end)
| python |
import quizzer.serializers.assessment_json_serializer as json_serializer
import quizzer.serializers.assessment_xml_serializer as xml_serializer
__author__ = 'David Moreno García'
def serialize_grades(grades, format):
"""
Returns an string with the representation of the grades in the desired format.
:param grades: grades to serialize
:param format: format of the output
:return: an string with the representation in the desired format
"""
if format == 'xml':
result = xml_serializer.serialize_grades(grades)
else:
result = json_serializer.serialize_grades(grades)
return result
def serialize_statistics(statistics, format):
"""
Returns an string with the representation of the statistics in the desired format.
:param statistics: statistics to serialize
:param format: format of the output
:return: an string with the representation in the desired format
"""
if format == 'xml':
result = xml_serializer.serialize_statistics(statistics)
else:
result = json_serializer.serialize_statistics(statistics)
return result | python |
# Generated from sdp.g4 by ANTLR 4.8
# encoding: utf-8
from __future__ import print_function
from antlr4 import *
from io import StringIO
import sys
def serializedATN():
with StringIO() as buf:
buf.write(u"\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2")
buf.write(u"\u0102\u0403\b\1\4\2\t\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6")
buf.write(u"\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13\t\13\4\f\t")
buf.write(u"\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20\4\21\t\21\4")
buf.write(u"\22\t\22\4\23\t\23\4\24\t\24\4\25\t\25\4\26\t\26\4\27")
buf.write(u"\t\27\4\30\t\30\4\31\t\31\4\32\t\32\4\33\t\33\4\34\t")
buf.write(u"\34\4\35\t\35\4\36\t\36\4\37\t\37\4 \t \4!\t!\4\"\t\"")
buf.write(u"\4#\t#\4$\t$\4%\t%\4&\t&\4\'\t\'\4(\t(\4)\t)\4*\t*\4")
buf.write(u"+\t+\4,\t,\4-\t-\4.\t.\4/\t/\4\60\t\60\4\61\t\61\4\62")
buf.write(u"\t\62\4\63\t\63\4\64\t\64\4\65\t\65\4\66\t\66\4\67\t")
buf.write(u"\67\48\t8\49\t9\4:\t:\4;\t;\4<\t<\4=\t=\4>\t>\4?\t?\4")
buf.write(u"@\t@\4A\tA\4B\tB\4C\tC\4D\tD\4E\tE\4F\tF\4G\tG\4H\tH")
buf.write(u"\4I\tI\4J\tJ\4K\tK\4L\tL\4M\tM\4N\tN\4O\tO\4P\tP\4Q\t")
buf.write(u"Q\4R\tR\4S\tS\4T\tT\4U\tU\4V\tV\4W\tW\4X\tX\4Y\tY\4Z")
buf.write(u"\tZ\4[\t[\4\\\t\\\4]\t]\4^\t^\4_\t_\4`\t`\4a\ta\4b\t")
buf.write(u"b\4c\tc\4d\td\4e\te\4f\tf\4g\tg\4h\th\4i\ti\4j\tj\4k")
buf.write(u"\tk\4l\tl\4m\tm\4n\tn\4o\to\4p\tp\4q\tq\4r\tr\4s\ts\4")
buf.write(u"t\tt\4u\tu\4v\tv\4w\tw\4x\tx\4y\ty\4z\tz\4{\t{\4|\t|")
buf.write(u"\4}\t}\4~\t~\4\177\t\177\4\u0080\t\u0080\4\u0081\t\u0081")
buf.write(u"\4\u0082\t\u0082\4\u0083\t\u0083\4\u0084\t\u0084\4\u0085")
buf.write(u"\t\u0085\4\u0086\t\u0086\4\u0087\t\u0087\4\u0088\t\u0088")
buf.write(u"\4\u0089\t\u0089\4\u008a\t\u008a\4\u008b\t\u008b\4\u008c")
buf.write(u"\t\u008c\4\u008d\t\u008d\4\u008e\t\u008e\4\u008f\t\u008f")
buf.write(u"\4\u0090\t\u0090\4\u0091\t\u0091\4\u0092\t\u0092\4\u0093")
buf.write(u"\t\u0093\4\u0094\t\u0094\4\u0095\t\u0095\4\u0096\t\u0096")
buf.write(u"\4\u0097\t\u0097\4\u0098\t\u0098\4\u0099\t\u0099\4\u009a")
buf.write(u"\t\u009a\4\u009b\t\u009b\4\u009c\t\u009c\4\u009d\t\u009d")
buf.write(u"\4\u009e\t\u009e\4\u009f\t\u009f\4\u00a0\t\u00a0\4\u00a1")
buf.write(u"\t\u00a1\4\u00a2\t\u00a2\4\u00a3\t\u00a3\4\u00a4\t\u00a4")
buf.write(u"\4\u00a5\t\u00a5\4\u00a6\t\u00a6\4\u00a7\t\u00a7\4\u00a8")
buf.write(u"\t\u00a8\4\u00a9\t\u00a9\4\u00aa\t\u00aa\4\u00ab\t\u00ab")
buf.write(u"\4\u00ac\t\u00ac\4\u00ad\t\u00ad\4\u00ae\t\u00ae\4\u00af")
buf.write(u"\t\u00af\4\u00b0\t\u00b0\4\u00b1\t\u00b1\4\u00b2\t\u00b2")
buf.write(u"\4\u00b3\t\u00b3\4\u00b4\t\u00b4\4\u00b5\t\u00b5\4\u00b6")
buf.write(u"\t\u00b6\4\u00b7\t\u00b7\4\u00b8\t\u00b8\4\u00b9\t\u00b9")
buf.write(u"\4\u00ba\t\u00ba\4\u00bb\t\u00bb\4\u00bc\t\u00bc\4\u00bd")
buf.write(u"\t\u00bd\4\u00be\t\u00be\4\u00bf\t\u00bf\4\u00c0\t\u00c0")
buf.write(u"\4\u00c1\t\u00c1\4\u00c2\t\u00c2\4\u00c3\t\u00c3\4\u00c4")
buf.write(u"\t\u00c4\4\u00c5\t\u00c5\4\u00c6\t\u00c6\4\u00c7\t\u00c7")
buf.write(u"\4\u00c8\t\u00c8\4\u00c9\t\u00c9\4\u00ca\t\u00ca\4\u00cb")
buf.write(u"\t\u00cb\4\u00cc\t\u00cc\4\u00cd\t\u00cd\4\u00ce\t\u00ce")
buf.write(u"\4\u00cf\t\u00cf\4\u00d0\t\u00d0\4\u00d1\t\u00d1\4\u00d2")
buf.write(u"\t\u00d2\4\u00d3\t\u00d3\4\u00d4\t\u00d4\4\u00d5\t\u00d5")
buf.write(u"\4\u00d6\t\u00d6\4\u00d7\t\u00d7\4\u00d8\t\u00d8\4\u00d9")
buf.write(u"\t\u00d9\4\u00da\t\u00da\4\u00db\t\u00db\4\u00dc\t\u00dc")
buf.write(u"\4\u00dd\t\u00dd\4\u00de\t\u00de\4\u00df\t\u00df\4\u00e0")
buf.write(u"\t\u00e0\4\u00e1\t\u00e1\4\u00e2\t\u00e2\4\u00e3\t\u00e3")
buf.write(u"\4\u00e4\t\u00e4\4\u00e5\t\u00e5\4\u00e6\t\u00e6\4\u00e7")
buf.write(u"\t\u00e7\4\u00e8\t\u00e8\4\u00e9\t\u00e9\4\u00ea\t\u00ea")
buf.write(u"\4\u00eb\t\u00eb\4\u00ec\t\u00ec\4\u00ed\t\u00ed\4\u00ee")
buf.write(u"\t\u00ee\4\u00ef\t\u00ef\4\u00f0\t\u00f0\4\u00f1\t\u00f1")
buf.write(u"\4\u00f2\t\u00f2\4\u00f3\t\u00f3\4\u00f4\t\u00f4\4\u00f5")
buf.write(u"\t\u00f5\4\u00f6\t\u00f6\4\u00f7\t\u00f7\4\u00f8\t\u00f8")
buf.write(u"\4\u00f9\t\u00f9\4\u00fa\t\u00fa\4\u00fb\t\u00fb\4\u00fc")
buf.write(u"\t\u00fc\4\u00fd\t\u00fd\4\u00fe\t\u00fe\4\u00ff\t\u00ff")
buf.write(u"\4\u0100\t\u0100\4\u0101\t\u0101\3\2\3\2\3\3\3\3\3\4")
buf.write(u"\3\4\3\5\3\5\3\6\3\6\3\7\3\7\3\b\3\b\3\t\3\t\3\n\3\n")
buf.write(u"\3\13\3\13\3\f\3\f\3\r\3\r\3\16\3\16\3\17\3\17\3\20\3")
buf.write(u"\20\3\21\3\21\3\22\3\22\3\23\3\23\3\24\3\24\3\25\3\25")
buf.write(u"\3\26\3\26\3\27\3\27\3\30\3\30\3\31\3\31\3\32\3\32\3")
buf.write(u"\33\3\33\3\34\3\34\3\35\3\35\3\36\3\36\3\37\3\37\3 \3")
buf.write(u" \3!\3!\3\"\3\"\3#\3#\3$\3$\3%\3%\3&\3&\3\'\3\'\3(\3")
buf.write(u"(\3)\3)\3*\3*\3+\3+\3,\3,\3-\3-\3.\3.\3/\3/\3\60\3\60")
buf.write(u"\3\61\3\61\3\62\3\62\3\63\3\63\3\64\3\64\3\65\3\65\3")
buf.write(u"\66\3\66\3\67\3\67\38\38\39\39\3:\3:\3;\3;\3<\3<\3=\3")
buf.write(u"=\3>\3>\3?\3?\3@\3@\3A\3A\3B\3B\3C\3C\3D\3D\3E\3E\3F")
buf.write(u"\3F\3G\3G\3H\3H\3I\3I\3J\3J\3K\3K\3L\3L\3M\3M\3N\3N\3")
buf.write(u"O\3O\3P\3P\3Q\3Q\3R\3R\3S\3S\3T\3T\3U\3U\3V\3V\3W\3W")
buf.write(u"\3X\3X\3Y\3Y\3Z\3Z\3[\3[\3\\\3\\\3]\3]\3^\3^\3_\3_\3")
buf.write(u"`\3`\3a\3a\3b\3b\3c\3c\3d\3d\3e\3e\3f\3f\3g\3g\3h\3h")
buf.write(u"\3i\3i\3j\3j\3k\3k\3l\3l\3m\3m\3n\3n\3o\3o\3p\3p\3q\3")
buf.write(u"q\3r\3r\3s\3s\3t\3t\3u\3u\3v\3v\3w\3w\3x\3x\3y\3y\3z")
buf.write(u"\3z\3{\3{\3|\3|\3}\3}\3~\3~\3\177\3\177\3\u0080\3\u0080")
buf.write(u"\3\u0081\3\u0081\3\u0082\3\u0082\3\u0083\3\u0083\3\u0084")
buf.write(u"\3\u0084\3\u0085\3\u0085\3\u0086\3\u0086\3\u0087\3\u0087")
buf.write(u"\3\u0088\3\u0088\3\u0089\3\u0089\3\u008a\3\u008a\3\u008b")
buf.write(u"\3\u008b\3\u008c\3\u008c\3\u008d\3\u008d\3\u008e\3\u008e")
buf.write(u"\3\u008f\3\u008f\3\u0090\3\u0090\3\u0091\3\u0091\3\u0092")
buf.write(u"\3\u0092\3\u0093\3\u0093\3\u0094\3\u0094\3\u0095\3\u0095")
buf.write(u"\3\u0096\3\u0096\3\u0097\3\u0097\3\u0098\3\u0098\3\u0099")
buf.write(u"\3\u0099\3\u009a\3\u009a\3\u009b\3\u009b\3\u009c\3\u009c")
buf.write(u"\3\u009d\3\u009d\3\u009e\3\u009e\3\u009f\3\u009f\3\u00a0")
buf.write(u"\3\u00a0\3\u00a1\3\u00a1\3\u00a2\3\u00a2\3\u00a3\3\u00a3")
buf.write(u"\3\u00a4\3\u00a4\3\u00a5\3\u00a5\3\u00a6\3\u00a6\3\u00a7")
buf.write(u"\3\u00a7\3\u00a8\3\u00a8\3\u00a9\3\u00a9\3\u00aa\3\u00aa")
buf.write(u"\3\u00ab\3\u00ab\3\u00ac\3\u00ac\3\u00ad\3\u00ad\3\u00ae")
buf.write(u"\3\u00ae\3\u00af\3\u00af\3\u00b0\3\u00b0\3\u00b1\3\u00b1")
buf.write(u"\3\u00b2\3\u00b2\3\u00b3\3\u00b3\3\u00b4\3\u00b4\3\u00b5")
buf.write(u"\3\u00b5\3\u00b6\3\u00b6\3\u00b7\3\u00b7\3\u00b8\3\u00b8")
buf.write(u"\3\u00b9\3\u00b9\3\u00ba\3\u00ba\3\u00bb\3\u00bb\3\u00bc")
buf.write(u"\3\u00bc\3\u00bd\3\u00bd\3\u00be\3\u00be\3\u00bf\3\u00bf")
buf.write(u"\3\u00c0\3\u00c0\3\u00c1\3\u00c1\3\u00c2\3\u00c2\3\u00c3")
buf.write(u"\3\u00c3\3\u00c4\3\u00c4\3\u00c5\3\u00c5\3\u00c6\3\u00c6")
buf.write(u"\3\u00c7\3\u00c7\3\u00c8\3\u00c8\3\u00c9\3\u00c9\3\u00ca")
buf.write(u"\3\u00ca\3\u00cb\3\u00cb\3\u00cc\3\u00cc\3\u00cd\3\u00cd")
buf.write(u"\3\u00ce\3\u00ce\3\u00cf\3\u00cf\3\u00d0\3\u00d0\3\u00d1")
buf.write(u"\3\u00d1\3\u00d2\3\u00d2\3\u00d3\3\u00d3\3\u00d4\3\u00d4")
buf.write(u"\3\u00d5\3\u00d5\3\u00d6\3\u00d6\3\u00d7\3\u00d7\3\u00d8")
buf.write(u"\3\u00d8\3\u00d9\3\u00d9\3\u00da\3\u00da\3\u00db\3\u00db")
buf.write(u"\3\u00dc\3\u00dc\3\u00dd\3\u00dd\3\u00de\3\u00de\3\u00df")
buf.write(u"\3\u00df\3\u00e0\3\u00e0\3\u00e1\3\u00e1\3\u00e2\3\u00e2")
buf.write(u"\3\u00e3\3\u00e3\3\u00e4\3\u00e4\3\u00e5\3\u00e5\3\u00e6")
buf.write(u"\3\u00e6\3\u00e7\3\u00e7\3\u00e8\3\u00e8\3\u00e9\3\u00e9")
buf.write(u"\3\u00ea\3\u00ea\3\u00eb\3\u00eb\3\u00ec\3\u00ec\3\u00ed")
buf.write(u"\3\u00ed\3\u00ee\3\u00ee\3\u00ef\3\u00ef\3\u00f0\3\u00f0")
buf.write(u"\3\u00f1\3\u00f1\3\u00f2\3\u00f2\3\u00f3\3\u00f3\3\u00f4")
buf.write(u"\3\u00f4\3\u00f5\3\u00f5\3\u00f6\3\u00f6\3\u00f7\3\u00f7")
buf.write(u"\3\u00f8\3\u00f8\3\u00f9\3\u00f9\3\u00fa\3\u00fa\3\u00fb")
buf.write(u"\3\u00fb\3\u00fc\3\u00fc\3\u00fd\3\u00fd\3\u00fe\3\u00fe")
buf.write(u"\3\u00ff\3\u00ff\3\u0100\3\u0100\3\u0101\3\u0101\2\2")
buf.write(u"\u0102\3\3\5\4\7\5\t\6\13\7\r\b\17\t\21\n\23\13\25\f")
buf.write(u"\27\r\31\16\33\17\35\20\37\21!\22#\23%\24\'\25)\26+\27")
buf.write(u"-\30/\31\61\32\63\33\65\34\67\359\36;\37= ?!A\"C#E$G")
buf.write(u"%I&K\'M(O)Q*S+U,W-Y.[/]\60_\61a\62c\63e\64g\65i\66k\67")
buf.write(u"m8o9q:s;u<w=y>{?}@\177A\u0081B\u0083C\u0085D\u0087E\u0089")
buf.write(u"F\u008bG\u008dH\u008fI\u0091J\u0093K\u0095L\u0097M\u0099")
buf.write(u"N\u009bO\u009dP\u009fQ\u00a1R\u00a3S\u00a5T\u00a7U\u00a9")
buf.write(u"V\u00abW\u00adX\u00afY\u00b1Z\u00b3[\u00b5\\\u00b7]\u00b9")
buf.write(u"^\u00bb_\u00bd`\u00bfa\u00c1b\u00c3c\u00c5d\u00c7e\u00c9")
buf.write(u"f\u00cbg\u00cdh\u00cfi\u00d1j\u00d3k\u00d5l\u00d7m\u00d9")
buf.write(u"n\u00dbo\u00ddp\u00dfq\u00e1r\u00e3s\u00e5t\u00e7u\u00e9")
buf.write(u"v\u00ebw\u00edx\u00efy\u00f1z\u00f3{\u00f5|\u00f7}\u00f9")
buf.write(u"~\u00fb\177\u00fd\u0080\u00ff\u0081\u0101\u0082\u0103")
buf.write(u"\u0083\u0105\u0084\u0107\u0085\u0109\u0086\u010b\u0087")
buf.write(u"\u010d\u0088\u010f\u0089\u0111\u008a\u0113\u008b\u0115")
buf.write(u"\u008c\u0117\u008d\u0119\u008e\u011b\u008f\u011d\u0090")
buf.write(u"\u011f\u0091\u0121\u0092\u0123\u0093\u0125\u0094\u0127")
buf.write(u"\u0095\u0129\u0096\u012b\u0097\u012d\u0098\u012f\u0099")
buf.write(u"\u0131\u009a\u0133\u009b\u0135\u009c\u0137\u009d\u0139")
buf.write(u"\u009e\u013b\u009f\u013d\u00a0\u013f\u00a1\u0141\u00a2")
buf.write(u"\u0143\u00a3\u0145\u00a4\u0147\u00a5\u0149\u00a6\u014b")
buf.write(u"\u00a7\u014d\u00a8\u014f\u00a9\u0151\u00aa\u0153\u00ab")
buf.write(u"\u0155\u00ac\u0157\u00ad\u0159\u00ae\u015b\u00af\u015d")
buf.write(u"\u00b0\u015f\u00b1\u0161\u00b2\u0163\u00b3\u0165\u00b4")
buf.write(u"\u0167\u00b5\u0169\u00b6\u016b\u00b7\u016d\u00b8\u016f")
buf.write(u"\u00b9\u0171\u00ba\u0173\u00bb\u0175\u00bc\u0177\u00bd")
buf.write(u"\u0179\u00be\u017b\u00bf\u017d\u00c0\u017f\u00c1\u0181")
buf.write(u"\u00c2\u0183\u00c3\u0185\u00c4\u0187\u00c5\u0189\u00c6")
buf.write(u"\u018b\u00c7\u018d\u00c8\u018f\u00c9\u0191\u00ca\u0193")
buf.write(u"\u00cb\u0195\u00cc\u0197\u00cd\u0199\u00ce\u019b\u00cf")
buf.write(u"\u019d\u00d0\u019f\u00d1\u01a1\u00d2\u01a3\u00d3\u01a5")
buf.write(u"\u00d4\u01a7\u00d5\u01a9\u00d6\u01ab\u00d7\u01ad\u00d8")
buf.write(u"\u01af\u00d9\u01b1\u00da\u01b3\u00db\u01b5\u00dc\u01b7")
buf.write(u"\u00dd\u01b9\u00de\u01bb\u00df\u01bd\u00e0\u01bf\u00e1")
buf.write(u"\u01c1\u00e2\u01c3\u00e3\u01c5\u00e4\u01c7\u00e5\u01c9")
buf.write(u"\u00e6\u01cb\u00e7\u01cd\u00e8\u01cf\u00e9\u01d1\u00ea")
buf.write(u"\u01d3\u00eb\u01d5\u00ec\u01d7\u00ed\u01d9\u00ee\u01db")
buf.write(u"\u00ef\u01dd\u00f0\u01df\u00f1\u01e1\u00f2\u01e3\u00f3")
buf.write(u"\u01e5\u00f4\u01e7\u00f5\u01e9\u00f6\u01eb\u00f7\u01ed")
buf.write(u"\u00f8\u01ef\u00f9\u01f1\u00fa\u01f3\u00fb\u01f5\u00fc")
buf.write(u"\u01f7\u00fd\u01f9\u00fe\u01fb\u00ff\u01fd\u0100\u01ff")
buf.write(u"\u0101\u0201\u0102\3\2\2\2\u0402\2\3\3\2\2\2\2\5\3\2")
buf.write(u"\2\2\2\7\3\2\2\2\2\t\3\2\2\2\2\13\3\2\2\2\2\r\3\2\2\2")
buf.write(u"\2\17\3\2\2\2\2\21\3\2\2\2\2\23\3\2\2\2\2\25\3\2\2\2")
buf.write(u"\2\27\3\2\2\2\2\31\3\2\2\2\2\33\3\2\2\2\2\35\3\2\2\2")
buf.write(u"\2\37\3\2\2\2\2!\3\2\2\2\2#\3\2\2\2\2%\3\2\2\2\2\'\3")
buf.write(u"\2\2\2\2)\3\2\2\2\2+\3\2\2\2\2-\3\2\2\2\2/\3\2\2\2\2")
buf.write(u"\61\3\2\2\2\2\63\3\2\2\2\2\65\3\2\2\2\2\67\3\2\2\2\2")
buf.write(u"9\3\2\2\2\2;\3\2\2\2\2=\3\2\2\2\2?\3\2\2\2\2A\3\2\2\2")
buf.write(u"\2C\3\2\2\2\2E\3\2\2\2\2G\3\2\2\2\2I\3\2\2\2\2K\3\2\2")
buf.write(u"\2\2M\3\2\2\2\2O\3\2\2\2\2Q\3\2\2\2\2S\3\2\2\2\2U\3\2")
buf.write(u"\2\2\2W\3\2\2\2\2Y\3\2\2\2\2[\3\2\2\2\2]\3\2\2\2\2_\3")
buf.write(u"\2\2\2\2a\3\2\2\2\2c\3\2\2\2\2e\3\2\2\2\2g\3\2\2\2\2")
buf.write(u"i\3\2\2\2\2k\3\2\2\2\2m\3\2\2\2\2o\3\2\2\2\2q\3\2\2\2")
buf.write(u"\2s\3\2\2\2\2u\3\2\2\2\2w\3\2\2\2\2y\3\2\2\2\2{\3\2\2")
buf.write(u"\2\2}\3\2\2\2\2\177\3\2\2\2\2\u0081\3\2\2\2\2\u0083\3")
buf.write(u"\2\2\2\2\u0085\3\2\2\2\2\u0087\3\2\2\2\2\u0089\3\2\2")
buf.write(u"\2\2\u008b\3\2\2\2\2\u008d\3\2\2\2\2\u008f\3\2\2\2\2")
buf.write(u"\u0091\3\2\2\2\2\u0093\3\2\2\2\2\u0095\3\2\2\2\2\u0097")
buf.write(u"\3\2\2\2\2\u0099\3\2\2\2\2\u009b\3\2\2\2\2\u009d\3\2")
buf.write(u"\2\2\2\u009f\3\2\2\2\2\u00a1\3\2\2\2\2\u00a3\3\2\2\2")
buf.write(u"\2\u00a5\3\2\2\2\2\u00a7\3\2\2\2\2\u00a9\3\2\2\2\2\u00ab")
buf.write(u"\3\2\2\2\2\u00ad\3\2\2\2\2\u00af\3\2\2\2\2\u00b1\3\2")
buf.write(u"\2\2\2\u00b3\3\2\2\2\2\u00b5\3\2\2\2\2\u00b7\3\2\2\2")
buf.write(u"\2\u00b9\3\2\2\2\2\u00bb\3\2\2\2\2\u00bd\3\2\2\2\2\u00bf")
buf.write(u"\3\2\2\2\2\u00c1\3\2\2\2\2\u00c3\3\2\2\2\2\u00c5\3\2")
buf.write(u"\2\2\2\u00c7\3\2\2\2\2\u00c9\3\2\2\2\2\u00cb\3\2\2\2")
buf.write(u"\2\u00cd\3\2\2\2\2\u00cf\3\2\2\2\2\u00d1\3\2\2\2\2\u00d3")
buf.write(u"\3\2\2\2\2\u00d5\3\2\2\2\2\u00d7\3\2\2\2\2\u00d9\3\2")
buf.write(u"\2\2\2\u00db\3\2\2\2\2\u00dd\3\2\2\2\2\u00df\3\2\2\2")
buf.write(u"\2\u00e1\3\2\2\2\2\u00e3\3\2\2\2\2\u00e5\3\2\2\2\2\u00e7")
buf.write(u"\3\2\2\2\2\u00e9\3\2\2\2\2\u00eb\3\2\2\2\2\u00ed\3\2")
buf.write(u"\2\2\2\u00ef\3\2\2\2\2\u00f1\3\2\2\2\2\u00f3\3\2\2\2")
buf.write(u"\2\u00f5\3\2\2\2\2\u00f7\3\2\2\2\2\u00f9\3\2\2\2\2\u00fb")
buf.write(u"\3\2\2\2\2\u00fd\3\2\2\2\2\u00ff\3\2\2\2\2\u0101\3\2")
buf.write(u"\2\2\2\u0103\3\2\2\2\2\u0105\3\2\2\2\2\u0107\3\2\2\2")
buf.write(u"\2\u0109\3\2\2\2\2\u010b\3\2\2\2\2\u010d\3\2\2\2\2\u010f")
buf.write(u"\3\2\2\2\2\u0111\3\2\2\2\2\u0113\3\2\2\2\2\u0115\3\2")
buf.write(u"\2\2\2\u0117\3\2\2\2\2\u0119\3\2\2\2\2\u011b\3\2\2\2")
buf.write(u"\2\u011d\3\2\2\2\2\u011f\3\2\2\2\2\u0121\3\2\2\2\2\u0123")
buf.write(u"\3\2\2\2\2\u0125\3\2\2\2\2\u0127\3\2\2\2\2\u0129\3\2")
buf.write(u"\2\2\2\u012b\3\2\2\2\2\u012d\3\2\2\2\2\u012f\3\2\2\2")
buf.write(u"\2\u0131\3\2\2\2\2\u0133\3\2\2\2\2\u0135\3\2\2\2\2\u0137")
buf.write(u"\3\2\2\2\2\u0139\3\2\2\2\2\u013b\3\2\2\2\2\u013d\3\2")
buf.write(u"\2\2\2\u013f\3\2\2\2\2\u0141\3\2\2\2\2\u0143\3\2\2\2")
buf.write(u"\2\u0145\3\2\2\2\2\u0147\3\2\2\2\2\u0149\3\2\2\2\2\u014b")
buf.write(u"\3\2\2\2\2\u014d\3\2\2\2\2\u014f\3\2\2\2\2\u0151\3\2")
buf.write(u"\2\2\2\u0153\3\2\2\2\2\u0155\3\2\2\2\2\u0157\3\2\2\2")
buf.write(u"\2\u0159\3\2\2\2\2\u015b\3\2\2\2\2\u015d\3\2\2\2\2\u015f")
buf.write(u"\3\2\2\2\2\u0161\3\2\2\2\2\u0163\3\2\2\2\2\u0165\3\2")
buf.write(u"\2\2\2\u0167\3\2\2\2\2\u0169\3\2\2\2\2\u016b\3\2\2\2")
buf.write(u"\2\u016d\3\2\2\2\2\u016f\3\2\2\2\2\u0171\3\2\2\2\2\u0173")
buf.write(u"\3\2\2\2\2\u0175\3\2\2\2\2\u0177\3\2\2\2\2\u0179\3\2")
buf.write(u"\2\2\2\u017b\3\2\2\2\2\u017d\3\2\2\2\2\u017f\3\2\2\2")
buf.write(u"\2\u0181\3\2\2\2\2\u0183\3\2\2\2\2\u0185\3\2\2\2\2\u0187")
buf.write(u"\3\2\2\2\2\u0189\3\2\2\2\2\u018b\3\2\2\2\2\u018d\3\2")
buf.write(u"\2\2\2\u018f\3\2\2\2\2\u0191\3\2\2\2\2\u0193\3\2\2\2")
buf.write(u"\2\u0195\3\2\2\2\2\u0197\3\2\2\2\2\u0199\3\2\2\2\2\u019b")
buf.write(u"\3\2\2\2\2\u019d\3\2\2\2\2\u019f\3\2\2\2\2\u01a1\3\2")
buf.write(u"\2\2\2\u01a3\3\2\2\2\2\u01a5\3\2\2\2\2\u01a7\3\2\2\2")
buf.write(u"\2\u01a9\3\2\2\2\2\u01ab\3\2\2\2\2\u01ad\3\2\2\2\2\u01af")
buf.write(u"\3\2\2\2\2\u01b1\3\2\2\2\2\u01b3\3\2\2\2\2\u01b5\3\2")
buf.write(u"\2\2\2\u01b7\3\2\2\2\2\u01b9\3\2\2\2\2\u01bb\3\2\2\2")
buf.write(u"\2\u01bd\3\2\2\2\2\u01bf\3\2\2\2\2\u01c1\3\2\2\2\2\u01c3")
buf.write(u"\3\2\2\2\2\u01c5\3\2\2\2\2\u01c7\3\2\2\2\2\u01c9\3\2")
buf.write(u"\2\2\2\u01cb\3\2\2\2\2\u01cd\3\2\2\2\2\u01cf\3\2\2\2")
buf.write(u"\2\u01d1\3\2\2\2\2\u01d3\3\2\2\2\2\u01d5\3\2\2\2\2\u01d7")
buf.write(u"\3\2\2\2\2\u01d9\3\2\2\2\2\u01db\3\2\2\2\2\u01dd\3\2")
buf.write(u"\2\2\2\u01df\3\2\2\2\2\u01e1\3\2\2\2\2\u01e3\3\2\2\2")
buf.write(u"\2\u01e5\3\2\2\2\2\u01e7\3\2\2\2\2\u01e9\3\2\2\2\2\u01eb")
buf.write(u"\3\2\2\2\2\u01ed\3\2\2\2\2\u01ef\3\2\2\2\2\u01f1\3\2")
buf.write(u"\2\2\2\u01f3\3\2\2\2\2\u01f5\3\2\2\2\2\u01f7\3\2\2\2")
buf.write(u"\2\u01f9\3\2\2\2\2\u01fb\3\2\2\2\2\u01fd\3\2\2\2\2\u01ff")
buf.write(u"\3\2\2\2\2\u0201\3\2\2\2\3\u0203\3\2\2\2\5\u0205\3\2")
buf.write(u"\2\2\7\u0207\3\2\2\2\t\u0209\3\2\2\2\13\u020b\3\2\2\2")
buf.write(u"\r\u020d\3\2\2\2\17\u020f\3\2\2\2\21\u0211\3\2\2\2\23")
buf.write(u"\u0213\3\2\2\2\25\u0215\3\2\2\2\27\u0217\3\2\2\2\31\u0219")
buf.write(u"\3\2\2\2\33\u021b\3\2\2\2\35\u021d\3\2\2\2\37\u021f\3")
buf.write(u"\2\2\2!\u0221\3\2\2\2#\u0223\3\2\2\2%\u0225\3\2\2\2\'")
buf.write(u"\u0227\3\2\2\2)\u0229\3\2\2\2+\u022b\3\2\2\2-\u022d\3")
buf.write(u"\2\2\2/\u022f\3\2\2\2\61\u0231\3\2\2\2\63\u0233\3\2\2")
buf.write(u"\2\65\u0235\3\2\2\2\67\u0237\3\2\2\29\u0239\3\2\2\2;")
buf.write(u"\u023b\3\2\2\2=\u023d\3\2\2\2?\u023f\3\2\2\2A\u0241\3")
buf.write(u"\2\2\2C\u0243\3\2\2\2E\u0245\3\2\2\2G\u0247\3\2\2\2I")
buf.write(u"\u0249\3\2\2\2K\u024b\3\2\2\2M\u024d\3\2\2\2O\u024f\3")
buf.write(u"\2\2\2Q\u0251\3\2\2\2S\u0253\3\2\2\2U\u0255\3\2\2\2W")
buf.write(u"\u0257\3\2\2\2Y\u0259\3\2\2\2[\u025b\3\2\2\2]\u025d\3")
buf.write(u"\2\2\2_\u025f\3\2\2\2a\u0261\3\2\2\2c\u0263\3\2\2\2e")
buf.write(u"\u0265\3\2\2\2g\u0267\3\2\2\2i\u0269\3\2\2\2k\u026b\3")
buf.write(u"\2\2\2m\u026d\3\2\2\2o\u026f\3\2\2\2q\u0271\3\2\2\2s")
buf.write(u"\u0273\3\2\2\2u\u0275\3\2\2\2w\u0277\3\2\2\2y\u0279\3")
buf.write(u"\2\2\2{\u027b\3\2\2\2}\u027d\3\2\2\2\177\u027f\3\2\2")
buf.write(u"\2\u0081\u0281\3\2\2\2\u0083\u0283\3\2\2\2\u0085\u0285")
buf.write(u"\3\2\2\2\u0087\u0287\3\2\2\2\u0089\u0289\3\2\2\2\u008b")
buf.write(u"\u028b\3\2\2\2\u008d\u028d\3\2\2\2\u008f\u028f\3\2\2")
buf.write(u"\2\u0091\u0291\3\2\2\2\u0093\u0293\3\2\2\2\u0095\u0295")
buf.write(u"\3\2\2\2\u0097\u0297\3\2\2\2\u0099\u0299\3\2\2\2\u009b")
buf.write(u"\u029b\3\2\2\2\u009d\u029d\3\2\2\2\u009f\u029f\3\2\2")
buf.write(u"\2\u00a1\u02a1\3\2\2\2\u00a3\u02a3\3\2\2\2\u00a5\u02a5")
buf.write(u"\3\2\2\2\u00a7\u02a7\3\2\2\2\u00a9\u02a9\3\2\2\2\u00ab")
buf.write(u"\u02ab\3\2\2\2\u00ad\u02ad\3\2\2\2\u00af\u02af\3\2\2")
buf.write(u"\2\u00b1\u02b1\3\2\2\2\u00b3\u02b3\3\2\2\2\u00b5\u02b5")
buf.write(u"\3\2\2\2\u00b7\u02b7\3\2\2\2\u00b9\u02b9\3\2\2\2\u00bb")
buf.write(u"\u02bb\3\2\2\2\u00bd\u02bd\3\2\2\2\u00bf\u02bf\3\2\2")
buf.write(u"\2\u00c1\u02c1\3\2\2\2\u00c3\u02c3\3\2\2\2\u00c5\u02c5")
buf.write(u"\3\2\2\2\u00c7\u02c7\3\2\2\2\u00c9\u02c9\3\2\2\2\u00cb")
buf.write(u"\u02cb\3\2\2\2\u00cd\u02cd\3\2\2\2\u00cf\u02cf\3\2\2")
buf.write(u"\2\u00d1\u02d1\3\2\2\2\u00d3\u02d3\3\2\2\2\u00d5\u02d5")
buf.write(u"\3\2\2\2\u00d7\u02d7\3\2\2\2\u00d9\u02d9\3\2\2\2\u00db")
buf.write(u"\u02db\3\2\2\2\u00dd\u02dd\3\2\2\2\u00df\u02df\3\2\2")
buf.write(u"\2\u00e1\u02e1\3\2\2\2\u00e3\u02e3\3\2\2\2\u00e5\u02e5")
buf.write(u"\3\2\2\2\u00e7\u02e7\3\2\2\2\u00e9\u02e9\3\2\2\2\u00eb")
buf.write(u"\u02eb\3\2\2\2\u00ed\u02ed\3\2\2\2\u00ef\u02ef\3\2\2")
buf.write(u"\2\u00f1\u02f1\3\2\2\2\u00f3\u02f3\3\2\2\2\u00f5\u02f5")
buf.write(u"\3\2\2\2\u00f7\u02f7\3\2\2\2\u00f9\u02f9\3\2\2\2\u00fb")
buf.write(u"\u02fb\3\2\2\2\u00fd\u02fd\3\2\2\2\u00ff\u02ff\3\2\2")
buf.write(u"\2\u0101\u0301\3\2\2\2\u0103\u0303\3\2\2\2\u0105\u0305")
buf.write(u"\3\2\2\2\u0107\u0307\3\2\2\2\u0109\u0309\3\2\2\2\u010b")
buf.write(u"\u030b\3\2\2\2\u010d\u030d\3\2\2\2\u010f\u030f\3\2\2")
buf.write(u"\2\u0111\u0311\3\2\2\2\u0113\u0313\3\2\2\2\u0115\u0315")
buf.write(u"\3\2\2\2\u0117\u0317\3\2\2\2\u0119\u0319\3\2\2\2\u011b")
buf.write(u"\u031b\3\2\2\2\u011d\u031d\3\2\2\2\u011f\u031f\3\2\2")
buf.write(u"\2\u0121\u0321\3\2\2\2\u0123\u0323\3\2\2\2\u0125\u0325")
buf.write(u"\3\2\2\2\u0127\u0327\3\2\2\2\u0129\u0329\3\2\2\2\u012b")
buf.write(u"\u032b\3\2\2\2\u012d\u032d\3\2\2\2\u012f\u032f\3\2\2")
buf.write(u"\2\u0131\u0331\3\2\2\2\u0133\u0333\3\2\2\2\u0135\u0335")
buf.write(u"\3\2\2\2\u0137\u0337\3\2\2\2\u0139\u0339\3\2\2\2\u013b")
buf.write(u"\u033b\3\2\2\2\u013d\u033d\3\2\2\2\u013f\u033f\3\2\2")
buf.write(u"\2\u0141\u0341\3\2\2\2\u0143\u0343\3\2\2\2\u0145\u0345")
buf.write(u"\3\2\2\2\u0147\u0347\3\2\2\2\u0149\u0349\3\2\2\2\u014b")
buf.write(u"\u034b\3\2\2\2\u014d\u034d\3\2\2\2\u014f\u034f\3\2\2")
buf.write(u"\2\u0151\u0351\3\2\2\2\u0153\u0353\3\2\2\2\u0155\u0355")
buf.write(u"\3\2\2\2\u0157\u0357\3\2\2\2\u0159\u0359\3\2\2\2\u015b")
buf.write(u"\u035b\3\2\2\2\u015d\u035d\3\2\2\2\u015f\u035f\3\2\2")
buf.write(u"\2\u0161\u0361\3\2\2\2\u0163\u0363\3\2\2\2\u0165\u0365")
buf.write(u"\3\2\2\2\u0167\u0367\3\2\2\2\u0169\u0369\3\2\2\2\u016b")
buf.write(u"\u036b\3\2\2\2\u016d\u036d\3\2\2\2\u016f\u036f\3\2\2")
buf.write(u"\2\u0171\u0371\3\2\2\2\u0173\u0373\3\2\2\2\u0175\u0375")
buf.write(u"\3\2\2\2\u0177\u0377\3\2\2\2\u0179\u0379\3\2\2\2\u017b")
buf.write(u"\u037b\3\2\2\2\u017d\u037d\3\2\2\2\u017f\u037f\3\2\2")
buf.write(u"\2\u0181\u0381\3\2\2\2\u0183\u0383\3\2\2\2\u0185\u0385")
buf.write(u"\3\2\2\2\u0187\u0387\3\2\2\2\u0189\u0389\3\2\2\2\u018b")
buf.write(u"\u038b\3\2\2\2\u018d\u038d\3\2\2\2\u018f\u038f\3\2\2")
buf.write(u"\2\u0191\u0391\3\2\2\2\u0193\u0393\3\2\2\2\u0195\u0395")
buf.write(u"\3\2\2\2\u0197\u0397\3\2\2\2\u0199\u0399\3\2\2\2\u019b")
buf.write(u"\u039b\3\2\2\2\u019d\u039d\3\2\2\2\u019f\u039f\3\2\2")
buf.write(u"\2\u01a1\u03a1\3\2\2\2\u01a3\u03a3\3\2\2\2\u01a5\u03a5")
buf.write(u"\3\2\2\2\u01a7\u03a7\3\2\2\2\u01a9\u03a9\3\2\2\2\u01ab")
buf.write(u"\u03ab\3\2\2\2\u01ad\u03ad\3\2\2\2\u01af\u03af\3\2\2")
buf.write(u"\2\u01b1\u03b1\3\2\2\2\u01b3\u03b3\3\2\2\2\u01b5\u03b5")
buf.write(u"\3\2\2\2\u01b7\u03b7\3\2\2\2\u01b9\u03b9\3\2\2\2\u01bb")
buf.write(u"\u03bb\3\2\2\2\u01bd\u03bd\3\2\2\2\u01bf\u03bf\3\2\2")
buf.write(u"\2\u01c1\u03c1\3\2\2\2\u01c3\u03c3\3\2\2\2\u01c5\u03c5")
buf.write(u"\3\2\2\2\u01c7\u03c7\3\2\2\2\u01c9\u03c9\3\2\2\2\u01cb")
buf.write(u"\u03cb\3\2\2\2\u01cd\u03cd\3\2\2\2\u01cf\u03cf\3\2\2")
buf.write(u"\2\u01d1\u03d1\3\2\2\2\u01d3\u03d3\3\2\2\2\u01d5\u03d5")
buf.write(u"\3\2\2\2\u01d7\u03d7\3\2\2\2\u01d9\u03d9\3\2\2\2\u01db")
buf.write(u"\u03db\3\2\2\2\u01dd\u03dd\3\2\2\2\u01df\u03df\3\2\2")
buf.write(u"\2\u01e1\u03e1\3\2\2\2\u01e3\u03e3\3\2\2\2\u01e5\u03e5")
buf.write(u"\3\2\2\2\u01e7\u03e7\3\2\2\2\u01e9\u03e9\3\2\2\2\u01eb")
buf.write(u"\u03eb\3\2\2\2\u01ed\u03ed\3\2\2\2\u01ef\u03ef\3\2\2")
buf.write(u"\2\u01f1\u03f1\3\2\2\2\u01f3\u03f3\3\2\2\2\u01f5\u03f5")
buf.write(u"\3\2\2\2\u01f7\u03f7\3\2\2\2\u01f9\u03f9\3\2\2\2\u01fb")
buf.write(u"\u03fb\3\2\2\2\u01fd\u03fd\3\2\2\2\u01ff\u03ff\3\2\2")
buf.write(u"\2\u0201\u0401\3\2\2\2\u0203\u0204\7\13\2\2\u0204\4\3")
buf.write(u"\2\2\2\u0205\u0206\7\f\2\2\u0206\6\3\2\2\2\u0207\u0208")
buf.write(u"\7\17\2\2\u0208\b\3\2\2\2\u0209\u020a\7\"\2\2\u020a\n")
buf.write(u"\3\2\2\2\u020b\u020c\7#\2\2\u020c\f\3\2\2\2\u020d\u020e")
buf.write(u"\7$\2\2\u020e\16\3\2\2\2\u020f\u0210\7%\2\2\u0210\20")
buf.write(u"\3\2\2\2\u0211\u0212\7&\2\2\u0212\22\3\2\2\2\u0213\u0214")
buf.write(u"\7\'\2\2\u0214\24\3\2\2\2\u0215\u0216\7(\2\2\u0216\26")
buf.write(u"\3\2\2\2\u0217\u0218\7)\2\2\u0218\30\3\2\2\2\u0219\u021a")
buf.write(u"\7*\2\2\u021a\32\3\2\2\2\u021b\u021c\7+\2\2\u021c\34")
buf.write(u"\3\2\2\2\u021d\u021e\7,\2\2\u021e\36\3\2\2\2\u021f\u0220")
buf.write(u"\7-\2\2\u0220 \3\2\2\2\u0221\u0222\7.\2\2\u0222\"\3\2")
buf.write(u"\2\2\u0223\u0224\7/\2\2\u0224$\3\2\2\2\u0225\u0226\7")
buf.write(u"\60\2\2\u0226&\3\2\2\2\u0227\u0228\7\61\2\2\u0228(\3")
buf.write(u"\2\2\2\u0229\u022a\7\62\2\2\u022a*\3\2\2\2\u022b\u022c")
buf.write(u"\7\63\2\2\u022c,\3\2\2\2\u022d\u022e\7\64\2\2\u022e.")
buf.write(u"\3\2\2\2\u022f\u0230\7\65\2\2\u0230\60\3\2\2\2\u0231")
buf.write(u"\u0232\7\66\2\2\u0232\62\3\2\2\2\u0233\u0234\7\67\2\2")
buf.write(u"\u0234\64\3\2\2\2\u0235\u0236\78\2\2\u0236\66\3\2\2\2")
buf.write(u"\u0237\u0238\79\2\2\u02388\3\2\2\2\u0239\u023a\7:\2\2")
buf.write(u"\u023a:\3\2\2\2\u023b\u023c\7;\2\2\u023c<\3\2\2\2\u023d")
buf.write(u"\u023e\7<\2\2\u023e>\3\2\2\2\u023f\u0240\7=\2\2\u0240")
buf.write(u"@\3\2\2\2\u0241\u0242\7>\2\2\u0242B\3\2\2\2\u0243\u0244")
buf.write(u"\7?\2\2\u0244D\3\2\2\2\u0245\u0246\7@\2\2\u0246F\3\2")
buf.write(u"\2\2\u0247\u0248\7A\2\2\u0248H\3\2\2\2\u0249\u024a\7")
buf.write(u"B\2\2\u024aJ\3\2\2\2\u024b\u024c\7C\2\2\u024cL\3\2\2")
buf.write(u"\2\u024d\u024e\7D\2\2\u024eN\3\2\2\2\u024f\u0250\7E\2")
buf.write(u"\2\u0250P\3\2\2\2\u0251\u0252\7F\2\2\u0252R\3\2\2\2\u0253")
buf.write(u"\u0254\7G\2\2\u0254T\3\2\2\2\u0255\u0256\7H\2\2\u0256")
buf.write(u"V\3\2\2\2\u0257\u0258\7I\2\2\u0258X\3\2\2\2\u0259\u025a")
buf.write(u"\7J\2\2\u025aZ\3\2\2\2\u025b\u025c\7K\2\2\u025c\\\3\2")
buf.write(u"\2\2\u025d\u025e\7L\2\2\u025e^\3\2\2\2\u025f\u0260\7")
buf.write(u"M\2\2\u0260`\3\2\2\2\u0261\u0262\7N\2\2\u0262b\3\2\2")
buf.write(u"\2\u0263\u0264\7O\2\2\u0264d\3\2\2\2\u0265\u0266\7P\2")
buf.write(u"\2\u0266f\3\2\2\2\u0267\u0268\7Q\2\2\u0268h\3\2\2\2\u0269")
buf.write(u"\u026a\7R\2\2\u026aj\3\2\2\2\u026b\u026c\7S\2\2\u026c")
buf.write(u"l\3\2\2\2\u026d\u026e\7T\2\2\u026en\3\2\2\2\u026f\u0270")
buf.write(u"\7U\2\2\u0270p\3\2\2\2\u0271\u0272\7V\2\2\u0272r\3\2")
buf.write(u"\2\2\u0273\u0274\7W\2\2\u0274t\3\2\2\2\u0275\u0276\7")
buf.write(u"X\2\2\u0276v\3\2\2\2\u0277\u0278\7Y\2\2\u0278x\3\2\2")
buf.write(u"\2\u0279\u027a\7Z\2\2\u027az\3\2\2\2\u027b\u027c\7[\2")
buf.write(u"\2\u027c|\3\2\2\2\u027d\u027e\7\\\2\2\u027e~\3\2\2\2")
buf.write(u"\u027f\u0280\7]\2\2\u0280\u0080\3\2\2\2\u0281\u0282\7")
buf.write(u"^\2\2\u0282\u0082\3\2\2\2\u0283\u0284\7_\2\2\u0284\u0084")
buf.write(u"\3\2\2\2\u0285\u0286\7`\2\2\u0286\u0086\3\2\2\2\u0287")
buf.write(u"\u0288\7a\2\2\u0288\u0088\3\2\2\2\u0289\u028a\7b\2\2")
buf.write(u"\u028a\u008a\3\2\2\2\u028b\u028c\7c\2\2\u028c\u008c\3")
buf.write(u"\2\2\2\u028d\u028e\7d\2\2\u028e\u008e\3\2\2\2\u028f\u0290")
buf.write(u"\7e\2\2\u0290\u0090\3\2\2\2\u0291\u0292\7f\2\2\u0292")
buf.write(u"\u0092\3\2\2\2\u0293\u0294\7g\2\2\u0294\u0094\3\2\2\2")
buf.write(u"\u0295\u0296\7h\2\2\u0296\u0096\3\2\2\2\u0297\u0298\7")
buf.write(u"i\2\2\u0298\u0098\3\2\2\2\u0299\u029a\7j\2\2\u029a\u009a")
buf.write(u"\3\2\2\2\u029b\u029c\7k\2\2\u029c\u009c\3\2\2\2\u029d")
buf.write(u"\u029e\7l\2\2\u029e\u009e\3\2\2\2\u029f\u02a0\7m\2\2")
buf.write(u"\u02a0\u00a0\3\2\2\2\u02a1\u02a2\7n\2\2\u02a2\u00a2\3")
buf.write(u"\2\2\2\u02a3\u02a4\7o\2\2\u02a4\u00a4\3\2\2\2\u02a5\u02a6")
buf.write(u"\7p\2\2\u02a6\u00a6\3\2\2\2\u02a7\u02a8\7q\2\2\u02a8")
buf.write(u"\u00a8\3\2\2\2\u02a9\u02aa\7r\2\2\u02aa\u00aa\3\2\2\2")
buf.write(u"\u02ab\u02ac\7s\2\2\u02ac\u00ac\3\2\2\2\u02ad\u02ae\7")
buf.write(u"t\2\2\u02ae\u00ae\3\2\2\2\u02af\u02b0\7u\2\2\u02b0\u00b0")
buf.write(u"\3\2\2\2\u02b1\u02b2\7v\2\2\u02b2\u00b2\3\2\2\2\u02b3")
buf.write(u"\u02b4\7w\2\2\u02b4\u00b4\3\2\2\2\u02b5\u02b6\7x\2\2")
buf.write(u"\u02b6\u00b6\3\2\2\2\u02b7\u02b8\7y\2\2\u02b8\u00b8\3")
buf.write(u"\2\2\2\u02b9\u02ba\7z\2\2\u02ba\u00ba\3\2\2\2\u02bb\u02bc")
buf.write(u"\7{\2\2\u02bc\u00bc\3\2\2\2\u02bd\u02be\7|\2\2\u02be")
buf.write(u"\u00be\3\2\2\2\u02bf\u02c0\7}\2\2\u02c0\u00c0\3\2\2\2")
buf.write(u"\u02c1\u02c2\7~\2\2\u02c2\u00c2\3\2\2\2\u02c3\u02c4\7")
buf.write(u"\177\2\2\u02c4\u00c4\3\2\2\2\u02c5\u02c6\7\u0080\2\2")
buf.write(u"\u02c6\u00c6\3\2\2\2\u02c7\u02c8\7\2\2\2\u02c8\u00c8")
buf.write(u"\3\2\2\2\u02c9\u02ca\7\3\2\2\u02ca\u00ca\3\2\2\2\u02cb")
buf.write(u"\u02cc\7\4\2\2\u02cc\u00cc\3\2\2\2\u02cd\u02ce\7\5\2")
buf.write(u"\2\u02ce\u00ce\3\2\2\2\u02cf\u02d0\7\6\2\2\u02d0\u00d0")
buf.write(u"\3\2\2\2\u02d1\u02d2\7\7\2\2\u02d2\u00d2\3\2\2\2\u02d3")
buf.write(u"\u02d4\7\b\2\2\u02d4\u00d4\3\2\2\2\u02d5\u02d6\7\t\2")
buf.write(u"\2\u02d6\u00d6\3\2\2\2\u02d7\u02d8\7\n\2\2\u02d8\u00d8")
buf.write(u"\3\2\2\2\u02d9\u02da\7\r\2\2\u02da\u00da\3\2\2\2\u02db")
buf.write(u"\u02dc\7\16\2\2\u02dc\u00dc\3\2\2\2\u02dd\u02de\7\20")
buf.write(u"\2\2\u02de\u00de\3\2\2\2\u02df\u02e0\7\21\2\2\u02e0\u00e0")
buf.write(u"\3\2\2\2\u02e1\u02e2\7\22\2\2\u02e2\u00e2\3\2\2\2\u02e3")
buf.write(u"\u02e4\7\23\2\2\u02e4\u00e4\3\2\2\2\u02e5\u02e6\7\24")
buf.write(u"\2\2\u02e6\u00e6\3\2\2\2\u02e7\u02e8\7\25\2\2\u02e8\u00e8")
buf.write(u"\3\2\2\2\u02e9\u02ea\7\26\2\2\u02ea\u00ea\3\2\2\2\u02eb")
buf.write(u"\u02ec\7\27\2\2\u02ec\u00ec\3\2\2\2\u02ed\u02ee\7\30")
buf.write(u"\2\2\u02ee\u00ee\3\2\2\2\u02ef\u02f0\7\31\2\2\u02f0\u00f0")
buf.write(u"\3\2\2\2\u02f1\u02f2\7\32\2\2\u02f2\u00f2\3\2\2\2\u02f3")
buf.write(u"\u02f4\7\33\2\2\u02f4\u00f4\3\2\2\2\u02f5\u02f6\7\34")
buf.write(u"\2\2\u02f6\u00f6\3\2\2\2\u02f7\u02f8\7\35\2\2\u02f8\u00f8")
buf.write(u"\3\2\2\2\u02f9\u02fa\7\36\2\2\u02fa\u00fa\3\2\2\2\u02fb")
buf.write(u"\u02fc\7\37\2\2\u02fc\u00fc\3\2\2\2\u02fd\u02fe\7 \2")
buf.write(u"\2\u02fe\u00fe\3\2\2\2\u02ff\u0300\7!\2\2\u0300\u0100")
buf.write(u"\3\2\2\2\u0301\u0302\7\u0081\2\2\u0302\u0102\3\2\2\2")
buf.write(u"\u0303\u0304\7\u0082\2\2\u0304\u0104\3\2\2\2\u0305\u0306")
buf.write(u"\7\u0083\2\2\u0306\u0106\3\2\2\2\u0307\u0308\7\u0084")
buf.write(u"\2\2\u0308\u0108\3\2\2\2\u0309\u030a\7\u0085\2\2\u030a")
buf.write(u"\u010a\3\2\2\2\u030b\u030c\7\u0086\2\2\u030c\u010c\3")
buf.write(u"\2\2\2\u030d\u030e\7\u0087\2\2\u030e\u010e\3\2\2\2\u030f")
buf.write(u"\u0310\7\u0088\2\2\u0310\u0110\3\2\2\2\u0311\u0312\7")
buf.write(u"\u0089\2\2\u0312\u0112\3\2\2\2\u0313\u0314\7\u008a\2")
buf.write(u"\2\u0314\u0114\3\2\2\2\u0315\u0316\7\u008b\2\2\u0316")
buf.write(u"\u0116\3\2\2\2\u0317\u0318\7\u008c\2\2\u0318\u0118\3")
buf.write(u"\2\2\2\u0319\u031a\7\u008d\2\2\u031a\u011a\3\2\2\2\u031b")
buf.write(u"\u031c\7\u008e\2\2\u031c\u011c\3\2\2\2\u031d\u031e\7")
buf.write(u"\u008f\2\2\u031e\u011e\3\2\2\2\u031f\u0320\7\u0090\2")
buf.write(u"\2\u0320\u0120\3\2\2\2\u0321\u0322\7\u0091\2\2\u0322")
buf.write(u"\u0122\3\2\2\2\u0323\u0324\7\u0092\2\2\u0324\u0124\3")
buf.write(u"\2\2\2\u0325\u0326\7\u0093\2\2\u0326\u0126\3\2\2\2\u0327")
buf.write(u"\u0328\7\u0094\2\2\u0328\u0128\3\2\2\2\u0329\u032a\7")
buf.write(u"\u0095\2\2\u032a\u012a\3\2\2\2\u032b\u032c\7\u0096\2")
buf.write(u"\2\u032c\u012c\3\2\2\2\u032d\u032e\7\u0097\2\2\u032e")
buf.write(u"\u012e\3\2\2\2\u032f\u0330\7\u0098\2\2\u0330\u0130\3")
buf.write(u"\2\2\2\u0331\u0332\7\u0099\2\2\u0332\u0132\3\2\2\2\u0333")
buf.write(u"\u0334\7\u009a\2\2\u0334\u0134\3\2\2\2\u0335\u0336\7")
buf.write(u"\u009b\2\2\u0336\u0136\3\2\2\2\u0337\u0338\7\u009c\2")
buf.write(u"\2\u0338\u0138\3\2\2\2\u0339\u033a\7\u009d\2\2\u033a")
buf.write(u"\u013a\3\2\2\2\u033b\u033c\7\u009e\2\2\u033c\u013c\3")
buf.write(u"\2\2\2\u033d\u033e\7\u009f\2\2\u033e\u013e\3\2\2\2\u033f")
buf.write(u"\u0340\7\u00a0\2\2\u0340\u0140\3\2\2\2\u0341\u0342\7")
buf.write(u"\u00a1\2\2\u0342\u0142\3\2\2\2\u0343\u0344\7\u00a2\2")
buf.write(u"\2\u0344\u0144\3\2\2\2\u0345\u0346\7\u00a3\2\2\u0346")
buf.write(u"\u0146\3\2\2\2\u0347\u0348\7\u00a4\2\2\u0348\u0148\3")
buf.write(u"\2\2\2\u0349\u034a\7\u00a5\2\2\u034a\u014a\3\2\2\2\u034b")
buf.write(u"\u034c\7\u00a6\2\2\u034c\u014c\3\2\2\2\u034d\u034e\7")
buf.write(u"\u00a7\2\2\u034e\u014e\3\2\2\2\u034f\u0350\7\u00a8\2")
buf.write(u"\2\u0350\u0150\3\2\2\2\u0351\u0352\7\u00a9\2\2\u0352")
buf.write(u"\u0152\3\2\2\2\u0353\u0354\7\u00aa\2\2\u0354\u0154\3")
buf.write(u"\2\2\2\u0355\u0356\7\u00ab\2\2\u0356\u0156\3\2\2\2\u0357")
buf.write(u"\u0358\7\u00ac\2\2\u0358\u0158\3\2\2\2\u0359\u035a\7")
buf.write(u"\u00ad\2\2\u035a\u015a\3\2\2\2\u035b\u035c\7\u00ae\2")
buf.write(u"\2\u035c\u015c\3\2\2\2\u035d\u035e\7\u00af\2\2\u035e")
buf.write(u"\u015e\3\2\2\2\u035f\u0360\7\u00b0\2\2\u0360\u0160\3")
buf.write(u"\2\2\2\u0361\u0362\7\u00b1\2\2\u0362\u0162\3\2\2\2\u0363")
buf.write(u"\u0364\7\u00b2\2\2\u0364\u0164\3\2\2\2\u0365\u0366\7")
buf.write(u"\u00b3\2\2\u0366\u0166\3\2\2\2\u0367\u0368\7\u00b4\2")
buf.write(u"\2\u0368\u0168\3\2\2\2\u0369\u036a\7\u00b5\2\2\u036a")
buf.write(u"\u016a\3\2\2\2\u036b\u036c\7\u00b6\2\2\u036c\u016c\3")
buf.write(u"\2\2\2\u036d\u036e\7\u00b7\2\2\u036e\u016e\3\2\2\2\u036f")
buf.write(u"\u0370\7\u00b8\2\2\u0370\u0170\3\2\2\2\u0371\u0372\7")
buf.write(u"\u00b9\2\2\u0372\u0172\3\2\2\2\u0373\u0374\7\u00ba\2")
buf.write(u"\2\u0374\u0174\3\2\2\2\u0375\u0376\7\u00bb\2\2\u0376")
buf.write(u"\u0176\3\2\2\2\u0377\u0378\7\u00bc\2\2\u0378\u0178\3")
buf.write(u"\2\2\2\u0379\u037a\7\u00bd\2\2\u037a\u017a\3\2\2\2\u037b")
buf.write(u"\u037c\7\u00be\2\2\u037c\u017c\3\2\2\2\u037d\u037e\7")
buf.write(u"\u00bf\2\2\u037e\u017e\3\2\2\2\u037f\u0380\7\u00c0\2")
buf.write(u"\2\u0380\u0180\3\2\2\2\u0381\u0382\7\u00c1\2\2\u0382")
buf.write(u"\u0182\3\2\2\2\u0383\u0384\7\u00c2\2\2\u0384\u0184\3")
buf.write(u"\2\2\2\u0385\u0386\7\u00c3\2\2\u0386\u0186\3\2\2\2\u0387")
buf.write(u"\u0388\7\u00c4\2\2\u0388\u0188\3\2\2\2\u0389\u038a\7")
buf.write(u"\u00c5\2\2\u038a\u018a\3\2\2\2\u038b\u038c\7\u00c6\2")
buf.write(u"\2\u038c\u018c\3\2\2\2\u038d\u038e\7\u00c7\2\2\u038e")
buf.write(u"\u018e\3\2\2\2\u038f\u0390\7\u00c8\2\2\u0390\u0190\3")
buf.write(u"\2\2\2\u0391\u0392\7\u00c9\2\2\u0392\u0192\3\2\2\2\u0393")
buf.write(u"\u0394\7\u00ca\2\2\u0394\u0194\3\2\2\2\u0395\u0396\7")
buf.write(u"\u00cb\2\2\u0396\u0196\3\2\2\2\u0397\u0398\7\u00cc\2")
buf.write(u"\2\u0398\u0198\3\2\2\2\u0399\u039a\7\u00cd\2\2\u039a")
buf.write(u"\u019a\3\2\2\2\u039b\u039c\7\u00ce\2\2\u039c\u019c\3")
buf.write(u"\2\2\2\u039d\u039e\7\u00cf\2\2\u039e\u019e\3\2\2\2\u039f")
buf.write(u"\u03a0\7\u00d0\2\2\u03a0\u01a0\3\2\2\2\u03a1\u03a2\7")
buf.write(u"\u00d1\2\2\u03a2\u01a2\3\2\2\2\u03a3\u03a4\7\u00d2\2")
buf.write(u"\2\u03a4\u01a4\3\2\2\2\u03a5\u03a6\7\u00d3\2\2\u03a6")
buf.write(u"\u01a6\3\2\2\2\u03a7\u03a8\7\u00d4\2\2\u03a8\u01a8\3")
buf.write(u"\2\2\2\u03a9\u03aa\7\u00d5\2\2\u03aa\u01aa\3\2\2\2\u03ab")
buf.write(u"\u03ac\7\u00d6\2\2\u03ac\u01ac\3\2\2\2\u03ad\u03ae\7")
buf.write(u"\u00d7\2\2\u03ae\u01ae\3\2\2\2\u03af\u03b0\7\u00d8\2")
buf.write(u"\2\u03b0\u01b0\3\2\2\2\u03b1\u03b2\7\u00d9\2\2\u03b2")
buf.write(u"\u01b2\3\2\2\2\u03b3\u03b4\7\u00da\2\2\u03b4\u01b4\3")
buf.write(u"\2\2\2\u03b5\u03b6\7\u00db\2\2\u03b6\u01b6\3\2\2\2\u03b7")
buf.write(u"\u03b8\7\u00dc\2\2\u03b8\u01b8\3\2\2\2\u03b9\u03ba\7")
buf.write(u"\u00dd\2\2\u03ba\u01ba\3\2\2\2\u03bb\u03bc\7\u00de\2")
buf.write(u"\2\u03bc\u01bc\3\2\2\2\u03bd\u03be\7\u00df\2\2\u03be")
buf.write(u"\u01be\3\2\2\2\u03bf\u03c0\7\u00e0\2\2\u03c0\u01c0\3")
buf.write(u"\2\2\2\u03c1\u03c2\7\u00e1\2\2\u03c2\u01c2\3\2\2\2\u03c3")
buf.write(u"\u03c4\7\u00e2\2\2\u03c4\u01c4\3\2\2\2\u03c5\u03c6\7")
buf.write(u"\u00e3\2\2\u03c6\u01c6\3\2\2\2\u03c7\u03c8\7\u00e4\2")
buf.write(u"\2\u03c8\u01c8\3\2\2\2\u03c9\u03ca\7\u00e5\2\2\u03ca")
buf.write(u"\u01ca\3\2\2\2\u03cb\u03cc\7\u00e6\2\2\u03cc\u01cc\3")
buf.write(u"\2\2\2\u03cd\u03ce\7\u00e7\2\2\u03ce\u01ce\3\2\2\2\u03cf")
buf.write(u"\u03d0\7\u00e8\2\2\u03d0\u01d0\3\2\2\2\u03d1\u03d2\7")
buf.write(u"\u00e9\2\2\u03d2\u01d2\3\2\2\2\u03d3\u03d4\7\u00ea\2")
buf.write(u"\2\u03d4\u01d4\3\2\2\2\u03d5\u03d6\7\u00eb\2\2\u03d6")
buf.write(u"\u01d6\3\2\2\2\u03d7\u03d8\7\u00ec\2\2\u03d8\u01d8\3")
buf.write(u"\2\2\2\u03d9\u03da\7\u00ed\2\2\u03da\u01da\3\2\2\2\u03db")
buf.write(u"\u03dc\7\u00ee\2\2\u03dc\u01dc\3\2\2\2\u03dd\u03de\7")
buf.write(u"\u00ef\2\2\u03de\u01de\3\2\2\2\u03df\u03e0\7\u00f0\2")
buf.write(u"\2\u03e0\u01e0\3\2\2\2\u03e1\u03e2\7\u00f1\2\2\u03e2")
buf.write(u"\u01e2\3\2\2\2\u03e3\u03e4\7\u00f2\2\2\u03e4\u01e4\3")
buf.write(u"\2\2\2\u03e5\u03e6\7\u00f3\2\2\u03e6\u01e6\3\2\2\2\u03e7")
buf.write(u"\u03e8\7\u00f4\2\2\u03e8\u01e8\3\2\2\2\u03e9\u03ea\7")
buf.write(u"\u00f5\2\2\u03ea\u01ea\3\2\2\2\u03eb\u03ec\7\u00f6\2")
buf.write(u"\2\u03ec\u01ec\3\2\2\2\u03ed\u03ee\7\u00f7\2\2\u03ee")
buf.write(u"\u01ee\3\2\2\2\u03ef\u03f0\7\u00f8\2\2\u03f0\u01f0\3")
buf.write(u"\2\2\2\u03f1\u03f2\7\u00f9\2\2\u03f2\u01f2\3\2\2\2\u03f3")
buf.write(u"\u03f4\7\u00fa\2\2\u03f4\u01f4\3\2\2\2\u03f5\u03f6\7")
buf.write(u"\u00fb\2\2\u03f6\u01f6\3\2\2\2\u03f7\u03f8\7\u00fc\2")
buf.write(u"\2\u03f8\u01f8\3\2\2\2\u03f9\u03fa\7\u00fd\2\2\u03fa")
buf.write(u"\u01fa\3\2\2\2\u03fb\u03fc\7\u00fe\2\2\u03fc\u01fc\3")
buf.write(u"\2\2\2\u03fd\u03fe\7\u00ff\2\2\u03fe\u01fe\3\2\2\2\u03ff")
buf.write(u"\u0400\7\u0100\2\2\u0400\u0200\3\2\2\2\u0401\u0402\7")
buf.write(u"\u0101\2\2\u0402\u0202\3\2\2\2\3\2\2")
return buf.getvalue()
class sdpLexer(Lexer):
atn = ATNDeserializer().deserialize(serializedATN())
decisionsToDFA = [ DFA(ds, i) for i, ds in enumerate(atn.decisionToState) ]
TAB = 1
LF = 2
CR = 3
SPACE = 4
EXCLAMATION = 5
QUOTE = 6
HASH = 7
DOLLAR = 8
PERCENT = 9
AMPERSAND = 10
APOSTROPHE = 11
LEFT_PAREN = 12
RIGHT_PAREN = 13
ASTERISK = 14
PLUS = 15
COMMA = 16
DASH = 17
PERIOD = 18
SLASH = 19
ZERO = 20
ONE = 21
TWO = 22
THREE = 23
FOUR = 24
FIVE = 25
SIX = 26
SEVEN = 27
EIGHT = 28
NINE = 29
COLON = 30
SEMICOLON = 31
LESS_THAN = 32
EQUALS = 33
GREATER_THAN = 34
QUESTION = 35
AT = 36
CAP_A = 37
CAP_B = 38
CAP_C = 39
CAP_D = 40
CAP_E = 41
CAP_F = 42
CAP_G = 43
CAP_H = 44
CAP_I = 45
CAP_J = 46
CAP_K = 47
CAP_L = 48
CAP_M = 49
CAP_N = 50
CAP_O = 51
CAP_P = 52
CAP_Q = 53
CAP_R = 54
CAP_S = 55
CAP_T = 56
CAP_U = 57
CAP_V = 58
CAP_W = 59
CAP_X = 60
CAP_Y = 61
CAP_Z = 62
LEFT_BRACE = 63
BACKSLASH = 64
RIGHT_BRACE = 65
CARAT = 66
UNDERSCORE = 67
ACCENT = 68
A = 69
B = 70
C = 71
D = 72
E = 73
F = 74
G = 75
H = 76
I = 77
J = 78
K = 79
L = 80
M = 81
N = 82
O = 83
P = 84
Q = 85
R = 86
S = 87
T = 88
U = 89
V = 90
W = 91
X = 92
Y = 93
Z = 94
LEFT_CURLY_BRACE = 95
PIPE = 96
RIGHT_CURLY_BRACE = 97
TILDE = 98
U_0000 = 99
U_0001 = 100
U_0002 = 101
U_0003 = 102
U_0004 = 103
U_0005 = 104
U_0006 = 105
U_0007 = 106
U_0008 = 107
U_000B = 108
U_000C = 109
U_000E = 110
U_000F = 111
U_0010 = 112
U_0011 = 113
U_0012 = 114
U_0013 = 115
U_0014 = 116
U_0015 = 117
U_0016 = 118
U_0017 = 119
U_0018 = 120
U_0019 = 121
U_001A = 122
U_001B = 123
U_001C = 124
U_001D = 125
U_001E = 126
U_001F = 127
U_007F = 128
U_0080 = 129
U_0081 = 130
U_0082 = 131
U_0083 = 132
U_0084 = 133
U_0085 = 134
U_0086 = 135
U_0087 = 136
U_0088 = 137
U_0089 = 138
U_008A = 139
U_008B = 140
U_008C = 141
U_008D = 142
U_008E = 143
U_008F = 144
U_0090 = 145
U_0091 = 146
U_0092 = 147
U_0093 = 148
U_0094 = 149
U_0095 = 150
U_0096 = 151
U_0097 = 152
U_0098 = 153
U_0099 = 154
U_009A = 155
U_009B = 156
U_009C = 157
U_009D = 158
U_009E = 159
U_009F = 160
U_00A0 = 161
U_00A1 = 162
U_00A2 = 163
U_00A3 = 164
U_00A4 = 165
U_00A5 = 166
U_00A6 = 167
U_00A7 = 168
U_00A8 = 169
U_00A9 = 170
U_00AA = 171
U_00AB = 172
U_00AC = 173
U_00AD = 174
U_00AE = 175
U_00AF = 176
U_00B0 = 177
U_00B1 = 178
U_00B2 = 179
U_00B3 = 180
U_00B4 = 181
U_00B5 = 182
U_00B6 = 183
U_00B7 = 184
U_00B8 = 185
U_00B9 = 186
U_00BA = 187
U_00BB = 188
U_00BC = 189
U_00BD = 190
U_00BE = 191
U_00BF = 192
U_00C0 = 193
U_00C1 = 194
U_00C2 = 195
U_00C3 = 196
U_00C4 = 197
U_00C5 = 198
U_00C6 = 199
U_00C7 = 200
U_00C8 = 201
U_00C9 = 202
U_00CA = 203
U_00CB = 204
U_00CC = 205
U_00CD = 206
U_00CE = 207
U_00CF = 208
U_00D0 = 209
U_00D1 = 210
U_00D2 = 211
U_00D3 = 212
U_00D4 = 213
U_00D5 = 214
U_00D6 = 215
U_00D7 = 216
U_00D8 = 217
U_00D9 = 218
U_00DA = 219
U_00DB = 220
U_00DC = 221
U_00DD = 222
U_00DE = 223
U_00DF = 224
U_00E0 = 225
U_00E1 = 226
U_00E2 = 227
U_00E3 = 228
U_00E4 = 229
U_00E5 = 230
U_00E6 = 231
U_00E7 = 232
U_00E8 = 233
U_00E9 = 234
U_00EA = 235
U_00EB = 236
U_00EC = 237
U_00ED = 238
U_00EE = 239
U_00EF = 240
U_00F0 = 241
U_00F1 = 242
U_00F2 = 243
U_00F3 = 244
U_00F4 = 245
U_00F5 = 246
U_00F6 = 247
U_00F7 = 248
U_00F8 = 249
U_00F9 = 250
U_00FA = 251
U_00FB = 252
U_00FC = 253
U_00FD = 254
U_00FE = 255
U_00FF = 256
channelNames = [ u"DEFAULT_TOKEN_CHANNEL", u"HIDDEN" ]
modeNames = [ u"DEFAULT_MODE" ]
literalNames = [ u"<INVALID>",
u"'\u0009'", u"'\u000A'", u"'\u000D'", u"' '", u"'!'", u"'\"'",
u"'#'", u"'$'", u"'%'", u"'&'", u"'''", u"'('", u"')'", u"'*'",
u"'+'", u"','", u"'-'", u"'.'", u"'/'", u"'0'", u"'1'", u"'2'",
u"'3'", u"'4'", u"'5'", u"'6'", u"'7'", u"'8'", u"'9'", u"':'",
u"';'", u"'<'", u"'='", u"'>'", u"'?'", u"'@'", u"'A'", u"'B'",
u"'C'", u"'D'", u"'E'", u"'F'", u"'G'", u"'H'", u"'I'", u"'J'",
u"'K'", u"'L'", u"'M'", u"'N'", u"'O'", u"'P'", u"'Q'", u"'R'",
u"'S'", u"'T'", u"'U'", u"'V'", u"'W'", u"'X'", u"'Y'", u"'Z'",
u"'['", u"'\\'", u"']'", u"'^'", u"'_'", u"'`'", u"'a'", u"'b'",
u"'c'", u"'d'", u"'e'", u"'f'", u"'g'", u"'h'", u"'i'", u"'j'",
u"'k'", u"'l'", u"'m'", u"'n'", u"'o'", u"'p'", u"'q'", u"'r'",
u"'s'", u"'t'", u"'u'", u"'v'", u"'w'", u"'x'", u"'y'", u"'z'",
u"'{'", u"'|'", u"'}'", u"'~'", u"'\u0000'", u"'\u0001'", u"'\u0002'",
u"'\u0003'", u"'\u0004'", u"'\u0005'", u"'\u0006'", u"'\u0007'",
u"'\u0008'", u"'\u000B'", u"'\u000C'", u"'\u000E'", u"'\u000F'",
u"'\u0010'", u"'\u0011'", u"'\u0012'", u"'\u0013'", u"'\u0014'",
u"'\u0015'", u"'\u0016'", u"'\u0017'", u"'\u0018'", u"'\u0019'",
u"'\u001A'", u"'\u001B'", u"'\u001C'", u"'\u001D'", u"'\u001E'",
u"'\u001F'", u"'\u007F'", u"'\u0080'", u"'\u0081'", u"'\u0082'",
u"'\u0083'", u"'\u0084'", u"'\u0085'", u"'\u0086'", u"'\u0087'",
u"'\u0088'", u"'\u0089'", u"'\u008A'", u"'\u008B'", u"'\u008C'",
u"'\u008D'", u"'\u008E'", u"'\u008F'", u"'\u0090'", u"'\u0091'",
u"'\u0092'", u"'\u0093'", u"'\u0094'", u"'\u0095'", u"'\u0096'",
u"'\u0097'", u"'\u0098'", u"'\u0099'", u"'\u009A'", u"'\u009B'",
u"'\u009C'", u"'\u009D'", u"'\u009E'", u"'\u009F'", u"'\u00A0'",
u"'\u00A1'", u"'\u00A2'", u"'\u00A3'", u"'\u00A4'", u"'\u00A5'",
u"'\u00A6'", u"'\u00A7'", u"'\u00A8'", u"'\u00A9'", u"'\u00AA'",
u"'\u00AB'", u"'\u00AC'", u"'\u00AD'", u"'\u00AE'", u"'\u00AF'",
u"'\u00B0'", u"'\u00B1'", u"'\u00B2'", u"'\u00B3'", u"'\u00B4'",
u"'\u00B5'", u"'\u00B6'", u"'\u00B7'", u"'\u00B8'", u"'\u00B9'",
u"'\u00BA'", u"'\u00BB'", u"'\u00BC'", u"'\u00BD'", u"'\u00BE'",
u"'\u00BF'", u"'\u00C0'", u"'\u00C1'", u"'\u00C2'", u"'\u00C3'",
u"'\u00C4'", u"'\u00C5'", u"'\u00C6'", u"'\u00C7'", u"'\u00C8'",
u"'\u00C9'", u"'\u00CA'", u"'\u00CB'", u"'\u00CC'", u"'\u00CD'",
u"'\u00CE'", u"'\u00CF'", u"'\u00D0'", u"'\u00D1'", u"'\u00D2'",
u"'\u00D3'", u"'\u00D4'", u"'\u00D5'", u"'\u00D6'", u"'\u00D7'",
u"'\u00D8'", u"'\u00D9'", u"'\u00DA'", u"'\u00DB'", u"'\u00DC'",
u"'\u00DD'", u"'\u00DE'", u"'\u00DF'", u"'\u00E0'", u"'\u00E1'",
u"'\u00E2'", u"'\u00E3'", u"'\u00E4'", u"'\u00E5'", u"'\u00E6'",
u"'\u00E7'", u"'\u00E8'", u"'\u00E9'", u"'\u00EA'", u"'\u00EB'",
u"'\u00EC'", u"'\u00ED'", u"'\u00EE'", u"'\u00EF'", u"'\u00F0'",
u"'\u00F1'", u"'\u00F2'", u"'\u00F3'", u"'\u00F4'", u"'\u00F5'",
u"'\u00F6'", u"'\u00F7'", u"'\u00F8'", u"'\u00F9'", u"'\u00FA'",
u"'\u00FB'", u"'\u00FC'", u"'\u00FD'", u"'\u00FE'", u"'\u00FF'" ]
symbolicNames = [ u"<INVALID>",
u"TAB", u"LF", u"CR", u"SPACE", u"EXCLAMATION", u"QUOTE", u"HASH",
u"DOLLAR", u"PERCENT", u"AMPERSAND", u"APOSTROPHE", u"LEFT_PAREN",
u"RIGHT_PAREN", u"ASTERISK", u"PLUS", u"COMMA", u"DASH", u"PERIOD",
u"SLASH", u"ZERO", u"ONE", u"TWO", u"THREE", u"FOUR", u"FIVE",
u"SIX", u"SEVEN", u"EIGHT", u"NINE", u"COLON", u"SEMICOLON",
u"LESS_THAN", u"EQUALS", u"GREATER_THAN", u"QUESTION", u"AT",
u"CAP_A", u"CAP_B", u"CAP_C", u"CAP_D", u"CAP_E", u"CAP_F",
u"CAP_G", u"CAP_H", u"CAP_I", u"CAP_J", u"CAP_K", u"CAP_L",
u"CAP_M", u"CAP_N", u"CAP_O", u"CAP_P", u"CAP_Q", u"CAP_R",
u"CAP_S", u"CAP_T", u"CAP_U", u"CAP_V", u"CAP_W", u"CAP_X",
u"CAP_Y", u"CAP_Z", u"LEFT_BRACE", u"BACKSLASH", u"RIGHT_BRACE",
u"CARAT", u"UNDERSCORE", u"ACCENT", u"A", u"B", u"C", u"D",
u"E", u"F", u"G", u"H", u"I", u"J", u"K", u"L", u"M", u"N",
u"O", u"P", u"Q", u"R", u"S", u"T", u"U", u"V", u"W", u"X",
u"Y", u"Z", u"LEFT_CURLY_BRACE", u"PIPE", u"RIGHT_CURLY_BRACE",
u"TILDE", u"U_0000", u"U_0001", u"U_0002", u"U_0003", u"U_0004",
u"U_0005", u"U_0006", u"U_0007", u"U_0008", u"U_000B", u"U_000C",
u"U_000E", u"U_000F", u"U_0010", u"U_0011", u"U_0012", u"U_0013",
u"U_0014", u"U_0015", u"U_0016", u"U_0017", u"U_0018", u"U_0019",
u"U_001A", u"U_001B", u"U_001C", u"U_001D", u"U_001E", u"U_001F",
u"U_007F", u"U_0080", u"U_0081", u"U_0082", u"U_0083", u"U_0084",
u"U_0085", u"U_0086", u"U_0087", u"U_0088", u"U_0089", u"U_008A",
u"U_008B", u"U_008C", u"U_008D", u"U_008E", u"U_008F", u"U_0090",
u"U_0091", u"U_0092", u"U_0093", u"U_0094", u"U_0095", u"U_0096",
u"U_0097", u"U_0098", u"U_0099", u"U_009A", u"U_009B", u"U_009C",
u"U_009D", u"U_009E", u"U_009F", u"U_00A0", u"U_00A1", u"U_00A2",
u"U_00A3", u"U_00A4", u"U_00A5", u"U_00A6", u"U_00A7", u"U_00A8",
u"U_00A9", u"U_00AA", u"U_00AB", u"U_00AC", u"U_00AD", u"U_00AE",
u"U_00AF", u"U_00B0", u"U_00B1", u"U_00B2", u"U_00B3", u"U_00B4",
u"U_00B5", u"U_00B6", u"U_00B7", u"U_00B8", u"U_00B9", u"U_00BA",
u"U_00BB", u"U_00BC", u"U_00BD", u"U_00BE", u"U_00BF", u"U_00C0",
u"U_00C1", u"U_00C2", u"U_00C3", u"U_00C4", u"U_00C5", u"U_00C6",
u"U_00C7", u"U_00C8", u"U_00C9", u"U_00CA", u"U_00CB", u"U_00CC",
u"U_00CD", u"U_00CE", u"U_00CF", u"U_00D0", u"U_00D1", u"U_00D2",
u"U_00D3", u"U_00D4", u"U_00D5", u"U_00D6", u"U_00D7", u"U_00D8",
u"U_00D9", u"U_00DA", u"U_00DB", u"U_00DC", u"U_00DD", u"U_00DE",
u"U_00DF", u"U_00E0", u"U_00E1", u"U_00E2", u"U_00E3", u"U_00E4",
u"U_00E5", u"U_00E6", u"U_00E7", u"U_00E8", u"U_00E9", u"U_00EA",
u"U_00EB", u"U_00EC", u"U_00ED", u"U_00EE", u"U_00EF", u"U_00F0",
u"U_00F1", u"U_00F2", u"U_00F3", u"U_00F4", u"U_00F5", u"U_00F6",
u"U_00F7", u"U_00F8", u"U_00F9", u"U_00FA", u"U_00FB", u"U_00FC",
u"U_00FD", u"U_00FE", u"U_00FF" ]
ruleNames = [ u"TAB", u"LF", u"CR", u"SPACE", u"EXCLAMATION", u"QUOTE",
u"HASH", u"DOLLAR", u"PERCENT", u"AMPERSAND", u"APOSTROPHE",
u"LEFT_PAREN", u"RIGHT_PAREN", u"ASTERISK", u"PLUS", u"COMMA",
u"DASH", u"PERIOD", u"SLASH", u"ZERO", u"ONE", u"TWO",
u"THREE", u"FOUR", u"FIVE", u"SIX", u"SEVEN", u"EIGHT",
u"NINE", u"COLON", u"SEMICOLON", u"LESS_THAN", u"EQUALS",
u"GREATER_THAN", u"QUESTION", u"AT", u"CAP_A", u"CAP_B",
u"CAP_C", u"CAP_D", u"CAP_E", u"CAP_F", u"CAP_G", u"CAP_H",
u"CAP_I", u"CAP_J", u"CAP_K", u"CAP_L", u"CAP_M", u"CAP_N",
u"CAP_O", u"CAP_P", u"CAP_Q", u"CAP_R", u"CAP_S", u"CAP_T",
u"CAP_U", u"CAP_V", u"CAP_W", u"CAP_X", u"CAP_Y", u"CAP_Z",
u"LEFT_BRACE", u"BACKSLASH", u"RIGHT_BRACE", u"CARAT",
u"UNDERSCORE", u"ACCENT", u"A", u"B", u"C", u"D", u"E",
u"F", u"G", u"H", u"I", u"J", u"K", u"L", u"M", u"N",
u"O", u"P", u"Q", u"R", u"S", u"T", u"U", u"V", u"W",
u"X", u"Y", u"Z", u"LEFT_CURLY_BRACE", u"PIPE", u"RIGHT_CURLY_BRACE",
u"TILDE", u"U_0000", u"U_0001", u"U_0002", u"U_0003",
u"U_0004", u"U_0005", u"U_0006", u"U_0007", u"U_0008",
u"U_000B", u"U_000C", u"U_000E", u"U_000F", u"U_0010",
u"U_0011", u"U_0012", u"U_0013", u"U_0014", u"U_0015",
u"U_0016", u"U_0017", u"U_0018", u"U_0019", u"U_001A",
u"U_001B", u"U_001C", u"U_001D", u"U_001E", u"U_001F",
u"U_007F", u"U_0080", u"U_0081", u"U_0082", u"U_0083",
u"U_0084", u"U_0085", u"U_0086", u"U_0087", u"U_0088",
u"U_0089", u"U_008A", u"U_008B", u"U_008C", u"U_008D",
u"U_008E", u"U_008F", u"U_0090", u"U_0091", u"U_0092",
u"U_0093", u"U_0094", u"U_0095", u"U_0096", u"U_0097",
u"U_0098", u"U_0099", u"U_009A", u"U_009B", u"U_009C",
u"U_009D", u"U_009E", u"U_009F", u"U_00A0", u"U_00A1",
u"U_00A2", u"U_00A3", u"U_00A4", u"U_00A5", u"U_00A6",
u"U_00A7", u"U_00A8", u"U_00A9", u"U_00AA", u"U_00AB",
u"U_00AC", u"U_00AD", u"U_00AE", u"U_00AF", u"U_00B0",
u"U_00B1", u"U_00B2", u"U_00B3", u"U_00B4", u"U_00B5",
u"U_00B6", u"U_00B7", u"U_00B8", u"U_00B9", u"U_00BA",
u"U_00BB", u"U_00BC", u"U_00BD", u"U_00BE", u"U_00BF",
u"U_00C0", u"U_00C1", u"U_00C2", u"U_00C3", u"U_00C4",
u"U_00C5", u"U_00C6", u"U_00C7", u"U_00C8", u"U_00C9",
u"U_00CA", u"U_00CB", u"U_00CC", u"U_00CD", u"U_00CE",
u"U_00CF", u"U_00D0", u"U_00D1", u"U_00D2", u"U_00D3",
u"U_00D4", u"U_00D5", u"U_00D6", u"U_00D7", u"U_00D8",
u"U_00D9", u"U_00DA", u"U_00DB", u"U_00DC", u"U_00DD",
u"U_00DE", u"U_00DF", u"U_00E0", u"U_00E1", u"U_00E2",
u"U_00E3", u"U_00E4", u"U_00E5", u"U_00E6", u"U_00E7",
u"U_00E8", u"U_00E9", u"U_00EA", u"U_00EB", u"U_00EC",
u"U_00ED", u"U_00EE", u"U_00EF", u"U_00F0", u"U_00F1",
u"U_00F2", u"U_00F3", u"U_00F4", u"U_00F5", u"U_00F6",
u"U_00F7", u"U_00F8", u"U_00F9", u"U_00FA", u"U_00FB",
u"U_00FC", u"U_00FD", u"U_00FE", u"U_00FF" ]
grammarFileName = u"sdp.g4"
def __init__(self, input=None, output=sys.stdout):
super(sdpLexer, self).__init__(input, output=output)
self.checkVersion("4.8")
self._interp = LexerATNSimulator(self, self.atn, self.decisionsToDFA, PredictionContextCache())
self._actions = None
self._predicates = None
| python |
import torch
import torch.nn as nn # for network
import torch.nn.functional as F # for forward method
drop_out_value = 0.1
class Network(nn.Module):
def __init__(self):
super(Network,self).__init__() # extending super class method
# Input block
self.convblock_input= nn.Sequential(
nn.Conv2d(3,32,3,padding=1), # In- 3x32x32, Out- 32x32x32, RF- 3x3, Jump_in -1, Jump_out -1
nn.ReLU(),
nn.BatchNorm2d(32),
nn.Dropout(drop_out_value)
)
# CONV BLOCK 1
self.convblock1 = nn.Sequential(
nn.Conv2d(32,32,3,padding=1), # In- 32x32x32, Out- 32x32x32, RF- 5x5, Jump_in -1, Jump_out -1
nn.ReLU(),
nn.BatchNorm2d(32),
nn.Dropout(drop_out_value)
,
nn.Conv2d(32,32,3,padding=1), # In- 32x32x32, Out- 32x32x32, RF- 7x7, Jump_in -1, Jump_out -1
nn.ReLU(),
nn.BatchNorm2d(32),
nn.Dropout(drop_out_value)
)
# TRANSITION BLOCK 1
# STRIDED CONVOLUTION LAYER
self.transitionblock1 = nn.Sequential(
nn.Conv2d(32,32,3,stride=2,padding=1), # In- 32x32x32, Out- 32x16x16, RF- 9x9, Jump_in -1, Jump_out -2
nn.ReLU(),
nn.BatchNorm2d(32),
nn.Dropout(drop_out_value)
)
# CONV BLOCK 2
# Depthwise Separable Convolution Layer
self.convblock2 = nn.Sequential(
nn.Conv2d(32,32,3,padding=1,groups=32),# In- 32x16x16, Out- 32x16x16, RF- 13x13, Jump_in -2, Jump_out -2
nn.Conv2d(32,32,1,padding=0), # In-32x16x16 , Out- 32x16x16, RF- 13x13, Jump_in -2, Jump_out -2
nn.ReLU(),
nn.BatchNorm2d(32),
nn.Dropout(drop_out_value)
,
nn.Conv2d(32,32,3,padding=1), # In-32x16x16 , Out-32x16x16 , RF- 17x17, Jump_in -2, Jump_out -2
nn.ReLU(),
nn.BatchNorm2d(32),
nn.Dropout(drop_out_value)
)
# TRANSITION BLOCK 2
# STRIDED CONVOLUTION LAYER
self.transitionblock2 = nn.Sequential(
nn.Conv2d(32,32,3,stride=2,padding=1), # In- 32x16x16, Out-32x8x8 , RF- 21x21, Jump_in -2, Jump_out -4
nn.ReLU(),
nn.BatchNorm2d(32),
nn.Dropout(drop_out_value)
)
# CONV BLOCK 3
# Dilated Convolution Layer
self.convblock3 = nn.Sequential(
nn.Conv2d(32,32,3,padding=1,dilation=2),# In- 32x8x8, Out-32x6x6 , RF- 29x29, Jump_in -4, Jump_out -4
nn.ReLU(),
nn.BatchNorm2d(32),
nn.Dropout(drop_out_value)
,
nn.Conv2d(32,32,3,padding=1), # In-32x6x6 , Out- 32x6x6, RF- 37x37, Jump_in -4, Jump_out -4
nn.ReLU(),
nn.BatchNorm2d(32),
nn.Dropout(drop_out_value)
)
# TRANSITION BLOCK 3
# STRIDED CONVOLUTION LAYER
self.transitionblock3 = nn.Sequential(
nn.Conv2d(32,32,3,stride=2,padding=1), # In-32x6x6 , Out-32x3x3 , RF- 45x45, Jump_in -4, Jump_out -8
nn.ReLU(),
nn.BatchNorm2d(32),
nn.Dropout(drop_out_value)
)
# CONV BLOCK 4
# Depthwise Separable Convolution Layer
self.convblock4 = nn.Sequential(
nn.Conv2d(32,32,3,padding=1), # In- 32x3x3, Out-32x3x3 , RF- 61x61, Jump_in -8, Jump_out -8
nn.ReLU(),
nn.BatchNorm2d(32),
nn.Dropout(drop_out_value)
,
nn.Conv2d(32,32,3,padding=1,groups=32), # In-32x3x3 , Out-32x3x3 , RF- 77x77, Jump_in -8, Jump_out -8
nn.Conv2d(32,10,1,padding=0) # In- 32x3x3, Out-10x3x3 , RF- 77x77, Jump_in -8, Jump_out -8
# ,
# nn.ReLU(),
# nn.BatchNorm2d(10),
# nn.Dropout(drop_out_value)
)
# Output BLOCK
# GAP Layer
self.gap = nn.AvgPool2d(3) # In- 10x3x3, Out-10x1x1 , RF- 77x77, Jump_in -8, Jump_out -8
def forward(self, x):
x = self.convblock_input(x)
x = self.convblock1(x)
x = self.transitionblock1(x)
x = self.convblock2(x)
x = self.transitionblock2(x)
x = self.convblock3(x)
x = self.transitionblock3(x)
x = self.convblock4(x)
x = self.gap(x)
x = x.view(-1, 10)
return F.log_softmax(x, dim=1) | python |
# -*- coding: utf-8 -*-
# Resource object code
#
# Created by: The Resource Compiler for PyQt4 (Qt v4.8.7)
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore
qt_resource_data = "\
\x00\x00\x03\x92\
\x89\
\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52\x00\
\x00\x00\x1f\x00\x00\x00\x1f\x08\x06\x00\x00\x00\x1f\xae\x16\x39\
\x00\x00\x00\x01\x73\x52\x47\x42\x02\x40\xc0\x7d\xc5\x00\x00\x00\
\x09\x70\x48\x59\x73\x00\x00\x0e\xc4\x00\x00\x0e\xc4\x01\x95\x2b\
\x0e\x1b\x00\x00\x00\x19\x74\x45\x58\x74\x53\x6f\x66\x74\x77\x61\
\x72\x65\x00\x4d\x69\x63\x72\x6f\x73\x6f\x66\x74\x20\x4f\x66\x66\
\x69\x63\x65\x7f\xed\x35\x71\x00\x00\x03\x12\x49\x44\x41\x54\x58\
\xc3\xc5\x97\x3d\x4c\xdb\x40\x14\xc7\x19\x19\x19\x33\x66\x65\x64\
\xcc\xd8\x35\x63\x25\x16\x46\x86\x0e\x0c\x2c\x1d\x99\x50\xb3\xa5\
\x63\xd9\x60\x8b\x98\x22\x16\x5a\x55\x55\x15\xb9\x2a\x76\x87\x28\
\x17\xb5\x09\x8e\x81\xda\x97\x60\xa1\x53\x9b\x92\x53\x15\x45\xb6\
\x44\x06\xf7\xde\xe1\x8f\xb3\xe3\x73\x9c\x0f\xa9\x91\xfe\x02\x27\
\xbe\xfb\xbd\xf7\xbf\xf3\xbd\xe7\x8d\xe3\xe3\xe3\x8d\xff\xa5\xdc\
\x37\x5e\x9c\x5f\xec\xe8\x86\xfe\x1a\xdf\xe3\x1a\x21\x04\x91\x5f\
\x84\xd2\x21\xf5\xe0\x2f\x5c\xb3\xdf\x6a\xea\x57\xf5\x00\xee\x5b\
\x1b\x5c\x55\xd5\xf2\xe3\xef\xc7\xda\x64\x32\x71\xd8\xc7\xe3\x1a\
\x47\x82\x00\x44\x91\x21\x71\xae\x7b\xd7\xa7\xea\x17\xb5\xbc\x34\
\x5c\xf9\xa8\x14\xe9\x1f\x5a\x8d\x41\x9f\x24\x72\xe2\x81\x10\x9b\
\x78\xe6\xc0\x74\x10\x42\x55\xd7\x72\x8b\x0b\xc1\x95\xcb\xcb\xd2\
\x68\x34\x7a\x1f\x4e\xfc\x94\x53\x4e\x3c\x00\x8c\xb1\xa7\xeb\x7a\
\x9d\xa9\x94\x0b\xee\x83\x1b\xb9\x81\x29\x0e\x04\x2e\xf0\x00\xee\
\xb0\xd7\xff\xd9\x6f\xb8\x43\xb7\x94\x09\xaf\x54\x2a\x45\x9e\xb1\
\xb3\x04\x38\x80\x3b\xb3\x70\x7c\xa7\x73\x07\x5c\xcf\x2d\x48\xe1\
\xa6\x69\x56\x97\x06\xa7\xc0\xa3\x00\x18\xbc\xa3\xc3\xf5\x51\x2a\
\x5c\x55\xd4\x72\xb8\xb9\xd6\x0e\xc7\x1c\xde\x6c\x35\xa9\x4b\x23\
\xfb\x43\x38\xb6\xf1\xe9\xdc\x5d\x9d\x13\x2c\x83\xf3\xec\xd9\x13\
\x14\x83\x9f\x9f\x9d\xef\x4c\xfe\xae\x3f\xeb\x24\x1c\xb5\x11\xcf\
\x7e\x3a\x9d\x6e\x87\x70\xe3\x87\x71\xc0\x23\x5e\x15\x3e\x9e\x0f\
\x47\x4d\xcd\x63\xd6\xbf\x0c\xe1\xdc\xf2\xf1\x8a\x96\x4b\xc0\x49\
\xdb\x21\x80\x60\xe3\x71\x38\x9c\xcd\x70\xf3\x52\xf0\x0c\xbb\x63\
\x8f\x9a\x0f\xd7\x58\xe6\x50\x07\x22\xb8\x5f\x24\x16\x3d\xcd\xe6\
\x81\xd3\xb2\x06\x38\x3b\x76\xb5\x10\x1e\x0c\xca\xb5\xdb\x1d\xf9\
\xce\x4e\x03\x8b\x59\x07\xf0\xc6\xe7\x06\x0a\xe1\xa6\x6d\x12\x0e\
\x1f\x27\x26\xcf\x12\x40\x69\xa2\xa2\x91\x59\x70\x00\xe7\x9b\x8d\
\xe9\x4a\xbd\x72\x58\x00\xf5\x10\xde\x37\xf4\x06\x0c\x08\x03\x18\
\xcb\x81\xd2\x52\x6a\xcb\xc1\x62\xd6\x00\xef\x1b\x46\xb4\xe1\x5a\
\xcd\xd6\x9b\x00\x1e\x0b\x40\x04\x51\x9a\x0a\xcd\x04\xf7\xe2\x59\
\x03\x5c\xfb\xa6\x11\xcb\xb6\xca\x21\xbc\x5e\xab\x97\x61\x90\x18\
\x40\x1e\x89\x50\x19\x58\xcc\x9a\x4b\xd3\x90\xeb\x3e\xd7\x78\x0e\
\xdf\x7d\xb5\x5b\xe8\x5e\x77\x49\x30\x49\x5e\x58\x04\x8c\xa0\x99\
\xe0\xa6\x46\x51\x07\xbd\xf3\x3c\x6f\x33\x76\xb6\x2b\x9f\x94\x83\
\x20\xfb\xbc\x4a\x82\x03\xa0\x04\xec\xb5\x5a\x2d\xcc\xea\xfa\xce\
\x4c\x61\x39\x3c\x3c\x2c\xb0\x01\xf8\x79\x22\x9c\x01\xc2\x73\xa1\
\xc9\x75\xf6\xff\xe7\x6d\x55\x90\xf5\x4c\x3d\x3f\x79\x7b\x52\x62\
\xb6\x38\x30\x58\xb4\x31\x29\xd1\x56\x19\x34\x21\x07\x7d\x47\x1a\
\xeb\xe7\x0a\x99\x6d\x54\xed\xac\xb6\x07\x95\x47\x36\x79\x96\x52\
\xc1\x1d\x04\xbf\xe9\xa2\xdd\x52\x38\xfb\x6c\x2a\x97\x1f\xf6\x60\
\x7d\x60\xa0\x3f\x58\x0a\x13\xa1\xe2\x77\x41\xf3\xd0\xed\x74\x91\
\x7d\x6b\x97\x16\x6b\x9d\x59\x23\xc9\x0a\x40\x83\x59\xcc\x5d\xc8\
\x0a\x62\x46\x6c\x59\x30\x93\x75\x63\xa1\xa9\xfd\x5c\xbb\x17\x7e\
\x69\xa0\x16\xdd\x32\xd8\x69\xd4\xef\xf5\x34\xd6\x00\x62\xec\x4f\
\x1a\xae\x7f\xcf\x5f\xff\xc4\xf7\xe6\xad\x4e\xa1\x1f\x64\x0f\xe8\
\xd6\xca\xaf\x4b\xb0\x51\xda\xdd\xf6\x3e\x94\x42\x38\x8a\x2d\xcb\
\xc2\x20\xf3\x46\x77\xe0\x7c\xf0\xaf\x11\xb4\xc8\xec\x7c\x3f\x9a\
\x07\x5d\xf8\x5d\x4d\x74\x03\xac\x1c\x0c\x06\x2f\x1e\x1e\x1e\xf6\
\x19\xb4\x3c\x25\xd3\xed\xbc\xc0\x95\xe0\xeb\xd4\x3f\xdc\x36\x4c\
\x60\x71\x91\x5a\x21\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\
\x82\
\x00\x00\x11\x96\
\x89\
\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52\x00\
\x00\x01\xea\x00\x00\x01\xe9\x08\x03\x00\x00\x00\x7a\x27\x8f\xa6\
\x00\x00\x00\x01\x73\x52\x47\x42\x02\x40\xc0\x7d\xc5\x00\x00\x00\
\xcc\x50\x4c\x54\x45\x00\x00\x00\x00\x00\x00\x01\x01\x00\x01\x01\
\x01\x02\x02\x01\x02\x02\x02\x01\x00\x00\x02\x01\x01\x74\x45\x11\
\x6b\x41\x11\x7c\x50\x1f\x7b\x50\x29\x84\x51\x12\x83\x50\x10\x8b\
\x5b\x1f\x83\x57\x1f\x8b\x5c\x20\x83\x5d\x29\x92\x60\x1f\x8d\x60\
\x1c\x9c\x73\x33\x9d\x73\x34\x9c\x72\x32\x8b\x60\x2e\x8c\x61\x30\
\x8b\x65\x29\xb4\x81\x39\xb4\x95\x5a\xac\x85\x41\xbd\x91\x4a\xc5\
\xa5\x62\xde\xba\x6a\xde\xbe\x7b\xde\xba\x6b\xd5\xb2\x73\xcd\xb2\
\x73\xcd\xb2\x74\xd5\xb2\x74\xdc\xb9\x69\xde\xc2\x83\xde\xce\x8b\
\xe6\xc2\x73\xe4\xc0\x72\xe6\xc6\x73\xe6\xc2\x74\xe4\xc1\x72\xe4\
\xc5\x72\xe5\xc1\x73\xe5\xc5\x73\xee\xde\x9c\xe6\xda\x9c\xe6\xc6\
\x8b\xe6\xc2\x83\xee\xde\xac\xec\xdc\xaa\xed\xdd\xac\xed\xdd\xab\
\xec\xdc\xab\xee\xda\xb4\xed\xd9\xb3\xec\xd8\xb3\xec\xd9\xb3\xed\
\xd9\xb4\xf6\xe2\xb4\xf5\xe1\xb4\xf5\xe1\xb3\xf4\xe0\xb3\xf4\xe0\
\xb2\x55\x63\x12\x96\x00\x00\x00\x01\x74\x52\x4e\x53\x00\x40\xe6\
\xd8\x66\x00\x00\x00\x09\x70\x48\x59\x73\x00\x00\x0e\xc4\x00\x00\
\x0e\xc4\x01\x95\x2b\x0e\x1b\x00\x00\x00\x19\x74\x45\x58\x74\x53\
\x6f\x66\x74\x77\x61\x72\x65\x00\x4d\x69\x63\x72\x6f\x73\x6f\x66\
\x74\x20\x4f\x66\x66\x69\x63\x65\x7f\xed\x35\x71\x00\x00\x10\x31\
\x49\x44\x41\x54\x78\xda\xed\xdd\x0d\x77\xdb\xb6\x15\x80\xe1\x24\
\xce\x62\xcb\xdb\xbc\x4d\xeb\xa6\x7d\x86\x2e\xd4\x74\xf5\xbc\x76\
\x5b\x93\x74\xab\xdb\xce\x8d\xfb\xff\xff\xd3\x22\x8a\xa2\x08\x82\
\x00\x41\x89\x1f\xc0\xbd\x2f\x4e\x4e\x8f\xea\x2b\x32\x42\x1e\x83\
\x00\x29\x5c\xe0\xd9\x33\x8a\x9a\xf2\x8b\xab\xab\xab\xd5\x55\x59\
\x56\xc7\x97\x57\xab\x5d\x29\xff\xb7\xfe\xb3\xfb\xcf\xea\x10\x3f\
\xfc\x64\x55\x1f\x51\xbe\xab\x71\x26\xeb\xbf\x7d\xef\x5b\x1d\xde\
\xd5\x28\x2b\xeb\x83\xd9\x7f\xed\x3e\x68\xbf\xff\xaa\x75\xf4\xea\
\x58\xa7\xd5\xe1\xe4\x56\x35\xec\xa3\xdb\x15\x3b\xfc\x0b\xac\xea\
\xbf\xc5\xfe\x8c\xab\xd5\x55\xeb\x03\xae\xaa\x6a\x96\x87\xb4\x4e\
\x7e\x38\x4b\xe3\xe8\xf2\xcf\xe1\x2c\x8d\x0f\x57\xff\x1d\xab\x66\
\xc4\x05\x88\x7c\x4b\x59\x3e\xf9\xdd\x47\xea\x5f\xfe\x9b\x22\xbd\
\x7c\xfd\xf5\xeb\xdf\x7f\xa4\xfe\xf5\x5b\x8a\xf8\xf2\xb7\xd7\x9f\
\x7c\xa4\xbe\xf9\xe2\x5d\x41\x11\x5e\x6e\xa1\x86\x9a\x02\x35\x25\
\x67\xea\x0d\xd4\xb4\x6a\x0a\xd4\x14\xa8\x29\x50\x53\x52\xa0\x5e\
\x43\xad\x85\x9a\x11\xb8\x1a\x6a\x2e\xe0\x6a\xa8\xb9\x80\xd3\xaa\
\x29\x50\x53\xa0\xa6\xa4\x4d\xed\x8e\xc0\x6f\xef\x28\x79\x97\xdb\
\xd8\x56\x7d\xf7\x9c\x92\x77\xf9\x7b\x6c\xab\xbe\x7b\xfe\xf8\x3e\
\x54\x1e\x53\x8f\xbf\xf8\x31\x1c\xbf\xf8\xb0\x6c\xfc\xe5\xd3\x79\
\xf1\x9f\xfd\xd4\x13\xff\xe6\xd3\xe8\x56\xfd\x3e\x78\xe1\x4f\x3e\
\xfe\xea\x3f\xe1\xf8\x8b\xff\x9e\x17\xbf\x38\x33\x7e\xf9\x6d\x38\
\xfe\xf2\xdb\x4f\xc3\xf1\x6f\x86\xc6\xfd\xad\x1a\x6a\x91\xd4\xb4\
\x6a\xa8\xa1\x96\x46\x7d\x0d\xb5\x16\x6a\xfa\x6a\x5a\x35\xd4\xd2\
\xa8\xe9\xab\xd5\x50\x73\x01\x87\x1a\x6a\x69\xd4\x5c\xc0\xd5\x50\
\xaf\xa1\xa6\x55\x43\x2d\x8c\x9a\xbe\x1a\x6a\xa8\xa5\x51\x73\x01\
\x57\x43\xcd\xb0\x8c\x56\x0d\x35\xd4\x50\x43\x0d\x75\xda\xd4\x8c\
\xc0\x69\xd5\x50\xd3\xaa\xa1\xa6\x55\x43\x4d\xab\x86\x9a\x56\x0d\
\x35\xd4\x50\x4f\x40\xcd\x34\x42\x35\xd4\xf4\xd5\xaa\x5b\xf5\x63\
\x30\x7b\xf7\x3e\xf5\xf8\xab\x1f\xc3\xf1\x17\x1f\xce\x8b\x5f\x9c\
\x19\xbf\x7c\x0a\xc7\x5f\x3e\xfd\x23\x1c\xff\xa9\x27\x3e\xa0\xaf\
\xa6\xe4\x5d\x06\x5c\xc0\xc9\xaf\x16\x99\x5f\x4d\x5f\xad\xa6\xaf\
\xe6\x66\x4b\x0d\x35\xb3\x50\x68\xd5\x50\x4b\xa3\xa6\xaf\x56\x43\
\xcd\x05\x5c\x0d\x35\x17\x70\xa8\xa1\x96\x46\x4d\x5f\x0d\x35\xd4\
\xd2\xa8\x19\x96\xd1\xaa\xa1\xa6\x55\x43\xcd\x08\x1c\x6a\xe9\xad\
\xda\xb4\x4a\xf1\xfc\x61\x6b\x7c\xe5\x78\xbc\xff\x2d\x1d\xc7\x43\
\x9d\x44\xab\xee\xa0\x32\x26\x60\x1d\x41\x6d\x32\xa2\x76\x3f\xeb\
\xc5\x77\xdb\xc0\x6f\x7a\x45\x1d\xf8\x17\xba\xfc\xfe\xb3\x40\xf5\
\xa1\x4e\x8a\xda\x04\xaf\x6a\xfd\xd4\x6f\xa0\x86\xba\x58\xf4\x66\
\x6b\x50\x5f\x6d\xc4\xf5\xd5\xfa\x5a\x75\xff\xf1\x5d\xd4\xfd\xe7\
\x97\xd5\x57\x47\x52\x4f\xd3\x57\x8f\x34\x02\x8f\x39\x5e\x32\xb5\
\x3f\xee\xbc\xaf\x41\xed\xa1\x6a\x8c\xc0\x13\x6c\xd5\xca\xa9\x8b\
\x7e\xea\x02\x6a\xa8\xe7\xa2\xde\x2c\x4e\xed\x1f\x96\x41\x9d\x6c\
\xab\x0e\x8c\xc0\x87\x51\x1b\x45\xd4\xfe\x61\x59\x16\xd4\x46\x25\
\x75\x60\x04\x3e\x90\xfa\x0d\xd4\xb9\x50\x9b\x24\xa9\x37\x29\x5e\
\xc0\xf3\xec\xab\x53\xa7\xbe\x1e\x99\xda\x89\xc7\x51\x3b\xe7\x57\
\x7d\x01\x9f\xa6\xaf\x5e\x9f\x9d\x5f\xbd\x3f\xe8\xf0\x2a\x10\x2f\
\xac\xb8\xf5\x63\xf7\xfc\xd6\x41\x45\xc2\xf9\xd5\xed\xea\xb7\xe2\
\x45\xbb\xfa\x55\x7e\xb5\xf3\x63\x3b\xbf\xda\x5f\xfd\xd3\xf3\xab\
\x37\xe4\x57\x6b\xc9\xaf\xbe\x39\x3b\xbf\xfa\x61\x57\xea\x57\x81\
\xf8\x83\x15\xb7\x7e\xec\x9e\xdf\x3a\xe8\x21\xe1\xfc\xea\x76\xf5\
\xbd\xf1\xc3\x8b\x7d\xfe\xb4\xb7\xfa\xfb\xb8\xbf\xfa\x4b\xee\x5f\
\xbd\xeb\x98\xb6\x87\x57\xdb\x40\xbc\x7a\x51\xc5\x9b\x3f\xde\xba\
\xe7\xdf\x36\x0e\xea\x8a\x27\xd3\x57\xb7\xab\xef\x8d\x1f\x5e\xec\
\xfb\x6a\x6f\xf5\xf7\x8f\x50\xfc\xd5\x4f\xe7\x66\x2b\x10\x0f\x0c\
\xcb\x0a\x29\xc3\xb2\x40\x3c\x30\x2c\x73\xa9\x73\xb8\xaf\x86\x1a\
\x6a\xa8\x97\xa6\xde\x40\x4d\xab\x86\x1a\x6a\xa8\xa1\x86\x1a\x6a\
\xa8\xa1\x86\x9a\x11\x38\xd4\xb4\x6a\xa8\x69\xd5\x50\xcf\xdd\xaa\
\x4d\xf7\xd4\x84\xce\x59\x26\xad\xef\xee\xa1\xce\x8c\xba\x27\x67\
\xab\x2f\x7d\x2f\xf7\x09\x47\xed\x78\x47\xfd\x2e\x7f\x08\xe7\xa4\
\xe5\x72\x01\x8f\xa2\x8c\x8c\xe7\x48\xdd\x93\xb3\xb5\xa7\x0e\xd7\
\x3f\xf3\xc9\xc1\xba\xa8\xcd\x99\xd4\xd3\x4c\x23\x5c\x43\xad\x85\
\x7a\xb3\x44\x5f\x1d\x19\x87\x3a\xe7\xf4\xbc\xc2\xba\xd9\x8a\x38\
\xbf\xc8\xbe\x7a\xbb\x48\x5f\xbd\x81\x7a\x2c\xea\xee\x78\xbb\xfa\
\x8d\x9b\x2d\x1f\x95\x8c\xa4\x5b\xa8\x97\xa3\x9e\x7b\x2d\x94\xd3\
\xe2\x50\xa7\x4a\x3d\xd2\x08\x3c\x1f\x6a\xeb\xb3\x8e\xd5\x57\x77\
\x57\x3f\x9f\xc5\xac\x54\x50\x8f\x33\x02\x1f\x9b\x9a\x56\xad\x86\
\xfa\x66\xa1\x35\x46\x65\xf5\xd5\xd1\xd4\x45\xd6\xeb\x96\x45\xc7\
\x77\x1f\xfa\x90\xfb\x77\x17\xbb\xec\xcd\x09\xf1\xa4\xd7\x2d\xbb\
\xdc\xd7\xff\xf3\x2c\xfb\x6a\xe5\xd4\xd1\xf1\xb2\xbe\x77\x15\xf5\
\x97\xc6\x7f\xb3\x39\xe7\x2a\xff\x13\xed\x2f\xbd\x3b\xf9\x7d\x45\
\x7d\xef\xe6\x15\x4b\xdf\xbf\xba\xac\xef\x7d\x45\xfd\x95\xb7\xfa\
\xec\x5f\x4d\xc9\x69\xff\xea\x5d\xa6\xf0\x63\xf5\x69\x1e\xdf\xbb\
\x89\xc3\xc2\xf7\xaf\x2e\xeb\xfb\xf8\x72\x5f\xff\x27\x6f\xf5\xa7\
\xdb\xbf\x7a\xc6\xbe\x7a\x97\x33\x7c\xec\xab\x8f\x79\xc9\x4a\xfa\
\xea\x32\x65\xba\xee\xab\xbd\xd5\x17\xb1\x4d\x0b\xc3\xb2\x65\x87\
\x65\xdc\x57\xcf\x4a\x7d\x5b\x2d\x7b\x73\x2b\x85\x9a\x67\xe0\x3c\
\x03\xe7\xc1\xa8\xb4\x07\xa3\x50\xf3\x0c\x3c\x32\x0e\xf5\x14\xd4\
\x9b\x85\xf6\xee\x10\xfd\x75\xc7\xb9\x7d\x75\xd2\xad\x3a\xe6\x78\
\x6b\x04\x1e\x7d\xb3\x95\x07\xb5\x3f\xee\xbc\xaf\xfc\x66\x2b\xe3\
\x61\x99\x72\xea\xa2\x9f\xba\x63\xc2\x51\xcc\xcd\xd6\x88\xd4\x6b\
\xa8\xb5\x50\xcf\xd7\xaa\x87\x0f\xdb\xa0\x4e\x96\xfa\xf4\x11\x76\
\x77\x5c\x14\xf5\xf0\x47\x28\x59\x50\x1b\x95\xd4\xf1\x23\xf0\xb8\
\x9b\xad\xb1\xa9\x53\x4e\xba\x35\xb9\x52\x9b\x24\xa9\x17\x69\xd5\
\x5b\xa8\x63\xee\xab\xf3\xec\xab\x8b\x93\x1e\xa1\x48\xa5\xde\x8a\
\xa0\x1e\xb4\xec\x4d\x80\x32\x6b\xea\x6d\xe0\x37\x7d\xc0\x23\x14\
\xa8\xc5\x2c\x7b\xe3\xa3\xac\xd6\x42\x19\x9b\x7a\x03\xb5\x16\x6a\
\x5a\x35\xad\x1a\x6a\xa8\xa1\xe6\x02\x0e\x35\xd4\x50\x43\x0d\x35\
\xd4\x50\x33\x2c\x83\x9a\x56\x0d\xf5\x49\xad\x7a\xb6\xfd\xab\xbb\
\xf7\x6f\xae\xf7\xaf\x0e\xc5\x73\xd9\xbf\xda\xad\xc8\x71\xff\xea\
\xce\xea\x1d\xf7\xaf\xf6\xc6\xc9\xaf\xa6\x24\xbc\x7f\xb5\x7d\xb8\
\xb3\x7f\x75\x28\x2e\x61\xff\xea\xce\xea\x1d\xf7\xaf\xf6\xc5\x4f\
\xcd\xaf\xde\x2c\xb8\x7f\xf5\xd6\x3e\xdc\x3a\xbf\xb3\xed\x73\xaa\
\x7d\xf5\xe9\xfb\x57\x77\x57\xaf\xde\xbf\xda\x1f\x4f\x7b\xef\x8e\
\x9e\x61\x59\xf5\xea\x78\xfe\x5c\xa7\x26\x28\x19\x81\x9b\xf0\x2c\
\x94\x20\xb5\x98\x59\x28\xdd\x7b\x77\xf4\x50\x37\x7f\xd3\x4b\x6a\
\x93\xf8\x7d\xb5\x09\xcc\x2d\x1b\x46\x9d\xe5\xdc\x32\x13\x9e\x85\
\x12\xa4\xce\x6d\x16\x0a\xd4\xde\xb9\x65\x03\xa9\xdf\xd0\xaa\xa1\
\x3e\x87\x7a\x3d\xcb\x8c\xd1\xe2\xa4\xbe\xba\x80\x3a\xcf\x9c\x2d\
\x0f\x75\xdf\xf9\x33\x1b\x96\x75\xf6\xd5\xc5\x40\xea\xf4\x13\x79\
\x94\x53\x77\xc7\x9d\x37\x0e\x5a\xe5\x1f\x6a\xa8\x97\xa3\x6e\x7c\
\x1c\x37\x5e\xbe\xa7\x95\xdd\xe1\x9f\xf4\x2e\x79\xef\x0e\x19\xd4\
\x41\xaa\x26\x5a\x04\xb5\xc9\x8d\xda\x5a\x0b\xa6\x1d\xb7\x7f\xd3\
\x63\x96\x7e\x9f\x66\x81\x8c\xf5\xcc\x8b\x59\x49\xa5\x6e\x7c\xd6\
\xe0\xd2\xef\x0b\xae\xf2\xbf\x81\x7a\x7c\x6a\x93\x24\xf5\x0d\xd4\
\x50\x4f\xdc\x57\x1f\x3a\x2f\x11\xc3\xb2\x2c\xa8\xaf\xe7\x5b\x24\
\x7a\xae\x78\x16\x7d\xb5\xf7\x37\x7d\xba\x61\xd9\x06\xea\xf3\xa8\
\x87\xc7\xf7\xd4\x01\xaa\x64\x17\x89\x86\x1a\x6a\xa8\xd3\xa2\xe6\
\x02\x0e\x35\xd4\x50\x43\x9d\x29\x35\x37\x5b\x6a\xa8\x19\x96\x41\
\x0d\x35\xd4\x50\xd3\x57\x43\x4d\xab\x86\x3a\x09\xea\xf5\x7c\xfb\
\x57\xcf\x15\x4f\x74\xff\xea\x3a\x5e\xe6\x57\x87\xf2\xa3\xd9\xbf\
\x9a\xb2\x74\x7e\x75\x72\xf1\x44\xf7\xaf\x8e\xde\x9f\x5a\xc0\xfe\
\xd5\xf4\xd5\xcb\xf6\xd5\x8c\xc0\xd5\x50\xd3\xaa\xa1\x86\x5a\x1a\
\x35\xdf\x6c\x41\x0d\xb5\x34\xea\x35\xd4\x5a\xa8\xe9\xab\xa1\x86\
\x1a\x6a\xa8\xe9\xab\xa1\x4e\x9b\x9a\x11\x38\xd4\x50\x4b\xa3\xa6\
\xaf\xa6\x55\xe7\x42\xed\x66\x32\xbe\xfa\xdf\x36\x90\x08\x59\x51\
\x06\x92\x5e\x5f\x74\x2f\x46\x45\xab\x4e\x91\x3a\x9c\xdf\xdc\x4f\
\x6d\x44\x52\x67\xff\x25\x26\xd4\xaa\x2f\xe0\x50\xab\xa1\xde\x9e\
\x49\x2d\xb3\xaf\x16\x42\xdd\x8c\x77\x8f\xc0\xbb\xa8\xbb\xcf\xdf\
\x1c\x81\xd3\x57\xa7\x46\x5d\xf4\x53\x17\xea\xa9\x65\x8c\xc0\xa1\
\x86\x1a\x6a\xa8\xeb\xc3\xfc\xc3\x32\x69\xd4\x32\x86\x65\x8d\x16\
\xd8\x39\x02\x1f\x48\x6d\x44\x52\x0b\x6a\xd5\x81\xfb\x6a\xa8\xa1\
\xd6\x44\xcd\x05\x9c\xbe\x3a\x4f\xea\xa2\x3d\x2c\x8b\xa3\xb6\xce\
\xbf\x8b\x6b\xa1\xce\x2a\xbf\x7a\xff\x99\x9b\xfb\x47\xdb\xf9\xd5\
\x75\xfc\xf0\x62\x9f\x3f\x6d\xfd\xd8\xcd\xaf\xb6\x0e\x2a\xc8\xaf\
\xa6\x90\x5f\x3d\x67\xdc\xdd\x3f\xda\xce\xaf\x76\xf7\x8f\x2e\xf3\
\x9f\xad\x1f\xbb\xf9\xd1\xd6\x41\x0f\xe4\x57\x27\x11\x77\xf7\x8f\
\xb6\x1f\xa1\xb8\xfb\x47\x97\x7d\x75\xf3\xc7\xad\xfd\xa1\x77\xf1\
\xe6\xf6\xd2\xed\x38\x37\x5b\x69\x0e\xcb\x8a\x98\x61\x59\xa1\x62\
\x58\x26\xe8\x9b\x2d\xa8\x69\xd5\x50\xab\xb8\xaf\x86\x9a\x56\x0d\
\x35\xd4\x50\x43\x0d\x35\xd4\x50\x43\x0d\x35\xd4\x50\x43\x0d\x35\
\xd4\x50\x3b\xb3\x50\xba\xa7\x26\xf4\x24\xea\xe8\x98\x9a\x20\x72\
\x6e\x59\x60\x53\xe5\xce\xf4\x3b\x1d\x13\x8e\x74\x4c\x23\x1c\x48\
\xcd\x8c\x51\xa8\xa1\x86\x1a\xea\x85\xa8\xb7\x51\x7d\xb1\xb6\xbe\
\x5a\xd0\x97\x98\x87\x78\x20\x67\xab\x8c\xd7\x37\x5b\x9e\xf3\x4b\
\x4d\xcf\xcb\x7e\x35\x42\xa8\x69\xd5\x50\xb7\xa8\x45\x2e\x66\x35\
\x4e\x5f\xdd\xfd\x84\x05\xea\xa4\xa8\xc7\x19\x81\x43\x0d\x35\x7d\
\x35\xd4\x50\xcf\x4e\xcd\xba\x65\x22\x2f\xe0\x6e\x3c\x34\x02\xbf\
\x7b\xb1\xcf\x60\xfb\xa7\xf1\x0e\xc1\x59\x24\x1a\x6a\x89\xd4\x32\
\xf7\xaf\x2e\xeb\x76\x5f\x51\xff\x6b\x5f\x55\xf6\xaf\xa6\x48\xcc\
\xaf\xbe\x56\xb3\x7f\x75\x99\x28\xfd\x78\xb1\xff\xd7\xf8\xe0\xe6\
\x4d\x8b\xdf\xbf\x5a\xcf\xde\x1d\x65\xca\x74\xdd\x57\x1f\xd3\xb2\
\xd5\xf4\xd5\x7a\xa8\x19\x96\x71\x5f\xad\xe5\xbe\x9a\xa7\x65\x6a\
\x9e\x96\xc9\xf8\xbe\x1a\x6a\x5a\x35\xd4\x47\x6a\x91\x3b\xf2\x9c\
\xfb\x7d\x35\x5f\x62\x26\x4c\xdd\x8c\xc7\xec\xdd\xc1\xd4\x84\x5c\
\xa9\x8b\x7e\xea\x8e\x09\x47\x31\x37\x5b\x50\x43\x9d\x1f\xb5\xe6\
\x69\x84\xca\xa8\xd5\x4c\x0e\x3e\x6d\xca\x3f\x17\xf0\x24\xa9\xe3\
\x47\xe0\x71\x37\x5b\x50\xab\xca\xd9\x82\x5a\x05\xb5\x81\x3a\x7f\
\xea\xad\x4a\x6a\x35\xdb\xb4\x9c\xf0\x08\x05\x6a\x31\xcb\xde\x78\
\x28\xeb\x5f\x05\xa8\xa1\x86\x1a\xea\xa4\xa9\x35\xaf\x5b\x46\xab\
\x86\x9a\x56\x0d\x35\xd4\x50\x43\x0d\x75\x42\xd4\xf4\xd5\xb4\x6a\
\xa8\xa1\x86\x1a\x6a\xa8\xd3\xa6\xbe\x56\xbc\x7f\xb5\x7d\xb8\xb3\
\x7f\xb5\x2f\x4e\x7e\x35\x85\xfd\xab\x93\xdd\xbf\xda\x3e\xdc\xd9\
\xbf\x3a\x14\x67\xff\xea\x05\xe2\xa7\xef\x5f\xbd\xb5\x0f\xb7\xfa\
\x6a\xe7\x28\x01\x7d\xb5\xb4\xa9\x09\xdd\x7b\x77\xf4\x0c\xcb\xaa\
\x57\x47\x6a\x26\x1c\x25\x4d\x6d\xc2\xb3\x50\x82\xd4\x2a\x66\xa1\
\x88\xa4\x36\x67\x52\x33\x8d\x10\x6a\xa8\xa1\xce\x81\x5a\xc5\x8c\
\xd1\x62\x20\x35\x89\x3c\x89\x53\x1f\xe2\x81\xf4\x3c\x97\xba\xe3\
\xfc\xa4\xe7\x41\x4d\xab\x86\x9a\x56\x3d\x1f\x75\x53\xc3\xf9\x66\
\xab\x7c\x4f\x2b\xbb\x83\xf5\xc0\xf3\xa5\x6e\xb8\x9c\xbf\x44\x9d\
\x11\x49\xad\x6c\x31\x2b\xa8\xa1\x56\x40\xad\x6c\x47\x1e\xa8\x85\
\x51\x47\xf4\xd5\x87\x61\x1a\xc3\xb2\x7c\xa8\xdd\xb8\xe7\x66\xab\
\x8e\xf7\x2d\x02\xcd\x7a\xe0\x50\x43\x0d\x35\xd4\x50\x43\x0d\xf5\
\x12\xd4\x0c\xcb\xd4\x50\x67\xff\x0c\x1c\xea\x58\xea\xec\x97\x7e\
\x87\x3a\x96\x9a\x0b\xb8\x1a\x6a\x86\x65\x6a\xa8\xb9\x80\xab\xa1\
\xbe\x79\x0b\xb5\x16\x6a\x5a\xb5\xe6\x56\x2d\x73\xff\xea\xe8\xfd\
\xa9\xc5\xee\x5f\xfd\x96\xfc\x6a\x2d\xf9\xd5\x6f\xb5\xec\x5f\x3d\
\xdb\xfe\xd4\xc9\xe6\x57\x33\x2c\xd3\xdc\x57\x43\x2d\x92\xfa\x1a\
\x6a\x2d\xd4\xbf\x82\x5a\x0b\xf5\x06\x6a\xa8\xa1\x16\x46\xcd\xb0\
\x0c\x6a\xa8\xa5\x51\x33\x02\x57\x43\x4d\x5f\xad\x86\x9a\x0b\xb8\
\x9e\x56\xcd\x97\x98\x6a\x5a\x35\xd4\x50\x43\x2d\x8c\x9a\x0b\x38\
\xad\x3a\xf6\x9f\xda\xcd\x4f\x7e\xfe\xb0\x0d\xa4\x37\x57\xc7\x07\
\x52\xd9\xdd\xe3\x53\xa6\x76\x3f\xff\xc5\x77\xe1\xfa\x97\xd4\x81\
\xfa\x5f\x7e\xff\x59\xb0\xfe\x8b\x65\x77\x74\x51\x85\x57\x2d\xe8\
\xa7\x36\x99\x53\x87\xeb\xdf\x4f\xfd\x66\x12\xea\x1b\xa8\xa1\x86\
\x5a\x18\xf5\x66\xd6\xbe\x3a\x92\x5a\x6c\x5f\x1d\x49\x3d\x4d\x5f\
\x3d\x52\xab\xee\x3f\xbe\x8b\xba\xff\xfc\xb9\x50\xfb\xe3\x6e\xfd\
\x8f\xd4\x1e\xaa\xc6\x08\x3c\x3d\xea\x98\xe3\x25\x53\x17\xfd\xd4\
\x05\xd4\x50\x43\x0d\xf5\xc8\xd4\x9b\xa5\xa9\xfd\xc3\x32\x1d\xd4\
\xfe\x61\x59\xc2\xad\x3a\x30\x02\x1f\x48\x6d\xb2\xa4\x0e\x8c\xc0\
\x07\x52\xbf\x99\x84\xfa\x7a\x0a\x6a\xa3\x9c\xda\x24\x49\x7d\x03\
\x35\xd4\x0b\x5e\xc0\xf3\xec\xab\xc7\xbb\x80\xcf\xd7\x57\x9f\xb9\
\x7f\xb4\x15\x2f\xea\x78\x61\xc5\x9d\x1f\xdb\xe7\xb7\xa2\x45\xca\
\xf9\xd5\x6e\xfd\xad\x78\x47\xfd\xcb\xfc\xea\x40\xfd\x77\xf9\xd5\
\xa1\xfa\xb3\x7f\x35\x65\xea\xfd\xab\xdd\xfd\xa3\x3d\xf1\x07\x2b\
\x6e\xfd\xd8\x3d\xbf\x75\xd0\x43\xca\xf9\xd5\x6e\xfd\x3d\xf1\xba\
\xfe\x65\xfe\x74\xa0\xfe\xbb\x78\xa8\xfe\xa7\xe6\x57\x9f\x3d\x02\
\x77\xf7\x8f\xf6\xc4\xeb\xfd\xa3\xcb\x78\xf3\xc7\x5b\xf7\xfc\xcd\
\xed\xa5\xbb\xe2\xe9\xf4\xd5\x6e\xfd\x3d\xf1\xba\xfe\x65\x5f\x1d\
\xa8\xff\xee\x11\x4a\xa8\xfe\x89\x0c\xcb\x8a\x9e\x3d\x2b\xbb\x87\
\x65\xee\xf9\x73\x1d\x96\x05\xe2\x81\x61\x99\x4b\x9d\xc1\x08\x1c\
\xea\x74\xa9\xaf\xa1\xa6\x55\x43\x0d\x35\xd4\x50\x43\x0d\x35\xd4\
\x29\x50\x6f\xa0\xa6\x55\x43\x0d\x35\xd4\x50\x43\x0d\x35\xd4\x50\
\x43\x9d\x2f\xb5\x69\xc7\x8d\x7f\x96\x49\x6b\x96\x86\x08\x6a\xd3\
\x8e\x77\xd4\xff\xf2\x87\x70\xfd\xa7\xa2\x5e\xcf\x32\xe1\xa8\x73\
\xee\x98\x3f\x2e\x6e\xc2\x51\x8b\x3a\x5c\xff\xa9\x26\x1c\x6d\x66\
\x99\x46\x38\x90\xda\x64\x4e\x6d\xce\xa4\xce\x79\xc6\x28\xd4\x50\
\x43\x9d\x39\x75\x5f\x5f\x1d\x17\x97\xdb\x57\x6f\x17\xe9\xab\xd7\
\xb3\xe6\x6c\x1d\xe3\x4e\x0d\xba\x8f\xcf\x89\xba\x3b\xee\xd6\xbf\
\xbe\xd9\xf2\x51\x89\xc8\xc4\x84\x7a\x41\xea\x0d\xd4\xb4\xea\x21\
\xd4\x27\xf5\xc5\xf1\xf1\xe4\xa9\xad\x0f\x3b\x56\x5f\xed\xab\x7f\
\x26\x2b\x1c\x9d\x16\xcf\x8d\x7a\x9c\x11\x38\xd4\x50\xb3\x6e\x59\
\x0e\xd4\x85\xb4\x25\xea\x02\xeb\x76\x55\x19\x64\x6a\xd7\x2d\xbb\
\xdc\xd7\xff\xf3\x05\xfa\xea\xf5\x6c\x2b\x07\x97\x9f\xf9\x90\xe6\
\x79\x67\xbc\x43\x50\xa9\x2b\x07\xef\xeb\x5f\x51\x7f\x19\xa8\xff\
\x9c\x8b\x44\x4f\xb3\xbf\x74\x79\xee\xfb\x8a\xfa\x7e\xff\x57\x69\
\xda\xbf\x7a\x5f\xff\x8a\xfa\xab\x40\xfd\x27\xdb\xbf\x9a\xfc\x6a\
\xf2\xab\xc7\xde\x5f\xba\x4c\x14\x7e\xac\x3e\xcd\xa3\x9b\x37\x2c\
\x7d\xff\xea\x7d\xfd\x5f\xee\xeb\xff\x14\xa8\xff\x54\xfb\x57\x5f\
\xcf\xd6\x57\x97\x29\xc3\x75\x5f\x7d\x4c\x4b\xd6\xd2\x57\xef\xeb\
\x7f\xe8\xab\x03\xf5\xcf\x7f\xef\x0e\x86\x65\x0b\x0f\xcb\x66\xa6\
\xbe\xad\x86\x55\xb7\x4a\xa9\x6f\xab\x65\x6f\x6e\x73\xa4\xe6\x19\
\x38\xcf\xc0\x79\x30\xca\x33\x70\xa8\x97\xa1\xde\x40\x0d\xf5\x82\
\x7d\x75\xee\xd4\xe7\xf6\xd5\x49\x53\xf7\x1f\x5f\xbf\xaf\xce\xde\
\x90\x34\x2c\xf3\xc7\xdd\xfa\xef\xbe\xd9\xca\x77\x58\x16\x73\xfc\
\xe1\x7d\x83\x56\xf9\x2f\xf2\xa0\x2e\xfa\xa9\x3b\x26\x1c\xc5\xdc\
\x6c\x41\x0d\xf5\x52\x17\x70\xa8\x69\xd5\xad\xf7\x0d\x1a\xb6\xc9\
\xa2\x1e\xfe\x08\x65\x6c\xea\x24\x33\x31\x4d\x96\xd4\xf1\x23\xf0\
\xb8\x9b\xad\xb1\xa9\xaf\xd3\xce\xd9\xca\x93\xda\x24\x49\x9d\x70\
\xd2\xad\x51\x4e\x6d\x24\x50\x6f\x95\x53\x6f\xe5\x50\x77\x2d\x00\
\x71\xc2\x23\x14\x39\x7d\x75\x71\xd2\x23\x94\xb4\xa9\x8b\x21\xcb\
\xde\x04\x28\x73\xa5\x2e\x86\x2c\x7b\xe3\xa3\xac\xd6\x42\x19\x9b\
\x7a\x0d\xb5\x16\x6a\x5a\xb5\x1a\xea\x1b\xa8\xa1\x86\x1a\x6a\xa8\
\xa1\x86\x9a\x61\x19\xd4\x29\x50\x73\xb3\xc5\x05\x1c\x6a\xa8\xa1\
\x16\x44\x3d\xe6\xfe\xd5\xee\x46\xcd\xc7\xfd\xab\x3b\xb7\x6f\x3e\
\xee\x5f\x1d\x8a\x67\xb3\x7f\x75\x47\xfd\xeb\xfd\xab\x3d\xf5\x3b\
\xec\x5f\xed\x8d\x93\x5f\x4d\x49\x77\xff\x6a\xfb\x70\x67\xff\xea\
\x50\x5c\xc4\xfe\xd5\x9e\xfa\x1d\xf6\xaf\xf6\xc5\x4f\xcd\xaf\xbe\
\x59\x6e\xff\xea\xad\x7d\xb8\x75\x7e\xe7\xa8\x64\xfb\xea\xd3\xf7\
\xaf\xf6\xd5\xaf\xda\xbf\xda\x1f\x67\x58\xc6\xb0\x6c\x56\x6a\xcf\
\xde\x1d\x3d\xd4\xd5\xab\xe3\xf9\xf3\x9d\x9a\xd0\xbd\x77\x47\x0f\
\xb5\x5d\xff\x8f\xd4\x26\x6d\x6a\x13\x9e\x85\x12\xa4\x96\x30\x0b\
\xc5\x84\x67\xa1\x04\xa9\x67\x99\x85\x32\x09\xb5\x39\x93\x3a\xcb\
\xb9\x65\x26\x30\xb7\x6c\x20\x75\xea\x73\xcb\xa0\x4e\x9c\x9a\x56\
\x4d\xab\x1e\x4c\x1d\x98\x31\x5a\x9c\xd4\x57\x17\x79\x51\x07\x66\
\x8c\x16\x27\xf5\xd5\x45\xb2\xad\xba\xef\xf8\x6e\xea\xbe\xf3\x67\
\x44\xdd\x1d\x77\xeb\x3f\x64\x95\xff\x7c\x33\x31\xa1\x5e\x90\x9a\
\x56\xad\x86\x7a\x3d\xd2\x5a\x28\x81\x78\xf9\x9e\x56\x76\x87\xb8\
\xf5\xc0\x03\xf1\x76\xfd\xfb\x97\x7e\x9f\x66\x81\x8c\x99\x97\xbd\
\x89\xa3\x36\xf9\x51\x37\x3e\x6c\x70\xe9\x77\x69\xab\xfc\x1b\xe5\
\xd4\x06\x6a\xa8\xa1\x86\x3a\x57\xea\x88\xbe\xfa\x30\x4c\x91\x32\
\x2c\x1b\xda\x57\x07\xea\x9f\xec\xba\x65\xe9\xc5\x13\x5d\x24\xba\
\x8e\xef\xa9\x03\x54\xd9\xaf\x07\x0e\x35\xd4\x50\x43\x0d\x35\xd4\
\x50\x9f\x42\xbd\x81\x5a\x0b\xf5\x35\xd4\x5a\xa8\xb9\x80\xab\xa1\
\x5e\x43\xad\x85\x9a\xbe\x5a\x0d\x35\x17\x70\x5a\x35\xd4\x1a\xa8\
\xa7\xd9\xbf\x7a\xb6\x78\xa2\xfb\x57\xd7\xf1\x32\xbf\x3a\x94\x1f\
\x3d\xd1\xfe\xd5\x1b\xf2\xab\xc9\xaf\x1e\x7b\xff\xea\xd9\xe2\x89\
\xee\x5f\x1d\xbd\x3f\xf5\x54\xfb\x57\xd3\x57\xab\xe9\xab\xb9\xaf\
\x86\x1a\x6a\x69\xd4\xdc\x57\xd3\xaa\xa1\xa6\x55\x43\x0d\x35\xd4\
\x69\x53\x73\xb3\x05\x35\xd4\xd2\xa8\xb9\x80\xab\xa1\x66\x04\x4e\
\xab\x86\x1a\x6a\xa8\x19\x96\x41\x4d\xab\x86\x1a\x6a\xa8\xa1\x86\
\x7a\x02\x6a\xfa\x6a\x35\xd4\x24\xf2\xa8\xa1\xe6\x11\x0a\xd4\x50\
\x4b\xa3\x66\x58\x06\x35\xd4\x50\x43\xcd\x08\x1c\x6a\x5a\x35\xd4\
\x50\x43\x0d\x35\xd4\x50\x43\x3d\xee\x23\x14\xf2\xab\x45\xe6\x57\
\xb3\x7f\xb5\x9a\xfc\x6a\xf7\x9b\xad\xdb\xbb\xf7\x94\xac\xcb\x43\
\x6c\xab\xa6\x88\x2b\xbe\x56\x4d\x81\x9a\x92\x37\x35\x17\x70\xa8\
\x29\xd2\xa8\xb9\x80\x43\x4d\x91\x46\xcd\x05\x1c\x6a\x0a\xd4\x94\
\x4c\xa9\xe9\xab\x69\xd5\x14\xa8\x29\x50\x53\xd2\xa6\xfe\xc3\x17\
\xef\x6e\x29\xd2\x4b\x49\xfd\xdb\x77\xaf\xff\x4c\x91\x5e\xfe\xf2\
\xc7\x8f\xd4\x7f\xfa\xeb\x6f\x7e\x4e\x91\x5f\x9e\x51\xd4\x94\xff\
\x03\x73\xd7\xf7\xa6\x7f\xf2\xb1\x43\x00\x00\x00\x00\x49\x45\x4e\
\x44\xae\x42\x60\x82\
\x00\x00\x03\xa5\
\x89\
\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52\x00\
\x00\x00\x1f\x00\x00\x00\x1f\x08\x06\x00\x00\x00\x1f\xae\x16\x39\
\x00\x00\x00\x01\x73\x52\x47\x42\x02\x40\xc0\x7d\xc5\x00\x00\x00\
\x09\x70\x48\x59\x73\x00\x00\x0e\xc4\x00\x00\x0e\xc4\x01\x95\x2b\
\x0e\x1b\x00\x00\x00\x19\x74\x45\x58\x74\x53\x6f\x66\x74\x77\x61\
\x72\x65\x00\x4d\x69\x63\x72\x6f\x73\x6f\x66\x74\x20\x4f\x66\x66\
\x69\x63\x65\x7f\xed\x35\x71\x00\x00\x03\x25\x49\x44\x41\x54\x58\
\xc3\xc5\x97\xc1\x4e\xdb\x40\x10\x86\xad\xaa\x2d\x46\x45\x8a\x53\
\xa5\x4e\x40\x58\x38\x15\x52\x02\x17\xea\xb4\x6a\x31\xb4\x22\x51\
\x51\x65\xac\xaa\xaa\xe0\x54\x6e\xe5\x06\x57\x1f\x7b\xca\x39\xaf\
\xe1\x47\xc8\x35\x8f\x90\x57\xc9\xd1\xd7\xed\xfe\x1b\xef\x7a\x6c\
\xaf\x43\x12\x52\xf5\x30\x22\x64\xe3\xfd\x66\xfe\x99\xd9\x1d\x1b\
\xc3\xe1\xd0\xf8\x5f\xb6\xf4\x0f\x83\xef\x81\x17\x7c\x0b\xa2\xde\
\xfb\x5e\xec\x7d\xf0\xa6\x9d\xe3\xce\xcc\xed\xba\xcc\x3d\x74\x67\
\x6e\xc7\x9d\xb6\x0f\xdb\xf1\xc1\xdb\x83\xc8\x39\x76\xbc\x8d\xc1\
\x6f\x7e\xdc\x84\x67\xfd\xb3\xf8\xa4\x77\x92\x78\xa7\x1e\xf3\xde\
\x65\x76\xd4\x3d\x62\xc2\x01\x77\x6e\xad\x56\x8b\xd5\x5e\xd7\x12\
\xd3\x32\x63\xe3\xa5\x11\xae\x0d\x8f\xfe\x44\xee\x55\x70\x35\xf2\
\x3f\xfb\x89\x7f\xea\x33\xd8\x20\x18\xb0\x30\x08\xd9\xf5\xcf\x6b\
\x65\x83\xcb\x81\x58\x83\x33\x70\xc0\x6a\x58\xcc\xb2\x2c\x56\xab\
\xd5\x92\xad\xfa\xd6\xc8\x30\x0c\x77\x25\x78\xbf\xdf\xf7\x39\x68\
\x2c\xa0\x7d\x5f\x40\x6e\x7f\xdd\xb2\xbb\xdf\x77\xc2\xf0\x59\x80\
\xb9\x33\x02\xde\x9f\x3b\x07\x65\x84\x1a\x70\x82\x3b\x60\x9a\x26\
\xdb\x7e\xb5\x3d\xe6\x0e\xf8\x4b\xc1\x01\xbe\xf8\x7a\x31\xc1\x86\
\xd8\x1c\xb0\x87\xfb\x07\x61\x12\x8a\xe8\xb1\x86\xdf\x88\x54\x14\
\xd2\x41\x55\x80\x03\xc6\x73\x63\xa2\x73\xa0\x24\x35\x97\x59\x44\
\x0c\x88\x84\x16\xc1\x34\x52\x05\x43\xee\xa9\xa5\x75\x20\x15\xe0\
\x0e\x8c\x8b\x29\xc8\xc1\xfd\x2f\xfe\x48\xe4\xf6\x32\x8b\xb8\x28\
\xb3\x8a\x96\x16\x1c\x81\x89\xc2\xdb\x6f\xa9\xbf\x28\xc2\x14\xce\
\x38\x7c\xa4\x85\x7b\x9f\xbc\x10\x15\x0d\x38\x60\x25\xb0\x2c\xac\
\x53\x7d\xa5\x53\x98\x34\x51\x7c\x99\xf4\xb0\x84\x3b\x10\x96\xe0\
\xbd\x8f\xbc\x7f\xf9\xc6\x32\xcf\xb9\xfc\x92\x8a\x56\x12\x57\x40\
\x25\x50\x99\x65\x51\xe9\x99\xf1\xc2\x88\x73\x70\x1c\x20\xb2\x8f\
\x65\x65\x97\x8a\x4a\xd7\xd7\x80\xea\xc0\x56\x1e\x2a\x8d\x44\xef\
\x29\x38\x97\x3c\xc2\xe6\xb2\xd0\x74\xd1\x2e\x02\x3f\x06\x2d\xc0\
\x91\xfb\x48\xc1\x71\x64\x62\x73\x44\x29\xab\x99\x46\xbb\x0a\x58\
\x07\x2d\x39\x90\x4a\x2f\xe0\x38\x9b\x05\x3c\x3d\x54\x36\x25\x73\
\x25\xfc\x99\x31\xcd\xe0\xb8\x1c\xf8\xe6\xb4\x9a\x97\x82\xae\x08\
\x26\xd2\xcf\x14\x5c\xf6\x65\x25\xb8\xb5\x19\x30\xcd\xbb\x82\xdb\
\xb6\x3d\x03\x84\xca\xac\xcd\xeb\x13\xc1\xc4\x81\x2c\x72\xcb\xb6\
\xa6\xd8\x30\xd7\xbb\x8f\x44\xba\x2e\x58\xc0\x69\xce\xcd\x1d\x33\
\xc6\xe6\xea\x58\xac\x28\xa6\x75\xa0\xba\xe7\x72\xd5\x5e\xaf\xd7\
\x23\xb1\x98\x3a\xb0\x4e\x0b\x2d\x04\x93\x63\x56\xc0\x4d\xd2\xe7\
\xfc\x1f\x8f\x7f\x99\x60\x41\xc9\xbd\x01\x79\xb5\xf0\x1d\x33\x01\
\x2f\x77\xb6\x43\x0a\xf5\xd0\x13\xa2\x2e\x02\x45\x30\xfb\xe4\x92\
\xe1\x23\x56\xe9\x62\xc1\xcc\x25\xa3\x57\x0f\xaf\x18\x79\x09\x2c\
\x3b\x26\x85\x63\xbe\xdb\x75\x76\x43\xed\x7d\xce\x5b\x60\x94\xdb\
\xa8\x91\x81\x17\x39\x90\x4b\x11\x89\xb6\xd8\x39\xfc\xbb\x51\xe5\
\x30\x81\x49\x03\x13\x47\x55\xa5\x56\x5a\x23\x2f\xb3\xf6\xba\xdd\
\x6f\x8d\xcf\xcf\xcf\xdd\x85\x33\x1c\x66\x2d\xcc\x5c\x0b\x1d\x20\
\x20\x15\x29\x85\x16\x0e\x2a\xfe\x79\xe2\x38\x8e\xbf\xd4\xf4\x0a\
\x07\x30\x75\x96\x52\xd0\x28\x47\x49\x00\xe5\x43\x6a\xbe\x36\xd6\
\x81\x17\xce\xed\x48\x01\xe6\x6e\xb4\x06\x75\x80\xe4\xaf\x2c\x6f\
\x26\x31\xb3\xf7\xec\x04\x39\x2e\x4a\xbd\xd2\x1b\x8b\xe8\x02\xde\
\x1e\x78\x09\x28\x45\x4d\x2d\x05\x03\xda\xee\xb6\x63\x5a\xd5\x4f\
\x7e\x57\xc3\xc1\x50\x7f\x53\x8f\x9a\xcd\x66\x9c\xde\x05\x33\x01\
\xe3\x97\x92\xed\xd8\xd3\xe6\x5e\x73\xf3\xef\x6a\xff\xd2\xfe\x02\
\x0a\x58\xf5\x53\x11\x2f\x5c\x80\x00\x00\x00\x00\x49\x45\x4e\x44\
\xae\x42\x60\x82\
"
qt_resource_name = "\
\x00\x05\
\x00\x7d\xf0\xa5\
\x00\x77\
\x00\x68\x00\x69\x00\x74\x00\x65\
\x00\x0a\
\x0a\x94\x65\x04\
\x00\x63\
\x00\x68\x00\x65\x00\x73\x00\x73\x00\x62\x00\x6f\x00\x61\x00\x72\x00\x64\
\x00\x05\
\x00\x69\x27\x9b\
\x00\x62\
\x00\x6c\x00\x61\x00\x63\x00\x6b\
"
qt_resource_struct = "\
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x01\
\x00\x00\x00\x2a\x00\x00\x00\x00\x00\x01\x00\x00\x15\x30\
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\
\x00\x00\x00\x10\x00\x00\x00\x00\x00\x01\x00\x00\x03\x96\
"
def qInitResources():
QtCore.qRegisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
def qCleanupResources():
QtCore.qUnregisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
qInitResources()
| python |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
class TestTest(unittest.TestCase):
# @unittest.skip("skip this test")
def test_bench(self):
from tocoli.test import bench, Bencher
# Test 1 - add()
def add(a, b):
return a + b
res = bench(add, 2, 3)
self.assertEqual(res, 5)
b = Bencher(rounds=2)
res = b.bench(add, 1 + 1, 3)
self.assertEqual(res, 5)
b = Bencher(rounds=3, collect=True)
res = b.bench(add, 1 + 1, 3)
self.assertEqual(res, [5, 5, 5])
b = Bencher(stopwatch=False)
res = b.bench(add, 2, 3)
self.assertEqual(res, 5)
# Test 2 - echo()
def echo(a):
return a
res = bench(echo, 'a')
self.assertEqual(res, 'a')
res = bench(echo, 1)
self.assertEqual(res, 1)
res = bench(echo, (1, 2))
self.assertEqual(res, (1, 2))
res = bench(echo, [1, 2])
self.assertEqual(res, [1, 2])
# sleep
from time import sleep
b = Bencher(rounds=10, precision='.10')
res = b.bench(sleep, 0.001)
self.assertEqual(res, None)
# @unittest.skip("skip this test")
def test_fnprint(self):
from tocoli.test import fnprint
def concat(a, b, c):
return str(a) + str(b) + str(c)
fnprint(concat, a='aaa', b='b', c='c')
def mult(a, b):
return a * b
fnprint(mult, 2, 5)
if __name__ == '__main__':
unittest.main()
| python |
import os
def start_preparation_st(test_data_path, data_root, src_lang, tgt_lang):
os.system(test_data_path +
" --data-root " + data_root +
" --vocab-type char"
" --src-lang " + src_lang +
" --tgt-lang " + tgt_lang)
def start_preparation_asr(test_data_path, data_root, src_lang):
os.system(test_data_path +
" --data-root " + data_root +
" --vocab-type char"
" --src-lang " + src_lang)
test_data_path_covost = "../examples/speech_to_text/prep_covost_data.py"
data_root_prefix = "/Users/bdubel/Documents/ZHAW/BA/data/"
data_root_covost = data_root_prefix + "covost"
src_lang_sv = "sv-SE"
tgt_lang_en = "en"
start_preparation_st(test_data_path_covost, data_root_covost, src_lang_sv, tgt_lang_en)
| python |
from .query import *
| python |
# -*- coding: utf-8 -*-
import base64
import json
from watson_developer_cloud import ConversationV1
class FarmerConversation:
def __init__(self):
pass
def converse(self, text):
conversation = ConversationV1(
username='a5f91c9c-12e8-4809-9172-6f68ed4b01d3',
password='mLvAkRPDUWZm',
version='2016-09-20')
workspace_id = '769ec18f-f67b-4d40-9611-8ce3487545da'
response = conversation.message(workspace_id=workspace_id, message_input={'text': text})
print json.dumps(response)
intent = response["intents"][0]["intent"]
if intent == "TipOfTheDay" or intent == "NewWord":
entity_type = "None"
entity_value = "None"
else:
entity_type = response["entities"][0]["entity"]
entity_value = response["entities"][0]["value"]
data_json = {"intent": intent, "entity_type": entity_type, "entity_value": entity_value}
return json.dumps(data_json)
| python |
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# Generated file, DO NOT EDIT
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------------------------
from msrest.serialization import Model
class MavenPomPerson(Model):
"""MavenPomPerson.
:param email:
:type email: str
:param id:
:type id: str
:param name:
:type name: str
:param organization:
:type organization: str
:param organization_url:
:type organization_url: str
:param roles:
:type roles: list of str
:param timezone:
:type timezone: str
:param url:
:type url: str
"""
_attribute_map = {
'email': {'key': 'email', 'type': 'str'},
'id': {'key': 'id', 'type': 'str'},
'name': {'key': 'name', 'type': 'str'},
'organization': {'key': 'organization', 'type': 'str'},
'organization_url': {'key': 'organizationUrl', 'type': 'str'},
'roles': {'key': 'roles', 'type': '[str]'},
'timezone': {'key': 'timezone', 'type': 'str'},
'url': {'key': 'url', 'type': 'str'}
}
def __init__(self, email=None, id=None, name=None, organization=None, organization_url=None, roles=None, timezone=None, url=None):
super(MavenPomPerson, self).__init__()
self.email = email
self.id = id
self.name = name
self.organization = organization
self.organization_url = organization_url
self.roles = roles
self.timezone = timezone
self.url = url
| python |
import re
def do_selection_sort(in_list: list):
for i in range(len(in_list)):
print(f'Step {i}: {in_list}')
minimum = i
for j in range(i, len(in_list)):
if in_list[j] < in_list[minimum]:
minimum = j
in_list[i], in_list[minimum] = in_list[minimum], in_list[i]
if __name__ == "__main__":
in_str = input('Enter a list of number\n'
'format: 1, 2, 3\n'
'enter: ')
m = list(map(int, re.findall(r'\d+|-\d+', in_str)))
do_selection_sort(m)
| python |
# standard library
import warnings
import pdb
# 3rd party library
from torch import nn as nn
# mm library
from mmcv.cnn import build_conv_layer
# gaia lib
from gaiavision.core import DynamicMixin
from gaiavision.core.bricks import build_norm_layer, DynamicBottleneck
class DynamicResLayer(nn.ModuleList, DynamicMixin):
"""ResLayer to build ResNet style backbone.
Args:
block (nn.Module): block used to build DynamicResLayer.
inplanes (int): inplanes of block.
planes (int): planes of block.
depth (int): number of blocks.
stride (int): stride of the first block. Default: 1
avg_down (bool): Use AvgPool instead of stride conv when
downsampling in the bottleneck. Default: False
conv_cfg (dict): dictionary to construct and config conv layer.
Default: None
norm_cfg (dict): dictionary to construct and config norm layer.
Default: dict(type='BN')
downsample_first (bool): Downsample at the first block or last block.
False for Hourglass, True for ResNet. Default: True
"""
search_space = {'depth', 'width'}
def init_state(self, depth=None, width=None, **kwargs):
# reserved state
if depth is not None:
self.depth_state = depth
if width is not None:
self.width_state = depth
for k, v in kwargs.items():
setattr(self, f'{k}_state', v)
def __init__(self,
block,
inplanes,
planes,
depth,
stride=1,
avg_down=False,
conv_cfg=None,
norm_cfg=None,
downsample_first=True,
**kwargs):
# TODO: fix the workaround
if conv_cfg['type'] != 'DynConv2d':
warnings.warn('Non-dynamic-conv detected in dynamic block.')
if 'Dyn' not in norm_cfg['type']:
warnings.warn('Non-dynamic-bn detected in dynamic block.')
self.block = block
self.avg_down = avg_down
# TODO: support other states
self.init_state(depth=depth, width=planes)
# build downsample branch
downsample = None
if stride != 1 or inplanes != planes * block.expansion:
downsample = []
conv_stride = stride
if avg_down:
conv_stride = 1
downsample.append(
nn.AvgPool2d(kernel_size=stride,
stride=stride,
ceil_mode=True,
count_include_pad=False))
downsample.extend([
build_conv_layer(conv_cfg,
inplanes,
planes * block.expansion,
kernel_size=1,
padding=0,
stride=conv_stride,
bias=False),
build_norm_layer(norm_cfg, planes * block.expansion)[1]
])
downsample = nn.Sequential(*downsample)
layers = []
if downsample_first:
layers.append(
block(inplanes=inplanes,
planes=planes,
stride=stride,
downsample=downsample,
conv_cfg=conv_cfg,
norm_cfg=norm_cfg,
**kwargs))
inplanes = planes * block.expansion
for _ in range(1, depth):
layers.append(
block(inplanes=inplanes,
planes=planes,
stride=1,
conv_cfg=conv_cfg,
norm_cfg=norm_cfg,
**kwargs))
else: # downsample_first=False is for HourglassModule
for _ in range(depth - 1):
layers.append(
block(inplanes=inplanes,
planes=inplanes,
stride=1,
conv_cfg=conv_cfg,
norm_cfg=norm_cfg,
**kwargs))
layers.append(
block(inplanes=inplanes,
planes=planes,
stride=stride,
downsample=downsample,
conv_cfg=conv_cfg,
norm_cfg=norm_cfg,
**kwargs))
super(DynamicResLayer, self).__init__(layers)
def manipulate_depth(self, depth):
assert depth >= 1, 'Depth must be greater than 0, ' \
'skipping stage is not supported yet.'
self.depth_state = depth
def manipulate_width(self, width):
self.width_stage = width
for m in self:
m.manipulate_width(width)
def deploy_forward(self, x):
# remove unused layers based on depth_state
del self[self.depth_state:]
for i in range(self.depth_state):
x = self[i](x)
return x
def forward(self, x):
if getattr(self, '_deploying', False):
return self.deploy_forward(x)
for i in range(self.depth_state):
x = self[i](x)
return x
| python |
import csv
import os
# from utility import uprint
import pandas as pd
def extract_stat_names(dict_of_stats):
"""Extracts all the names of the statistics
Args:
dict_of_stats (dict): Dictionary containing key-alue pair of stats
"""
stat_names = []
for key, val in dict_of_stats.items():
stat_names += [key]
return stat_names
def parse_top_players(data, base_filename):
rows = []
for event in data["events"]:
gw = event["id"]
player_id = event["top_element"]
points = event["top_element_info"]["points"]
row = {}
row["gw"] = gw
row["player_id"] = player_id
row["points"] = points
rows += [row]
f = open(os.path.join(base_filename, "best_players.csv"), "w+", newline="")
w = csv.DictWriter(f, ["gw", "player_id", "points"])
w.writeheader()
for row in rows:
w.writerow(row)
def parse_players(list_of_players, base_filename):
stat_names = extract_stat_names(list_of_players[0])
filename = base_filename + "players_raw.csv"
os.makedirs(os.path.dirname(filename), exist_ok=True)
f = open(filename, "w+", encoding="utf8", newline="")
w = csv.DictWriter(f, sorted(stat_names))
w.writeheader()
for player in list_of_players:
w.writerow(
{k: str(v).encode("utf-8").decode("utf-8") for k, v in player.items()}
)
def parse_player_history(list_of_histories, base_filename, player_name, Id):
if len(list_of_histories) > 0:
stat_names = extract_stat_names(list_of_histories[0])
filename = base_filename + player_name + "_" + str(Id) + "/history.csv"
os.makedirs(os.path.dirname(filename), exist_ok=True)
f = open(filename, "w+", encoding="utf8", newline="")
w = csv.DictWriter(f, sorted(stat_names))
w.writeheader()
for history in list_of_histories:
w.writerow(history)
def parse_player_gw_history(list_of_gw, base_filename, player_name, Id):
if len(list_of_gw) > 0:
stat_names = extract_stat_names(list_of_gw[0])
filename = base_filename + player_name + "_" + str(Id) + "/gw.csv"
os.makedirs(os.path.dirname(filename), exist_ok=True)
f = open(filename, "w+", encoding="utf8", newline="")
w = csv.DictWriter(f, sorted(stat_names))
w.writeheader()
for gw in list_of_gw:
w.writerow(gw)
def parse_gw_entry_history(data, outfile_base):
for gw in data:
picks = gw["picks"]
event = gw["entry_history"]["event"]
filename = "picks_" + str(event) + ".csv"
picks_df = pd.DataFrame.from_records(picks)
picks_df.to_csv(os.path.join(outfile_base, filename), index=False)
def parse_entry_history(data, outfile_base):
chips_df = pd.DataFrame.from_records(data["chips"])
chips_df.to_csv(os.path.join(outfile_base, "chips.csv"))
season_df = pd.DataFrame.from_records(data["past"])
season_df.to_csv(os.path.join(outfile_base, "history.csv"))
# profile_data = data["entry"].pop('kit', data["entry"])
# profile_df = pd.DataFrame.from_records(profile_data)
# profile_df.to_csv(os.path.join(outfile_base, 'profile.csv'))
gw_history_df = pd.DataFrame.from_records(data["current"])
gw_history_df.to_csv(os.path.join(outfile_base, "gws.csv"), index=False)
def parse_entry_leagues(data, outfile_base):
classic_leagues_df = pd.DataFrame.from_records(data["leagues"]["classic"])
classic_leagues_df.to_csv(os.path.join(outfile_base, "classic_leagues.csv"))
try:
cup_leagues_df = pd.DataFrame.from_records(data["leagues"]["cup"]["matches"])
cup_leagues_df.to_csv(os.path.join(outfile_base, "cup_leagues.csv"))
except KeyError:
print("No cups yet")
h2h_leagues_df = pd.DataFrame.from_records(data["leagues"]["h2h"])
h2h_leagues_df.to_csv(os.path.join(outfile_base, "h2h_leagues.csv"))
def parse_transfer_history(data, outfile_base):
wildcards_df = pd.DataFrame.from_records(data)
wildcards_df.to_csv(os.path.join(outfile_base, "transfers.csv"), index=False)
def parse_fixtures(data, outfile_base):
fixtures_df = pd.DataFrame.from_records(data)
fixtures_df.to_csv(os.path.join(outfile_base, "fixtures.csv"), index=False)
def parse_team_data(data, outfile_base):
teams_df = pd.DataFrame.from_records(data)
teams_df.to_csv(os.path.join(outfile_base, "teams.csv"), index=False)
| python |
# Created by wangmeng at 2020/11/19
from toolkit.models.base_host import BaseHost
from toolkit.models.host import Host
from toolkit.models.operator import HostOperator
async def get_host_info_by_label(label: str) -> dict:
operator = HostOperator('localhost', 27017)
host_info = await operator.get_host_info_by_filter({'label': label})
if not host_info:
return None
target_host = Host(**host_info)
return target_host.to_dict()
async def insert_new_host_info(host: BaseHost) -> bool:
operator = HostOperator('localhost', 27017)
await operator.insert_host_info(host.to_dict())
return True
| python |
# -*- coding: UTF-8 -*-
from redis import ConnectionPool, Redis
from redlock import RedLockFactory
class RedisDB(object):
"""
Redis数据库连接池和Redis分布式锁统一获取入口,当前Redis只支持单节点,可以通过简单修改支持Redis集群
"""
def __init__(self, nodes):
assert len(nodes) > 0
self.__nodes = nodes
self.__redis_pool = ConnectionPool(host=nodes[0]['host'], port=nodes[0]['port'])
self.__redis_lock = RedLockFactory(connection_details=nodes)
@property
def client(self):
"""
从Redis连接池中获取Redis客户端实例
:return: Redis客户端实例
"""
return Redis(connection_pool=self.__redis_pool)
@property
def lock(self):
"""
从Redis分布式锁工厂中获取实例,用于对并发处理的资源进行安全操作
:return: Redis分布式锁实例
"""
return self.__redis_lock
@property
def nodes(self):
"""
获取Redis节点信息
:return: Redis节点信息
"""
return self.__nodes
if __name__ == '__main__':
NODES = [
{'host': '127.0.0.1', 'port': 6379},
]
redisDB = RedisDB(NODES)
redisDB.client.rpush('a1', 'bbb')
redisDB.client.hset('a2', 'ip', bytes([127, 0, 0, 1]))
import json
redisDB.client.hset('a3', 'ips', json.dumps({'ip': [127, 0, 0, 1]}))
res = redisDB.client.sadd('s1', 5)
print(res)
redisDB.client.flushall()
| python |
import sys
import random
from math import sqrt, log
import subprocess32, struct
U = 0.5
C = sqrt(2)
samples = 10
max_rounds = 100
total = 0
max_iterations = 10
class Node():
def __init__(self, path):
assert(path)
self.addr = path[-1]
self.path = path
self.children = {}
self.distinct = 1
self.visited = 1
def update(self, distinct, visited):
self.distinct += distinct
self.visited += visited
def insert(self, suffix):
if suffix:
pos = suffix[0]
rest = suffix[1:]
if not pos in self.children:
path = self.path + (pos,)
child = Node(path)
self.children[pos] = child
else:
child = self.children[pos]
child.insert(rest)
def pp(self, indent=0):
i = " " * indent
s = i
s += hex(self.addr)
s += " "
s += "(" + str(self.distinct) + "/" + str(self.visited) + ")"
s += " "
s += "uct = " + str(uct(self))
s += " "
print(s)
if len(self.children) > 1:
indent += 1
for child in self.children.values():
child.pp(indent)
def generate_random(seed):
bytes = [ random.randint(0, 255) for x in seed ] # WTF Python: range is inclusive
input = "".join(map(chr, bytes))
return input
def mutate(prefix, program, seed, samples):
global max_rounds
result = []
rounds = 0
print('generating inputs for prefix ' + str(map(hex, prefix)))
while len(result) < samples and rounds < max_rounds:
rounds += 1
input = generate_random(seed)
path = program(input)
n = len(prefix)
if path[:n] == prefix:
print('using input "' + input + '" with path ' + str(map(hex, path)))
result.append(path)
else:
print('discarding input with path ' + str(map(hex, path)))
return result
def uct(node):
global total
assert(total > 0)
assert(node.visited > 0)
exploit = node.distinct / node.visited
explore = sqrt(log(total) / node.visited)
return exploit + C * explore
def dice():
return random.random()
def sample(node, program, seed):
global total, samples
if not node.children or dice() < U:
suffixes = playout(node, program, seed, samples)
node.distinct += len(suffixes)
node.visited += samples
total += samples
for suffix in suffixes:
node.insert(suffix)
else:
child = max(node.children.values(), key=uct)
return sample(child, program, seed)
def playout(node, program, seed, samples):
prefix = node.path
n = len(prefix)
paths = mutate(prefix, program, seed, samples)
suffixes = { p[n:] for p in paths }
return suffixes
def traced(binary): # curry the input argument + convert result to immutable tuple
def with_input(input):
return tuple(traced_with_input(binary, input))
return with_input
def unpack(output):
assert(len(output) % 8 == 0)
addrs = []
for i in xrange(len(output) / 8):
addr = struct.unpack_from('q', output, i * 8) # returns a tuple
addrs.append(addr[0])
return addrs
def traced_with_input(binary, input):
p = subprocess32.Popen(binary, stdin=subprocess32.PIPE, stderr=subprocess32.PIPE)
(output, error) = p.communicate(input)
addrs = unpack(error)
return addrs
def run(binary, seed):
global max_iterations
program = traced(binary)
# obtain address of main function for the root node by sampling the seed
path = program(seed)
path = path[0:1]
root = Node(path)
for i in xrange(max_iterations):
sample(root, program, seed)
print('')
root.pp()
print('')
print('')
if __name__ == "__main__" and len(sys.argv) > 1:
binary = sys.argv[1]
args = sys.argv[2:]
seed = ''.join(sys.stdin.readlines())
print('seed')
print(seed)
run(binary, seed)
| python |
from .data_catalog import DataCatalog
from .deltalake import PyDeltaTableError, RawDeltaTable, rust_core_version
from .schema import DataType, Field, Schema
from .table import DeltaTable, Metadata
from .writer import write_deltalake
| python |
with open("even_more_odd_photos.in") as input_file:
N = int(input_file.readline().strip())
breed_IDs = list(map(int, input_file.readline().strip().split()))
odds = 0
evens = 0
for i in breed_IDs:
if i%2 == 0:
evens+=1
else:
odds+=1
groups = 0
if odds == 0:
groups = 1
elif evens == 0:
x = []
for i in breed_IDs:
x.append
groups = len(breed_IDs)-(len(breed_IDs)/3)
elif odds == evens:
groups = N
elif odds+1 == evens:
groups = N
print(groups)
| python |
#coding=utf-8
'''
Created on 2015-10-22
@author: zhangtiande
'''
from gatesidelib.common.simplelogger import SimpleLogger
from model_managers.model_manager import ModelManager
class LoggerManager(ModelManager):
'''
classdocs
'''
def all(self):
return super(LoggerManager,self).get_queryset().filter(IsActive=1)
def get(self,logger_id):
result=None
try:
result=super(LoggerManager,self).get_queryset().get(id=logger_id)
except Exception as ex:
SimpleLogger.exception(ex)
return result
def get_by_deviceid(self,device_id):
result=None
try:
result=self.all().filter(deviceId=device_id)[0]
except Exception as ex:
SimpleLogger.exception(ex)
return result
class BusinessLogManager(object):
def __init__(self,model):
self.model=model
def all(self):
return self.model.objects.all();
def get(self,log_id):
return self.model.objects.get(id=log_id);
def get_by_deviceid(self,device_id):
result=None
try:
result=self.model.objects.all().filter(deviceId=device_id)[0]
except Exception as ex:
SimpleLogger.exception(ex)
return result
| python |
#!/usr/bin/env python3
import socket
# HOST = '127.0.0.1' # Standard loopback interface address (localhost)
HOST = '192.168.0.100' # Standard loopback interface address (localhost)
PORT = 65432 # Port to listen on (non-privileged ports are > 1023)
#PORT = 8000
hostname = socket.gethostname()
# getting the IP address using socket.gethostbyname() method
ip_address = socket.gethostbyname(hostname)
print(ip_address)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((HOST, PORT))
s.listen(1)
print("Start")
conn, addr = s.accept()
print("accept")
with conn:
print('Connected by', addr)
while True:
data = conn.recv(1024)
if not data:
break
conn.sendall(data)
| python |
#!/usr/bin/env pybricks-micropython
from spockbots.gyro import SpockbotsGyro as Gyro
from spockbots.motor import SpockbotsMotor
import time
def run_crane():
"""
lower the block from the crane
"""
robot = SpockbotsMotor()
robot.debug = True
robot.setup()
robot.colorsensors.read()
print(robot)
#
# setup gyro
#
gyro = Gyro(robot)
gyro.setup()
robot.forward(50, 20)
robot.gotowhite(25, 3)
robot.turntoblack(25, direction="right", port=3)
robot.forward(50, 5)
robot.turntowhite(15, direction="left", port=2)
robot.followline(speed=10, distance=13,
port=2, right=True,
delta=-35, factor=0.4)
robot.forward(50, -5)
robot.gotowhite(10, 3)
robot.gotoblack(10, 3)
robot.gotowhite(10, 3)
robot.forward(2, 4)
robot.forward(10, 1)
# back to base
robot.forward(5, -5) # backup slowly
robot.forward(100, -20)
robot.turn(25, 56)
robot.forward(100, -60)
if __name__ == "__main__":
time_start = time.time()
run_crane()
time_end = time.time()
print("Time:", time_end - time_start)
# Time: 27.17
| python |
import bottle
import model
import pyperclip
gesla = model.Geslo(model.DATOTEKA_S_S)
with open("skrivnost.txt") as f:
SKRIVNOST = f.read()
@bottle.get("/")
def index():
return bottle.template("index.tpl")
@bottle.post("/geslo/")
def novo_geslo():
st = bottle.request.forms.get('prva') or 0
mc = bottle.request.forms.get('druga') or 0
vc = bottle.request.forms.get('tretja') or 0
si = bottle.request.forms.get('cetrta') or 0
d = bottle.request.forms.get('dolzine') or 0
c = bottle.request.forms.get('ctrlc') or 0
if (st== 0 and mc== 0 and vc== 0 and si == 0) or int(d)==0:
bottle.redirect("/napaka/")
else:
geslo= gesla.geslo(st,mc,vc,si,d)
id = gesla.novo_geslo(geslo)
bottle.response.set_cookie('idgesla','idigre{}'.format(id),secret=SKRIVNOST, path='/')
if int(c)==1:
pyperclip.copy(geslo)
bottle.redirect("/geslo/")
@bottle.get("/geslo/")
def dodaj_st():
id= int(bottle.request.get_cookie('idgesla', secret=SKRIVNOST).split('e')[1])
geslo = gesla.gesla[id]
return bottle.template("geslo.tpl", geslo=geslo)
@bottle.get("/napaka/")
def napaka():
return bottle.template("napaka.tpl")
bottle.run(reloader=True,debug=True) | python |
import os
import traceback
from argparse import ArgumentParser
import sys
import signal
from anime_automove.feature import Learn, Execute, Remove, Show
from anime_automove.util.app import Config
from anime_automove.util.dal import init
def main():
"""Run the main program"""
# ARGS
#
parser = ArgumentParser()
parser.add_argument('-c', '--configuration',
help="Configuration of the program",
required=True)
action_grp = parser.add_mutually_exclusive_group(required=True)
action_grp.add_argument('-l','--learn',
help="Suggest new anime rules that are found in source directory",
action="store_true")
action_grp.add_argument('-e', '--execute',
help="Move anime according to stored rules",
action="store_true")
action_grp.add_argument('-s', '--show',
help="Show all stored rule",
action="store_true")
action_grp.add_argument('-d', '--delete',
help="Try to delete rule by pattern",
action="store")
action_grp.add_argument('--cleanup',
help="Try to remove old rules that aren't matched since a while (according to conf.)",
action="store")
args = parser.parse_args()
# CONFIG FILE
#
cfg = Config(path=args.configuration)
init(config=cfg)
# LOCALE
#
if sys.stdout.encoding is None:
print("Encoding for output seems missing... ", file=sys.stderr)
"You should set env variable PYTHONIOENCODING=UTF-8. "
"Example: running 'export PYTHONIOENCODING=UTF-8' before calling this program"
exit(1)
# DIRECTORY
#
if not os.path.exists(cfg.src_dir):
raise Exception("The source directory '%s' doesn't exist, check your config." % cfg.src_dir)
if not os.path.isdir(cfg.src_dir):
raise Exception("The source directory '%s' isn't a directory, check your config." % cfg.src_dir)
if not os.path.exists(cfg.tgt_dir):
raise Exception("The target directory '%s' doesn't exist, check your config." % cfg.tgt_dir)
if not os.path.isdir(cfg.tgt_dir):
raise Exception("The target directory '%s' isn't a directory, check your config." % cfg.tgt_dir)
# PID LOCK
#
pid = str(os.getpid())
if os.path.isfile(cfg.lock_file):
if cfg.verbose:
print("Lock file found (%s), stopping program..." % cfg.lock_file)
sys.exit()
else:
if cfg.verbose:
print("Starting operations...")
print("Creating lock file (%s)" % cfg.lock_file)
with open(cfg.lock_file, 'w') as f:
f.write(pid)
# EXIT HANDLER
#
remote = None
def handler(signum=None, frame=None):
print("Exiting...")
print(remote)
if remote.process is not None:
try:
remote.process.terminate()
except:
print("Operation stopped")
os.unlink(cfg.lock_file)
exit(0)
# signal.SIGHUP, signal.SIGQUIT
for sig in [signal.SIGTERM, signal.SIGINT]:
signal.signal(sig, handler)
try:
if args.learn:
# learning new rules
learn = Learn(config=cfg)
animes = learn.find_distinct_names()
print("Searching new animes... %s candidates !" % len(animes))
for anime in animes:
if learn.exist(anime):
print("Ignored (exist): %s" % anime)
else:
learn.suggest_add_name(anime)
elif args.execute:
# Applying rules
execute = Execute(config=cfg)
animes = execute.find_all()
for anime in animes:
execute.apply(anime)
elif args.show:
# Show all stored rules
show = Show(config=cfg)
show.show_all()
elif args.delete:
# Removing rule by pattern
remove = Remove(config=cfg)
print("Trying to remove rule (pattern='%s')" % args.delete)
success = remove.remove(pattern=args.delete)
if success:
print("Rule removed...")
else:
print("Rule not found !")
elif args.cleanup:
# Cleaning up old rules
remove = Remove(config=cfg)
print("Cleaning rules older than %s days..." % cfg.rule_cleanup_days)
success = remove.cleanup(cfg.rule_cleanup_days)
else:
# (No actions)
print("You haven't asked any action... Printing Help.")
parser.print_help()
except:
print("Fatal error")
traceback.print_exc()
if os.path.isfile(cfg.lock_file):
if cfg.verbose:
print("Removing lock file (%s)" % cfg.lock_file)
os.unlink(cfg.lock_file)
exit(0)
if __name__ == '__main__':
main()
| python |
import argparse
import base64
import glob
import io
import json
import os
import random
import pycocotools
import cv2
import imageio
from PIL import Image, ImageColor, ImageDraw
import numpy as np
import visvis as vv
from pycocotools import mask
from skimage import measure
CAT_TO_ID = dict(egg=1, blob=2)
CAT_TO_COLOR = dict(egg='#f00562', blob='#d63526')
def r(): return random.randint(0, 255)
def options():
p = argparse.ArgumentParser(description='Convert Amazon SageMaker ' +
'instance segmentation data to COCO format')
p.add_argument('annotDir', metavar='path/to/annots', help='path to the ' +
'directory containing the raw annotation data from Amazon')
p.add_argument('manifest', metavar='path/to/manifest', help='path to ' +
'the manifest file associated with the labelling job')
p.add_argument('imgsDir', metavar='path/to/imgs', help='path to the ' +
'directory containing all possible training/eval images')
return p.parse_args()
opts = options()
alphabetizedImgList = [imgPath for imgPath in sorted(
glob.glob(os.path.join(opts.imgsDir, '*.jpg')))]
alphabetizedImgListBaseNames = [os.path.basename(
imgPath) for imgPath in alphabetizedImgList]
cocoOutput = dict(annotations=[], categories=[], images=[])
jsonAnnots = glob.glob(os.path.join(opts.annotDir, "*.json"))
with open(opts.manifest) as f:
labelledImgs = [os.path.basename(json.loads(imgLine)['source-ref']) for
imgLine in f.readlines()]
instance_id = 0
for jsonFile in jsonAnnots:
with open(jsonFile) as f:
jsonData = json.load(f)
taskName = list(
jsonData[0]['consolidatedAnnotation']['content'].keys())[0]
imgName = labelledImgs[int(jsonData[0]['datasetObjectId'])]
imgId = alphabetizedImgListBaseNames.index(imgName)
annotationData = json.loads(json.loads(jsonData[0]['consolidatedAnnotation'][
'content'][taskName]['annotationsFromAllWorkers'][0]['annotationData'][
'content'])['annotations'])
if len(cocoOutput['categories']) == 0:
label = annotationData[0]['class']
cocoOutput['categories'].append({'id': CAT_TO_ID[label],
'name': label, 'supercategory': "", 'color': CAT_TO_COLOR[label],
'metadata': {}, 'keypoint_colors': []})
img = cv2.imread(alphabetizedImgList[imgId])
# img = imageio.imread(io.BytesIO(base64.b64decode(annotationData[
# 'labeledImage']['pngImageData'])))
# cv2_img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
# # cv2.imshow('testing', cv2_img)
# # cv2.waitKey(0)
imageData = {'id': imgId, 'path': alphabetizedImgList[imgId],
'height': img.shape[0], 'width': img.shape[1], 'file_name': imgName,
'annotated': False, 'annotating': [], 'num_annotations': 0,
'metadata': {}, 'deleted': False, 'milliseconds': 0, 'events': [],
'regenerate_thumbnail': False}
cocoOutput['images'].append(imageData)
for i, instance in enumerate(annotationData):
runningArea = 0
# polygonPts = np.multiply(np.asarray(instance['data']).flatten(), img.shape[1] / 1200)
# polygonPts = np.multiply(np.asarray([[4, 3, 1, 5], [7, 4, 5, 3]]).flatten(), img.shape[1] / 1200)
# polygonPts = np.multiply(np.asarray([[int(el) for el in annot[
# 'segmentation'][0]]))
polygonPts = np.multiply(np.asarray(
np.asarray(instance['points'])), img.shape[1] / 1200)
blankImg = Image.new("L", tuple(reversed(img.shape[0:2])), 0)
for j, seg in enumerate(polygonPts):
if j == 0:
ImageDraw.Draw(blankImg).polygon([int(el)
for el in seg], outline=1, fill=1)
fortran_ground_truth_binary_mask = np.asfortranarray(
blankImg)
encoded_ground_truth = mask.encode(
fortran_ground_truth_binary_mask)
runningArea += mask.area(encoded_ground_truth)
ground_truth_bounding_box = mask.toBbox(
encoded_ground_truth)
else:
ImageDraw.Draw(blankImg).polygon([int(el)
for el in seg], outline=i, fill=i)
fortran_ground_truth_binary_mask = np.asfortranarray(
blankImg)
encoded_ground_truth = mask.encode(
fortran_ground_truth_binary_mask)
runningArea -= mask.area(encoded_ground_truth)
annotation = {
"segmentation": [],
"metadata": {},
"area": runningArea.tolist(),
"iscrowd": False,
"isbbox": False,
"image_id": imgId,
"bbox": ground_truth_bounding_box.tolist(),
"category_id": CAT_TO_ID[instance['class']],
"id": instance_id,
"color": '#{:02x}{:02x}{:02x}'.format(r(), r(), r())
}
instance_id += 1
for seg in polygonPts:
annotation['segmentation'].append(seg.tolist())
# for contour in contours:
# contour = np.flip(contour, axis=1)
# segmentation = contour.ravel().tolist()
# annotation["segmentation"].append(segmentation)
# how many levels of nesting are correct?
# only two because each instance can have one or more segmentations
# why are there three levels now?
cocoOutput['annotations'].append(annotation)
# # blankImg = Image.new("L", tuple(reversed(img.shape[0:2])), 0)
# # ImageDraw.Draw(blankImg).polygon([int(el) for el in annotation[
# # 'segmentation'][0]], outline=1, fill=1)
# # reconstructedMask = np.array(blankImg)
# # cv2.imshow('reconstructedMask', 255*reconstructedMask)
# # cv2.waitKey(0)
with open('%s_labels_fromAmzn_%s.json' % (label, taskName), 'w') as f:
json.dump(cocoOutput, f, ensure_ascii=False, indent=4)
| python |
import numpy as np
"""
Hidden Markov Model using Viterbi algorithm to find most
likely sequence of hidden states.
The problem is to find out the most likely sequence of states
of the weather (hot, cold) from a describtion of the number
of ice cream eaten by a boy in the summer.
"""
def main():
np.set_printoptions(suppress=True)
states = np.array(["initial", "hot", "cold", "final"])
# To simulate starting from index 1, we add a dummy value at index 0
observationss = [
[None, 3, 1, 3],
[None, 3, 3, 1, 1, 2, 2, 3, 1, 3],
[None, 3, 3, 1, 1, 2, 3, 3, 1, 2],
]
# Markov transition matrix
# transitions[start, end]
transitions = np.array([[.0, .8, .2, .0], # Initial state
[.0, .6, .3, .1], # Hot state
[.0, .4, .5, .1], # Cold state
[.0, .0, .0, .0], # Final state
])
# P(v|q)
# emission[state, observation]
emissions = np.array([[.0, .0, .0, .0], # Initial state
[.0, .2, .4, .4], # Hot state
[.0, .5, .4, .1], # Cold state
[.0, .0, .0, .0], # Final state
])
for observations in observationss:
print("Observations: {}".format(' '.join(map(str, observations[1:]))))
probability = compute_forward(states, observations, transitions, emissions)
print("Probability: {}".format(probability))
path = compute_viterbi(states, observations, transitions, emissions)
print("Path: {}".format(' '.join(path)))
print('')
def inclusive_range(a, b):
return range(a, b + 1)
def compute_forward(states, observations, transitions, emissions):
# number of states - subtract two because "initial" and "final" doesn't count.
big_n = len(states) - 2
# number of observations - subtract one, because a dummy "None" is added on index 0.
big_t = len(observations) - 1
# final state
f = big_n + 1
# probability matrix - all values initialized to 5, as 0 has meaning in the matrix
forward = np.ones((big_n + 2, big_t + 1)) * 5
'''
FINISH FUNCITON
'''
def compute_viterbi(states, observations, transitions, emissions):
# number of states - subtract two because "initial" and "final" doesn't count.
big_n = len(states) - 2
# number of observations - subtract one, because a dummy "None" is added on index 0.
big_t = len(observations) - 1
# final state
f = big_n + 1
# probability matrix - all values initialized to 5, as 0 is valid value in matrix
viterbi = np.ones((big_n + 2, big_t + 1)) * 5
# Must be of type int, otherwise it is tricky to use its elements to index
# the states
# all values initialized to 5, as 0 is valid value in matrix
backpointers = np.ones((big_n + 2, big_t + 1), dtype=int) * 5
return []
'''
FINISH FUNCTION
'''
def argmax(sequence):
# Note: You could use np.argmax(sequence), but only if sequence is a list.
# If it is a generator, first convert it: np.argmax(list(sequence))
# Since we loop from 1 to big_n, the result of argmax is between
# 0 and big_n - 1. However, 0 is the initial state, the actual
# states start from 1, so we add 1.
return 1 + max(enumerate(sequence), key=lambda x: x[1])[0]
if __name__ == '__main__':
main()
| python |
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os
from django.conf import settings
from django.utils.timezone import now
from django.utils.translation import activate, override
from aldryn_newsblog.models import Article
from cms import api
from . import NewsBlogTestCase, NewsBlogTransactionTestCase, TESTS_STATIC_ROOT
FEATURED_IMAGE_PATH = os.path.join(TESTS_STATIC_ROOT, 'featured_image.jpg')
class TestModels(NewsBlogTestCase):
def test_create_article(self):
article = self.create_article()
response = self.client.get(article.get_absolute_url())
self.assertContains(response, article.title)
def test_delete_article(self):
article = self.create_article()
article_pk = article.pk
article_url = article.get_absolute_url()
response = self.client.get(article_url)
self.assertContains(response, article.title)
Article.objects.get(pk=article_pk).delete()
response = self.client.get(article_url)
self.assertEqual(response.status_code, 404)
def test_auto_slugifies(self):
activate(self.language)
title = u'This is a title'
author = self.create_person()
article = Article.objects.create(
title=title, author=author, owner=author.user,
app_config=self.app_config, publishing_date=now(),
is_published=True,
)
article.save()
self.assertEquals(article.slug, 'this-is-a-title')
# Now, let's try another with the same title
article_1 = Article(
title=title.lower(),
author=author,
owner=author.user,
app_config=self.app_config,
publishing_date=now(),
is_published=True,
)
# Note, it cannot be the exact same title, else we'll fail the unique
# constraint on the field.
article_1.save()
# Note that this should be "incremented" slug here.
self.assertEquals(article_1.slug, 'this-is-a-title-1')
article_2 = Article(
title=title.upper(),
author=author,
owner=author.user,
app_config=self.app_config,
publishing_date=now(),
is_published=True,
)
article_2.save()
self.assertEquals(article_2.slug, 'this-is-a-title-2')
def test_auto_existing_author(self):
author = self.create_person()
article = Article.objects.create(
title=self.rand_str(), owner=author.user,
app_config=self.app_config, publishing_date=now(),
is_published=True,
)
article.save()
self.assertEquals(article.author.user, article.owner)
old = self.app_config.create_authors
self.app_config.create_authors = False
self.app_config.save()
article = Article.objects.create(
title=self.rand_str(), owner=author.user,
app_config=self.app_config, publishing_date=now(),
is_published=True,
)
self.app_config.create_authors = old
self.app_config.save()
self.assertEquals(article.author, None)
def test_auto_new_author(self):
user = self.create_user()
article = Article.objects.create(
title=self.rand_str(), owner=user,
app_config=self.app_config, publishing_date=now(),
is_published=True,
)
article.save()
self.assertEquals(article.author.name,
u' '.join((user.first_name, user.last_name)))
def test_auto_search_data(self):
activate(self.language)
user = self.create_user()
lead_in = 'Hello! this text will be searchable.'
Article.update_search_on_save = True
article = Article.objects.create(
title=self.rand_str(),
owner=user,
lead_in=lead_in,
app_config=self.app_config,
publishing_date=now(),
is_published=True,
)
article.save()
search_data = article.get_search_data()
self.assertEquals(lead_in, search_data)
self.assertEquals(article.search_data, search_data)
def test_auto_search_data_off(self):
activate(self.language)
user = self.create_user()
lead_in = 'Hello! this text will not be searchable.'
Article.update_search_on_save = False
article = Article.objects.create(
title=self.rand_str(),
owner=user,
lead_in=lead_in,
app_config=self.app_config,
publishing_date=now(),
is_published=True,
)
article.save()
search_data = article.get_search_data()
# set it back to true
Article.update_search_on_save = True
self.assertEquals(lead_in, search_data)
self.assertNotEquals(article.search_data, search_data)
def test_has_content(self):
# Just make sure we have a known language
activate(self.language)
title = self.rand_str()
content = self.rand_str()
author = self.create_person()
article = Article.objects.create(
title=title, slug=self.rand_str(), author=author, owner=author.user,
app_config=self.app_config, publishing_date=now(),
is_published=True,
)
article.save()
api.add_plugin(article.content, 'TextPlugin', self.language)
plugin = article.content.get_plugins()[0].get_plugin_instance()[0]
plugin.body = content
plugin.save()
response = self.client.get(article.get_absolute_url())
self.assertContains(response, title)
self.assertContains(response, content)
def test_change_title(self):
"""
Test that we can change the title of an existing, published article
without issue. Also ensure that the slug does NOT change when changing
the title alone.
"""
activate(self.language)
initial_title = "This is the initial title"
initial_slug = "this-is-the-initial-title"
author = self.create_person()
article = Article.objects.create(
title=initial_title, author=author, owner=author.user,
app_config=self.app_config, publishing_date=now(),
is_published=True,
)
article.save()
self.assertEquals(article.title, initial_title)
self.assertEquals(article.slug, initial_slug)
# Now, let's try to change the title
new_title = "This is the new title"
article.title = new_title
article.save()
article = self.reload(article)
self.assertEquals(article.title, new_title)
self.assertEquals(article.slug, initial_slug)
class TestModelsTransactions(NewsBlogTransactionTestCase):
def test_duplicate_title_and_language(self):
"""
Test that if user attempts to create an article with the same name and
in the same language as another, it will not raise exceptions.
"""
title = "Sample Article"
author = self.create_person()
original_lang = settings.LANGUAGES[0][0]
# Create an initial article in the first language
article1 = Article(
title=title, author=author, owner=author.user,
app_config=self.app_config, publishing_date=now(),
is_published=True,
)
article1.set_current_language(original_lang)
article1.save()
# Now try to create an article with the same title in every possible
# language and every possible language contexts.
for context_lang, _ in settings.LANGUAGES:
with override(context_lang):
for article_lang, _ in settings.LANGUAGES:
try:
article = Article(
author=author, owner=author.user,
app_config=self.app_config, publishing_date=now(),
is_published=True,
)
article.set_current_language(article_lang)
article.title = title
article.save()
except Exception:
self.fail('Creating article in process context "{0}" '
'and article language "{1}" with identical name '
'as another "{2}" article raises exception'.format(
context_lang,
article_lang,
original_lang,
))
| python |
# ==============================================================================
# Copyright 2018-2020 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""nGraph TensorFlow L2loss test
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
import numpy as np
import pytest
from common import NgraphTest
np.random.seed(5)
class TestL2Loss(NgraphTest):
@pytest.mark.parametrize(("xshape"), ((3, 4, 5), (1,)))
def test_l2loss(self, xshape):
x = tf.compat.v1.placeholder(tf.float32, shape=xshape)
out = tf.nn.l2_loss(x)
values = np.random.rand(*xshape)
sess_fn = lambda sess: sess.run((out), feed_dict={x: values})
assert np.allclose(
self.with_ngraph(sess_fn), self.without_ngraph(sess_fn))
def test_l2loss_empty(self):
x = tf.compat.v1.placeholder(tf.float32, shape=())
out = tf.nn.l2_loss(x)
sess_fn = lambda sess: sess.run((out), feed_dict={x: None})
# expect to be nan
assert (self.with_ngraph(sess_fn) != self.without_ngraph(sess_fn))
| python |
# Copyright 2018 AT&T Intellectual Property. All other rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The design reference is a commonly used object across most of the undercloud
platform, particularly for use during validations of documents by each
component.
"""
import json
from shipyard_airflow.control.helpers.deckhand_client import (
DeckhandClient, DeckhandPaths
)
class DesignRefHelper:
def __init__(self):
self._path = DeckhandClient.get_path(
DeckhandPaths.RENDERED_REVISION_DOCS
)
def get_design_reference(self, revision_id):
"""Constructs a design reference as json using the supplied revision_id
:param revision_id: the numeric Deckhand revision
Returns a json String
"""
return json.dumps(self.get_design_reference_dict(revision_id))
def get_design_reference_dict(self, revision_id):
"""Constructs a Deckhand specific design reference
:param revision_id: the numeric Deckhand revision
Returns a dictionary representing the design_ref
"""
return {
"rel": "design",
"href": "deckhand+{}".format(self._path.format(revision_id)),
"type": "application/x-yaml"
}
| python |
from Mask_RCNN.mrcnn.utils import Dataset
from Mask_RCNN.mrcnn.utils import extract_bboxes
from Mask_RCNN.mrcnn.visualize import display_instances
from numpy import expand_dims
from numpy import mean
from mrcnn.config import Config
from mrcnn.model import MaskRCNN
from mrcnn.utils import Dataset
from mrcnn.utils import compute_ap
from mrcnn.model import load_image_gt
from mrcnn.model import mold_image
from our_dataset import OurDataset
def fromOutputToAnn(image_id,out):
recognized_objects = []
for i in range(len(out['class_ids'])):
class_id = out['class_ids'][i]
bbox = out['rois'][i]
score = out['scores'][i]
# from [xmin, ymin, xmax, ymax] to [xmin, ymin, width, height]
bbox[2] = bbox[2]-bbox[0]
bbox[3] = bbox[3]-bbox[1]
bbox[0] = float(bbox[0])
bbox[1] = float(bbox[1])
bbox[2] = float(bbox[2])
bbox[3] = float(bbox[3])
bbox = bbox.tolist()
new_box = [bbox[1],bbox[0],bbox[3],bbox[2]]
entry = {
"category_id": int(class_id),
"bbox" : new_box,
"score": float(score),
"image_id" : int(image_id)
}
recognized_objects.append(entry)
return recognized_objects
'''
Function that from a dataset and a model returns a file with all the predictions
'''
def generateAnnotations(dataset,model,cfg):
i = 0
all_outputs = []
for image_id in dataset.image_ids:
# load image info
info = dataset.image_info[image_id]
image = dataset.load_image(i)
mask, _ = dataset.load_mask(i)
scaled_image = mold_image(image, cfg)
# convert image into one sample
sample = expand_dims(scaled_image, 0)
# make prediction
yhat = model.detect(sample, verbose=0)[0]
out = fromOutputToAnn(info['real_id'],yhat)
all_outputs.extend(out)
i = i+1
return all_outputs
'''
Function that takes in input the ground truth file of the annotation
and the output of a network in the json format and outputs the
miss rates in the output file
'''
def evaluation(annFile,resFile,outFile = "results.txt"):
from coco import COCO # IMPORT THEIR COCO, not pycocotools
from eval_MR_multisetup import COCOeval
# running evaluation
res_file = open("results.txt", "w")
for id_setup in range(0,4):
cocoGt = COCO(annFile)
cocoDt = cocoGt.loadRes(resFile)
imgIds = sorted(cocoGt.getImgIds())
cocoEval = COCOeval(cocoGt,cocoDt,'bbox')
cocoEval.params.imgIds = imgIds
cocoEval.evaluate(id_setup)
cocoEval.accumulate()
cocoEval.summarize(id_setup,res_file)
res_file.close() | python |
# -*- coding: utf-8 -*-
import os
def count_files(path):
"""Count number of files in a directory recursively.
Args:
path (str): Directory.
Returns:
int: Return number of files.
"""
count = 0
for root, dirs, files in os.walk(path):
for f in files:
count += 1
return count
| python |
# Generated by Django 2.1.7 on 2019-03-20 14:14
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('internet_nl_dashboard', '0003_uploadlog'),
]
operations = [
migrations.AddField(
model_name='uploadlog',
name='user',
field=models.ForeignKey(blank=True, help_text='What user performed this upload.', null=True,
on_delete=django.db.models.deletion.CASCADE, to='internet_nl_dashboard.DashboardUser'),
),
]
| python |
from numpy import double
import torch
import torch.nn as nn
import torch.nn.functional as F
"""
Multi-agent Modules
"""
# define the actor network
class actor_shared(nn.Module):
def __init__(self, env_params, identification = True):
# Note: id for agent is important
super(actor_shared, self).__init__()
self.identification = identification
self.max_action = env_params['action_max']
self.num_agents = env_params['num_agents']
self.partial_obs_size = int(env_params['obs']/self.num_agents)
self.partial_action_size = int(env_params['action']/self.num_agents)
self.goal_size = env_params['goal']
input_size = self.partial_obs_size + env_params['goal']
if self.identification: input_size+=1
self.fc1 = nn.Linear(input_size, 256)
self.fc2 = nn.Linear(256, 256)
self.fc3 = nn.Linear(256, 256)
self.action_out = nn.Linear(256, self.partial_action_size)
def forward(self, x):
batch_size, obs_size = x.shape
all_obs = x[..., :-self.goal_size].reshape(batch_size, self.num_agents, self.partial_obs_size)
goal = x[..., -self.goal_size:].repeat(1, self.num_agents).reshape(batch_size, self.num_agents, self.goal_size)
x = torch.cat((all_obs, goal), dim = -1)
if self.identification:
i = torch.arange(-1, 1, 2/self.num_agents).view(1, self.num_agents, 1).repeat(batch_size, 1, 1)
x = torch.cat((i, x), dim = -1)
x = F.relu(self.fc1(x))
x = F.relu(self.fc2(x))
x = F.relu(self.fc3(x))
actions = self.max_action * torch.tanh(self.action_out(x))
return actions.reshape(batch_size, self.num_agents*self.partial_action_size)
class actor_separated(nn.Module):
def __init__(self, env_params):
super(actor_separated, self).__init__()
self.max_action = env_params['action_max']
self.num_agents = env_params['num_agents']
self.partial_obs_size = int(env_params['obs']/self.num_agents)
self.partial_action_size = int(env_params['action']/self.num_agents)
self.goal_size = env_params['goal']
self.module_list = nn.ModuleList(
[nn.Sequential(
nn.Linear(self.partial_obs_size + self.goal_size, 128),
nn.ReLU(),
nn.Linear(128, 128),
nn.ReLU(),
nn.Linear(128, 128),
nn.ReLU(),
nn.Linear(128, self.partial_action_size),
nn.Tanh()
)] * self.num_agents)
def forward(self, x):
batch_size, obs_size = x.shape
all_obs = x[..., :-self.goal_size].reshape(batch_size, self.num_agents, self.partial_obs_size)
goal = x[..., -self.goal_size:].repeat(1, self.num_agents).reshape(batch_size, self.num_agents, self.goal_size)
x = torch.cat((all_obs, goal), dim = -1)
act = torch.Tensor()
for i, module in enumerate(self.module_list):
act = torch.cat((act, self.max_action*module(x[:, i, :])), dim = 1)
return act.reshape(batch_size, self.num_agents*self.partial_action_size)
class actor_dropout(nn.Module):
def __init__(self, env_params):
super(actor_dropout, self).__init__()
self.max_action = env_params['action_max']
self.fc1 = nn.Linear(env_params['obs'] + env_params['goal'], 256)
self.fc2 = nn.Linear(256, 256)
self.fc3 = nn.Linear(256, 256)
self.action_out = nn.Linear(256, env_params['action'])
self.drop_out_rate = env_params['drop_out_rate']
self.num_agents = env_params['num_agents']
self.partial_obs_size = int(env_params['obs']/self.num_agents)
self.partial_action_size = int(env_params['action']/self.num_agents)
self.goal_size = env_params['goal']
def forward(self, x):
batch_size, obs_size = x.shape
goal = x[..., -self.goal_size:].repeat(1, self.num_agents)\
.reshape(batch_size, self.num_agents, self.goal_size)
obs = x[..., :-self.goal_size].repeat(1, self.num_agents)\
.reshape(batch_size, self.num_agents, self.partial_obs_size*self.num_agents)
mat = torch.tensor([1]*self.partial_obs_size)
full_mask = torch.block_diag(*[mat]*self.num_agents)\
.reshape(1,self.num_agents,self.partial_obs_size*self.num_agents)\
.repeat(batch_size,1,1)
mask_coef = (torch.rand((batch_size,self.num_agents))<self.drop_out_rate)\
.reshape(batch_size, self.num_agents, 1).repeat(1,1,self.partial_obs_size*self.num_agents)
mask = full_mask * mask_coef + torch.ones_like(full_mask) * torch.logical_not(mask_coef)
x = torch.cat((obs*mask, goal), dim = -1)
x = F.relu(self.fc1(x))
x = F.relu(self.fc2(x))
x = F.relu(self.fc3(x))
actions = self.max_action * torch.tanh(self.action_out(x))
mat = torch.tensor([1]*self.partial_action_size)
act_mask = torch.block_diag(*[mat]*self.num_agents)\
.reshape(1,self.num_agents,self.partial_action_size*self.num_agents)\
.repeat(batch_size,1,1)
actions = (act_mask*actions).sum(dim=1)
return actions
class actor_multihead(nn.Module):
def __init__(self, env_params):
super(actor_multihead, self).__init__()
self.max_action = env_params['action_max']
self.num_agents = env_params['num_agents']
self.partial_obs_size = int(env_params['obs']/self.num_agents)
self.partial_action_size = int(env_params['action']/self.num_agents)
self.goal_size = env_params['goal']
self.fc1 = nn.Linear(env_params['obs'] + env_params['goal']*self.num_agents, 256)
self.fc2 = nn.Linear(256, 256)
self.fc3 = nn.Linear(256, 256)
self.action_out = nn.Linear(256, env_params['action'])
def forward(self, x):
batch_size, obs_size = x.shape
goal = x[..., -self.goal_size:].repeat(1, self.num_agents)\
.reshape(batch_size, self.num_agents, self.goal_size)
obs = x[..., :-self.goal_size]\
.reshape(batch_size, self.num_agents, self.partial_obs_size)
og = torch.cat((goal, obs), dim=-1).reshape(batch_size, -1).repeat(1, self.num_agents)\
.reshape(batch_size, self.num_agents, self.num_agents*(self.partial_obs_size+self.goal_size))
mat = torch.tensor([1]*(self.partial_obs_size+self.goal_size))
full_mask = torch.block_diag(*[mat]*self.num_agents)\
.reshape(1,self.num_agents,(self.partial_obs_size+self.goal_size)*self.num_agents)\
.repeat(batch_size,1,1)
x = og*full_mask
x = F.relu(self.fc1(x))
x = F.relu(self.fc2(x))
x = F.relu(self.fc3(x))
actions = self.max_action * torch.tanh(self.action_out(x))
mat = torch.tensor([1]*self.partial_action_size)
act_mask = torch.block_diag(*[mat]*self.num_agents)\
.reshape(1,self.num_agents,self.partial_action_size*self.num_agents)\
.repeat(batch_size,1,1)
actions = (act_mask*actions).sum(dim=1)
return actions | python |
"""
calendarimg.py
获取单向历,存储于本地
调用方式: calendarAcquirer.getImg()
write on 2018.09.15
"""
__author__ = "Vincent Zhang"
import pgconfig
import usrconfig
import requests
import json
import re
import time
import os
class calendarAcquirer:
@staticmethod
def getUrl():
headers = {
"Accept":"application/json, text/plain, */*",
"Accept-Encoding":"gzip, deflate, br",
"Connection":"keep-alive",
"Origin":"http://web.okjike.com",
"platform":"web",
"Referer":"https://m.weibo.cn/u/1673965152",
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36",
}
url = "https://m.weibo.cn/api/container/getIndex?type=uid&value=1673965152&containerid=1076031673965152"
r = requests.get(url, headers=headers)
data = json.loads(r.text)
imgUrl = ""
for card in data['data']['cards']:
if 'page_info' in card['mblog']:
if card['mblog']['page_info']['page_title'] == "#单向历#":
imgUrl = card['mblog']['original_pic']
break
return imgUrl
@staticmethod
def saveImg(url):
folder_path = usrconfig.FOLDER_PATH_
if folder_path[-1] != '/':
folder_path = folder_path + '/'
# 格式化成2018-09-12形式
time_str = time.strftime("%Y-%m-%d", time.localtime())
if os.path.exists(folder_path) == False:
os.makedirs(folder_path)
img_html = requests.get(url)
img_name = folder_path + 'calendar-' + time_str + '.jpg'
with open(img_name, 'wb') as file:
file.write(img_html.content)
file.flush()
file.close()
@staticmethod
def getImg():
calendarAcquirer.saveImg(calendarAcquirer.getUrl())
if __name__ == '__main__':
calendarAcquirer.getImg() | python |
from flask import Flask, request
import os
app = Flask(__name__)
@app.route("/upload", methods=["POST"])
def upload():
file = request.files.get("file_name")
if file is None:
return "None file"
localfile = open("demo.png", "wb")
data = file.read()
localfile.write(data)
localfile.close()
return "success"
@app.route("/upload_flask", methods=["POST"])
def upload_flask():
file = request.files.get("file_name")
if file is None:
return "None file"
file.save("demo_flask.png")
return "success"
if __name__ == "__main__":
app.run(debug=True, host="192.168.2.110")
| python |
from flask import Blueprint, render_template, request
from users.models import SessionModel
from utils.http import require_session
application = Blueprint('dashboard', __name__)
@application.route("/dashboard/", methods=['GET'])
@require_session()
def get_list(session):
return render_template('index.html', session=session)
@application.route("/dashboard/edit", methods=['GET'])
def get_edit():
return render_template('login.html')
@application.route("/dashboard/edit", methods=['POST'])
def post_edit():
return render_template('login.html')
@application.route("/dashboard/follow_urls", methods=['GET'])
@require_session()
def get_follow(session):
return render_template('follow_urls.html', session=session)
@application.route("/dashboard/follow_urls", methods=['POST'])
def post_follow():
print(request.headers.get('Authorization'))
return ""
| python |
from flask import Flask, send_file, send_from_directory, make_response, request, abort, session, redirect, jsonify
import re, threading, datetime, time, os, random, string, base64
from flask_pymongo import PyMongo
# 此程序只能在64位机器上运行,否则可能溢出
password = "password" # when deploy, change this !!!
imagepath = "/home/hwlab/"
def init(app, mongo, prefix):
# 静态文件
@app.route(prefix + '/', methods=['GET'])
def hwlab_index():
if "logined" in session:
return app.send_static_file("hwlab/index.html")
return redirect(prefix + "/login.html")
@app.route(prefix + "/login.html", methods=['GET'])
def hwlab_getpublic_login():
return app.send_static_file("hwlab/login.html")
@app.route(prefix + "/css/bootstrap.min.css", methods=['GET'])
def hwlab_getpublic_bootstrap():
return app.send_static_file("hwlab/css/bootstrap.min.css")
@app.route(prefix + "/<path:path_name>", methods=['GET'])
def hwlab_getstatic(path_name):
if "logined" not in session:
abort(404)
return app.send_static_file("hwlab/" + path_name)
# API
@app.route(prefix + '/login', methods=['POST'])
def hwlab_login():
if "password" not in request.form:
return "no password"
if request.form["password"] != password:
return "password error"
session["logined"] = ''.join(random.sample(string.ascii_letters + string.digits, 32))
return redirect(prefix)
@app.route(prefix + "/query_all", methods=['GET'])
def hwlab_query_all():
if "logined" not in session: return redirect(prefix + "/login.html")
hwlab = mongo.db.hwlab
cursor = hwlab.find({})
data = []
for ele in cursor:
del ele['_id'] # remove _id
data.append(ele)
print(ele)
return jsonify({
"data": data
})
nonminus = re.compile(r'^[0-9]+$')
@app.route(prefix + "/add", methods=['POST'])
def hwlab_add():
if "logined" not in session: return redirect(prefix + "/login.html")
hwlab = mongo.db.hwlab
ele = {}
if "name" not in request.form: return "no name"
else: ele["name"] = request.form["name"]
if hwlab.find_one({"name": ele["name"]}) is not None: return "duplicate name"
if "quantity" not in request.form: return "no quantity"
else: ele["quantity"] = request.form["quantity"]
if not re.match(nonminus, ele["quantity"]): return "quantity invalid"
ele["quantity"] = int(ele["quantity"])
if "position" not in request.form: return "no position"
else: ele["position"] = request.form["position"]
if "description" not in request.form: return "no description"
else: ele["description"] = request.form["description"]
if "image" not in request.form: return "no image"
else: ele["image"] = request.form["image"]
if "lastmodified" not in request.form: return "no lastmodified"
else: ele["lastmodified"] = request.form["lastmodified"]
if not re.match(nonminus, ele["lastmodified"]): return "lastmodified invalid"
ele["lastmodified"] = int(ele["lastmodified"]) # 可能溢出,需要在64位机器上运行
i = 0
tags = []
while ("tag%d" % i) in request.form:
tags.append(request.form["tag%d" % i])
i += 1
ele["tag"] = tags
print(ele)
hwlab.insert(ele)
return "OK"
@app.route(prefix + "/modify", methods=['POST'])
def hwlab_modify():
if "logined" not in session: return redirect(prefix + "/login.html")
hwlab = mongo.db.hwlab
ele = {}
if "name" not in request.form: return "no name"
else: ele["name"] = request.form["name"]
if "quantity" not in request.form: return "no quantity"
else: ele["quantity"] = request.form["quantity"]
if not re.match(nonminus, ele["quantity"]): return "quantity invalid"
ele["quantity"] = int(ele["quantity"])
if "position" not in request.form: return "no position"
else: ele["position"] = request.form["position"]
if "description" not in request.form: return "no description"
else: ele["description"] = request.form["description"]
if "image" not in request.form: return "no image"
else: ele["image"] = request.form["image"]
if "lastmodified" not in request.form: return "no lastmodified"
else: ele["lastmodified"] = request.form["lastmodified"]
if not re.match(nonminus, ele["lastmodified"]): return "lastmodified invalid"
ele["lastmodified"] = int(ele["lastmodified"]) # 可能溢出,需要在64位机器上运行
i = 0
tags = []
while ("tag%d" % i) in request.form:
tags.append(request.form["tag%d" % i])
i += 1
ele["tag"] = tags
print(ele)
hwlab.update({"name": ele["name"]},{"$set": ele})
return "OK"
@app.route(prefix + "/uploadpic", methods=['POST'])
def hwlab_uploadpic():
if "logined" not in session: return redirect(prefix + "/login.html")
if "base64" not in request.form or "type" not in request.form:
return "error"
base = request.form["base64"]
print("base:", base[:40], "...", base[-20:])
sp = base.split(',')
data = base64.b64decode(sp[1])
filename = ''.join(random.sample(string.ascii_letters + string.digits, 8)) + "." + sp[0].split("/")[1].split(";")[0]
print(filename)
if os.path.exists(imagepath + filename): return "error"
with open(imagepath + filename, "wb") as f:
f.write(data)
return filename
@app.route(prefix + "/getpic/<filename>", methods=['GET'])
def hwlab_getpic(filename):
if "logined" not in session: return redirect(prefix + "/login.html")
global imagepath
return send_from_directory(imagepath, filename)
if __name__ == "__main__":
imagepath = os.path.dirname(__file__) + "/image_test/"
print(imagepath)
app = Flask(__name__, static_folder='')
app.config['SECRET_KEY'] = '12345678' # use os.urandom(24) to generate one when deploy
app.config['MONGO_URI'] = 'mongodb://localhost:27017/flask'
mongo = PyMongo(app)
init(app, mongo, "/hwlab")
app.run(host='0.0.0.0', port=80, debug=True)
| python |
from .authentication import *
from .external_authentication import *
from .guest_authentication import *
from .key_authentication import *
from .plain_authentication import *
from .transport_authentication import *
| python |
import json, os, re, sublime, sublime_plugin, time
class PhpNamespaceMonkey():
namespaces = {}
def addBoilerplate(self, view):
settings = sublime.load_settings('PhpNamespaceMonkey.sublime-settings')
if not view.file_name() or not self.isPhpClassFile(view.file_name()) or view.size(): return
if time.time() - os.path.getctime(view.file_name()) > 1: return
namespace = self.resolveNamespace(view.file_name())
className = self.resolveClassName(view.file_name())
type = self.resolveType(className)
if not namespace: return
namespaceStyle = settings.get('namespace_style')
declarations = 'declare(strict_types=1);' if settings.get('declare_strict_types') else None
namespace = 'namespace {};'.format(namespace)
boilerplate = list(filter(None, [ '<?php', declarations, namespace ]))
if namespaceStyle == 'same-line':
view.run_command('append', { 'characters': ' '.join(boilerplate) + '\n' })
elif namespaceStyle == 'next-line':
view.run_command('append', { 'characters': '\n'.join(boilerplate) + '\n' })
elif namespaceStyle == 'psr-2':
view.run_command('append', { 'characters': '\n\n'.join(boilerplate) + '\n' })
if settings.get('include_class_definition'):
view.run_command('append', { 'characters': '\n{} {}\n{{\n}}\n'.format(type, className) })
def loadNamespaces(self, view, force = False):
if not view.window(): return
for path in view.window().folders():
if path in self.namespaces and not force: continue
self.namespaces[path] = namespaces = []
composerJsonPath = path + '/composer.json'
if not os.path.isfile(composerJsonPath): continue
composerJson = json.loads(open(composerJsonPath, 'r').read())
if not composerJson['autoload']: continue
for key in [ 'psr-0', 'psr-4' ]:
if not key in composerJson['autoload']: continue
for namespace, paths in composerJson['autoload'][key].items():
if not namespace: continue
if not isinstance(paths, list): paths = [ paths ]
for path in paths:
if not path.endswith('/'): path += '/'
namespaces.append({ 'path': path, 'namespace': namespace })
def isPhpClassFile(self, path):
fileName = path.split('/')[-1]
return len(fileName) > 0 and fileName[0] == fileName[0].upper() and fileName.endswith('.php')
def resolveNamespace(self, path):
for folder, folderNamespaces in self.namespaces.items():
if path.startswith(folder):
path = path.replace(folder, '').lstrip('/')
namespaces = folderNamespaces
break
if not namespaces: return
namespace = next(filter(lambda namespace: path.startswith(namespace['path']), namespaces), None)
if not namespace: return
subnamespace = '\\'.join(path.replace(namespace['path'], '').replace('.php', '').split('/')[:-1])
return re.sub(r"\\$", '', namespace['namespace'] + subnamespace)
def resolveClassName(self, path):
return path.replace('.php', '').split('/')[-1]
def resolveType(self, className):
matches = re.search('(Interface|Trait|Abstract)$', className)
type = matches.group(1).lower() if matches else 'class'
if type == 'abstract': type += ' class'
return type
class PhpNamespaceMonkeyListener(sublime_plugin.EventListener):
def on_activated_async(self, view):
global monkey
monkey.loadNamespaces(view)
monkey.addBoilerplate(view)
class PhpNamespaceMonkeyReloadNamespacesCommand(sublime_plugin.TextCommand):
def run(self, edit):
global monkey
monkey.loadNamespaces(self.view, True)
def description(self):
return "PHP Namespace Monkey: Reload namespaces"
monkey = PhpNamespaceMonkey()
| python |
# Given a string text,
# you want to use the characters of text to form as many instances of the word "balloon" as possible.
# You can use each character in text at most once.
# Return the maximum number of instances that can be formed.
# Example 1:
# Input: text = "nlaebolko"
# Output: 1
# Example 2:
# Input: text = "loonbalxballpoon"
# Output: 2
# Example 3:
# Input: text = "leetcode"
# Output: 0
# Constraints:
# 1 <= text.length <= 10^4
# text consists of lower case English letters only.
# Hints:
# Count the frequency of letters in the given string.
# Find the letter than can make the minimum number of instances of the word "balloon".
from collections import Counter
class Solution(object):
def maxNumberOfBalloons(self, text):
"""
:type text: str
:rtype: int
"""
# 计数看瓶颈 O(n)
# dic = {}
# for i in range(len(text)):
# if text[i] not in dic:
# dic[text[i]] = 1
# else:
# dic[text[i]] += 1
# return min(dic.get('b',0), dic.get('a',0), dic.get('l',0)//2,
# dic.get('o',0)//2, dic.get('n',0))
dic = Counter(text)
return min(dic['b'], dic['a'], dic['l']//2, dic['o']//2, dic['n']) | python |
import pytest
from rest_framework.permissions import AllowAny, IsAuthenticated
from rest_framework.permissions import IsAuthenticated
from rest_framework.exceptions import PermissionDenied
from ..decorators import resolver_permission_classes
from .test_views import url_string, response_json
class user(object):
is_authenticated = True
class anon(object):
is_authenticated = False
class request(object):
def __init__(self, user=None):
self.user = user
class info(object):
def __init__(self, user=None):
self.context = {"request": request(user), "view": None}
def test_resolver_permission_classes_decorator():
@resolver_permission_classes([])
def no_permission(info):
return True
@resolver_permission_classes([AllowAny])
def allow_any(info):
return True
@resolver_permission_classes([IsAuthenticated])
def is_authenticated(info):
return True
assert no_permission(info()) == True
assert allow_any(info()) == True
assert is_authenticated(info(user=user())) == True
with pytest.raises(PermissionDenied):
is_authenticated(info(user=anon()))
@pytest.mark.django_db
def test_resolver_permission_classes_without_login(api_client, django_user_model):
response = api_client.get(url_string(query="{authentication}"))
assert response.status_code == 200
assert response_json(response) == {
"errors": [
{
"locations": [{"column": 2, "line": 1}],
"message": "You do not have permission to perform this action.",
"path": ["authentication"],
}
],
"data": {"authentication": None},
}
@pytest.mark.django_db
def test_resolver_permission_classes_with_login(api_client, django_user_model):
user = django_user_model.objects.create_user(username="foo", password="bar")
api_client.force_authenticate(user=user)
response = api_client.get(url_string(query="{authentication}"))
assert response.status_code == 200
assert response_json(response) == {"data": {"authentication": "Is authenticated"}}
api_client.force_authenticate(user=None)
@pytest.mark.django_db
def test_resolver_permission_classes_without_permission(api_client, django_user_model):
user = django_user_model.objects.create_user(username="foo", password="bar")
api_client.force_authenticate(user=user)
response = api_client.get(url_string(query="{permission}"))
assert response.status_code == 200
assert response_json(response) == {
"errors": [
{
"locations": [{"column": 2, "line": 1}],
"message": "You do not have permission to perform this action.",
"path": ["permission"],
}
],
"data": {"permission": None},
}
api_client.force_authenticate(user=None)
@pytest.mark.django_db
def test_resolver_permission_classes_with_permission(api_client, django_user_model):
superuser = django_user_model.objects.create_superuser(
username="superfoo", password="superbar", email="[email protected]", is_staff=True
)
api_client.force_authenticate(user=superuser)
response = api_client.get(url_string(query="{permission}"))
assert response.status_code == 200
assert response_json(response) == {"data": {"permission": "Permission granted"}}
api_client.force_authenticate(user=None)
| python |
import matplotlib.pyplot as plt
import numpy as np
import os
import random
class City:
def __init__(self, x, y):
self.x = x
self.y = y
def distance_to(self, city):
x_dist = abs(self.x - city.x)
y_dist = abs(self.y - city.y)
distance = np.sqrt(x_dist ** 2 + y_dist ** 2)
return distance
class Route:
def __init__(self, cities):
self.cities = cities
self.distance = self._calculate_distance()
self.fitness = 1 / self.distance
def _calculate_distance(self):
self.distance = 0
for i, from_city in enumerate(self.cities):
to_city = self.cities[(i + 1) % len(self.cities)]
self.distance += from_city.distance_to(to_city)
return self.distance
def mate_with(self, route):
child_cities = list()
# from parent 1
start = random.randint(0, len(self.cities) - 1)
end = random.randint(start, len(self.cities) - 1)
child_cities = self.cities[start:end]
# from parent 2
for city in route.cities:
if city not in child_cities:
child_cities.append(city)
return Route(child_cities)
def plot(self, save=None):
fig, ax = plt.subplots(figsize=(5, 5))
xx = [city.x for city in self.cities] + [self.cities[0].x]
yy = [city.y for city in self.cities] + [self.cities[0].y]
ax.plot(xx, yy, c='k')
ax.scatter(xx, yy, c='r')
plt.axis('off')
if save:
plt.savefig(save, dpi=500)
class Population:
def __init__(self, cities, size):
self.routes = list()
self.size = size
for _ in range(size):
shuffled_cities = random.sample(cities, len(cities))
self.routes.append(Route(shuffled_cities))
self.routes = sorted(self.routes, key=lambda r: r.fitness, reverse=True)
def best_route(self):
return self.routes[0]
def propagate(self, elite_size):
elite = self.routes[:elite_size]
self.routes = elite
while len(self.routes) < self.size:
parent1, parent2 = random.sample(elite, 2)
self.routes.append(parent1.mate_with(parent2))
self.routes = sorted(self.routes, key=lambda r: r.fitness, reverse=True)
def run_algorithm(n_cities, n_generations, snap_freq):
if not os.path.exists(f"snapshots_{n_cities}cities"):
os.mkdir(f"snapshots_{n_cities}cities")
cities = list()
for _ in range(n_cities):
cities.append(City(x=random.randint(0, 200), y=random.randint(0, 200)))
popul = Population(cities, size=1000)
best_distance = list()
for i in range(n_generations):
popul.propagate(elite_size=300)
best_route = popul.best_route()
print(best_route.distance)
best_distance.append(best_route.distance)
if i % snap_freq == 0:
best_route.plot(save=f"snapshots_{n_cities}cities/generation_{i}.png")
fix, ax = plt.subplots(figsize=(7, 7))
ax.plot(range(len(best_distance)), best_distance, c='k')
plt.xlabel("Generation", fontsize=15)
plt.ylabel("Distance", fontsize=15)
ax.tick_params(axis="both", labelsize=12)
plt.title(f"Genetic algorithm on a {n_cities}-city TSP", fontsize=15)
plt.savefig(f"{n_cities}_distance_generation.png", dpi=500)
if __name__ == "__main__":
run_algorithm(25, 200, 1)
run_algorithm(50, 400, 10)
run_algorithm(100, 2500, 10)
| python |
import rasterio as rio
import numpy as np
def rio_read_all_bands(file_path):
with rio.open(file_path, "r") as src:
meta = src.meta
n_bands = src.count
arr = np.zeros((src.count, src.height, src.width), dtype=np.float32)
for i in range(n_bands):
arr[i] = src.read(i+1).astype(np.float32)
return arr, meta
| python |
# Django Rest Framework
from rest_framework import viewsets
from rest_framework.permissions import IsAuthenticated
# Models
from sunnysouth.marketplace.models.categories import Category
# Serializers
from sunnysouth.marketplace.serializers.categories import CategoryModelSerializer
class CategoryViewSet(viewsets.ModelViewSet):
queryset = Category.objects.all()
serializer_class = CategoryModelSerializer
| python |
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
# <pep8 compliant>
import bpy
from bpy.types import Panel
from rna_prop_ui import PropertyPanel
class DataButtonsPanel:
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "data"
@classmethod
def poll(cls, context):
return context.meta_ball
class DATA_PT_context_metaball(DataButtonsPanel, Panel):
bl_label = ""
bl_options = {'HIDE_HEADER'}
def draw(self, context):
layout = self.layout
ob = context.object
mball = context.meta_ball
space = context.space_data
if ob:
layout.template_ID(ob, "data")
elif mball:
layout.template_ID(space, "pin_id")
class DATA_PT_metaball(DataButtonsPanel, Panel):
bl_label = "Metaball"
def draw(self, context):
layout = self.layout
layout.use_property_split = True
mball = context.meta_ball
col = layout.column(align=True)
col.prop(mball, "resolution", text="Resolution Viewport")
col.prop(mball, "render_resolution", text="Render")
col.separator()
col.prop(mball, "threshold", text="Influence Threshold")
col.separator()
col.prop(mball, "update_method", text="Update on Edit")
class DATA_PT_mball_texture_space(DataButtonsPanel, Panel):
bl_label = "Texture Space"
bl_options = {'DEFAULT_CLOSED'}
COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
def draw(self, context):
layout = self.layout
layout.use_property_split = True
mball = context.meta_ball
layout.prop(mball, "use_auto_texspace")
col = layout.column()
col.prop(mball, "texspace_location")
col.prop(mball, "texspace_size")
class DATA_PT_metaball_element(DataButtonsPanel, Panel):
bl_label = "Active Element"
@classmethod
def poll(cls, context):
return (context.meta_ball and context.meta_ball.elements.active)
def draw(self, context):
layout = self.layout
layout.use_property_split = True
metaelem = context.meta_ball.elements.active
col = layout.column()
col.prop(metaelem, "type")
col.separator()
col.prop(metaelem, "stiffness", text="Stiffness")
col.prop(metaelem, "radius", text="Radius")
col.prop(metaelem, "use_negative", text="Negative")
col.prop(metaelem, "hide", text="Hide")
sub = col.column(align=True)
if metaelem.type in {'CUBE', 'ELLIPSOID'}:
sub.prop(metaelem, "size_x", text="Size X")
sub.prop(metaelem, "size_y", text="Y")
sub.prop(metaelem, "size_z", text="Z")
elif metaelem.type == 'CAPSULE':
sub.prop(metaelem, "size_x", text="Size X")
elif metaelem.type == 'PLANE':
sub.prop(metaelem, "size_x", text="Size X")
sub.prop(metaelem, "size_y", text="Y")
class DATA_PT_custom_props_metaball(DataButtonsPanel, PropertyPanel, Panel):
COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
_context_path = "object.data"
_property_type = bpy.types.MetaBall
classes = (
DATA_PT_context_metaball,
DATA_PT_metaball,
DATA_PT_mball_texture_space,
DATA_PT_metaball_element,
DATA_PT_custom_props_metaball,
)
if __name__ == "__main__": # only for live edit.
from bpy.utils import register_class
for cls in classes:
register_class(cls)
| python |
import unittest
from routes import request_config, _RequestConfig
from routes.base import Route
class TestBase(unittest.TestCase):
def test_route(self):
route = Route(None, ':controller/:action/:id')
assert not route.static
def test_request_config(self):
orig_config = request_config()
class Obby(object): pass
myobj = Obby()
class MyCallable(object):
def __init__(self):
class Obby(object): pass
self.obj = myobj
def __call__(self):
return self.obj
mycall = MyCallable()
if hasattr(orig_config, 'using_request_local'):
orig_config.request_local = mycall
config = request_config()
assert id(myobj) == id(config)
old_config = request_config(original=True)
assert issubclass(old_config.__class__, _RequestConfig) is True
del orig_config.request_local
if __name__ == '__main__':
unittest.main()
| python |
#!/usr/bin/env python
# encoding=utf-8
# Created by andy on 2016-08-03 18:38.
import pickle
import common
import utils
__author__ = "andy"
a = ['a','b','c','d']
print (a.index('d'))
#for batch in xrange(common.BATCHES):
# train_inputs, train_targets, train_seq_len = utils.get_data_set('train', batch*common.BATCH_SIZE, (batch + 1) * common.BATCH_SIZE)
# print batch, train_inputs.shape
| python |
import unittest
from dxtrack import dxtrack
class TestFramework(unittest.TestCase):
def test_configure(self):
"""
Test the simple base case
"""
default_metadata = {'default': 'metadata'}
dxtrack.configure(
context='test_error_track',
stage='test',
run_id='test_run_id',
default_metadata=default_metadata
)
self.assertEqual(dxtrack.context, 'test_error_track')
self.assertEqual(dxtrack.stage, 'test')
self.assertEqual(dxtrack.run_id, 'test_run_id')
self.assertEqual(dxtrack.default_metadata, default_metadata)
def test_configure_error(self):
"""
Test for missing arguments
"""
with self.assertRaises(ValueError) as e:
dxtrack.configure(
context=None,
stage='test',
run_id='test_run_id'
)
self.assertIn('context', str(e))
with self.assertRaises(ValueError) as e:
dxtrack.configure(
context='test_error_track',
stage=None,
run_id='test_run_id'
)
self.assertIn('stage', str(e))
with self.assertRaises(ValueError) as e:
dxtrack.configure(
context='test_error_track',
stage='test',
run_id=None
)
self.assertIn('run_id', str(e))
def test_not_configured(self):
dxtrack.metric('test_metric_name', 1)
if __name__ == '__main__':
unittest.main()
| python |
from datetime import datetime
# Three log levels, ERROR enforced by default
messages = {
0: "ERROR",
1: "INFO",
2: "DEBUG",
}
class logger:
def __init__(self, level, logfile=None):
if logfile:
self.logfile = open(logfile, "wb")
else:
self.logfile = None
if level == "info":
self.level = 1
self.str = "INFO"
elif level == "debug":
self.level = 2
self.str = "DEBUG"
else:
self.level = 0
def log(self, level, mssg):
if level <= self.level:
entry = "%s: %s, %s" % (messages[level], datetime.now(), mssg)
if self.logfile:
self.logfile.write(("%s\n" % entry).encode())
self.logfile.flush()
else:
print(entry)
| python |
from .base_config import base_config, get_config
new_config = {
'exp_name': "protonet_default",
'trainer': 'prototypical',
'num_training_examples': 14000,
'n_support': 5,
'n_query': 20,
'n_test_query': 100,
'freeze_until_layer': 10,
}
config = get_config(base_config, new_config) | python |