def get(self): (out, err) = runCommand('mpc status') if err: return {'error', err}, 500 c = C() c.volume = Parser.parseVolume(out) c.playMode = Parser.parsePlayMode(out) c.title = Parser.parseTitle(out) return c.__dict__
def post(self, action, position = ''): global scheduler self.checkStartup() if action == 'play': runCommand('mpc play ' + position) #Settings.set('radio', 'state', 'play') if scheduler is None: scheduler = BackgroundScheduler() scheduler.add_job(self.checkStatus, 'interval', seconds=30, id='checkStatus', replace_existing=True) scheduler.start() elif action == 'stop': runCommand('mpc stop') #Settings.set('radio', 'state', 'stop') if scheduler is not None: scheduler.remove_job('checkStatus') scheduler.shutdown() scheduler = None return {'playMode': 'stopped'} elif action =='pause': runCommand('mpc pause') elif action =='next': runCommand('mpc next') elif action =='previous': runCommand('mpc prev') else: return {'playMode': 'invalid'} (out, err) = runCommand('mpc status') if err: return {'error', err}, 500 return {'playMode': Parser.parsePlayMode(out)}
def test_one_digit(self): cases = ["0", "1", "7"] for d in cases: self.assertEqual(Parser.string_to_result(d), int(d))
def test_semi_digit_1(self): cases = ["12", "343", "2452525", "543442424"] for d in cases: self.assertEqual(Parser.string_to_result(d), int(d))
lenth, A_, M_, H_, args.epsilon, Random=False) out = critic.predict_target_with_rl_att([lenth], [inputs], attented_vec) if np.argmax(out) == np.argmax(solution): acc += 1 return float(acc) / len(val_data) if __name__ == '__main__': tf.logging.set_verbosity(tf.logging.ERROR) os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' argv = sys.argv[1:] args, _ = Parser().getParser().parse_known_args(argv) random.seed() logging.basicConfig(filename=args.log, level=logging.INFO, format='%(message)s') logger = logging.getLogger(__name__) dataset = Dataset(args.dataset, logger) train_data, dev_data = dataset.getdata(args.maxlenth) word_vector = dataset.get_wordvector(args.word_vector) ### train_text_num = 500 dev_text_num = 20 if args.smalldata == 1: train_data = train_data[:train_text_num]
from helpers import Parser, train_svm_from_data_then_update_db from svm import SVM_Helper from mongo_helper import MongoHelper from config import getKeys settings = getKeys(os) parser_dependencies = { "get": get, "np": np, "BeautifulSoup": BeautifulSoup, "json": json, "shuffle": shuffle, "sub": sub } wiki_quote_scraper = Parser(**parser_dependencies) svm_dependencies = { 'np': np, 'json': json, "preprocessing": preprocessing, "GridSearchCV": GridSearchCV, "SVC": SVC, "Counter": Counter } svm_dependencies['LogisticRegression'] = LogisticRegression svm_dependencies['KNeighborsClassifier'] = KNeighborsClassifier svm_dependencies["DecisionTreeClassifier"] = DecisionTreeClassifier svm_dependencies["RandomForestClassifier"] = RandomForestClassifier svm_helper = SVM_Helper(**svm_dependencies)
def put(self, volume): (out, err) = runCommand('mpc volume ' + volume) if err: return {'error', err}, 500 return {'volume': Parser.parseVolume(out)}
def get(self): (out, err) = runCommand('mpc volume') if err: return {'error', err}, 500 return {'volume': Parser.parseVolume(out)}
def test_1(self): cases = {"+ * 2 4 3": 11, "- + 2 3 + 0 2": 3, "+ 0 * 1 0": 0, "- - - 4 2 1 8": -7, "* + 3 5 10": 80} for s, r in cases.items(): self.assertEqual(Parser.string_to_result(s), r)
from collections import deque from helpers import get_aoc_data, Parser ONE_BILLION = 1000_000_000 d = get_aoc_data(day=16) spin = Parser('s<int>') exchange = Parser('x<int>/<int>') partner = Parser('p<str>/<str>') def initial(): return deque('abcdefghijklmnop') def dance(programs): for instruction in d.data.split(','): if spin(instruction): programs.rotate(*spin) elif exchange(instruction): a, b = exchange programs[a], programs[b] = programs[b], programs[a] elif partner(instruction): a, b = partner a = programs.index(a) b = programs.index(b) programs[a], programs[b] = programs[b], programs[a] else: raise ValueError(f"Don't know how to execute {instruction}")
def main(): if len(sys.argv) < 3: print("Error 1: Please input both .asm and .hack filenames at the command line") return 1 elif len(sys.argv) > 3: print("Warning: too many arguments, discarding the rest after the 3rd") if sys.argv[1][-4:] != ".asm" or sys.argv[2][-5:] != ".hack": print("Error 2: Invalid file extension(s), must use .asm and .hack filenames") return 2 print ("success") f1 = open(sys.argv[1], "r") f2 = open(sys.argv[2], "w") theobject = Parser(f1) romAddress = 0 #executing the first pass, in order to save all the labels in the SymbolTable first #notice that the romAddress counter does not increase, unless an A or C instruction is encountered while theobject.hasMoreCommands(): if theobject.commandType == L_COMMAND: SymbolTable[theobject.symbol] = romAddress theobject.advance(f1) elif theobject.commandType == A_COMMAND or theobject.commandType == C_COMMAND: romAddress += 1 theobject.advance(f1) elif theobject.commandType == 0: theobject.advance(f1) else: sys.exit("Exception: invalid command type encountered, exiting program...") f1.seek(0) #resetting the file pointer to the beginning theobject.__init__(f1) #reinitializing the object with the reset file pointer ramAddress = 16 romAddress = 0 #executing the 2nd pass, where all the instructions are translated into binary code while True: if theobject.commandType == A_COMMAND: if theobject.symbol.isdigit() == True: #addresses are converted directly into binary f2.write(f"{to16binary(theobject.symbol)}\n") else: if theobject.symbol in SymbolTable: #symbols are first looked up in the SymbolTable f2.write(f"{to16binary(SymbolTable[theobject.symbol])}\n") else: SymbolTable[theobject.symbol] = ramAddress ramAddress += 1 f2.write(f"{to16binary(SymbolTable[theobject.symbol])}\n") romAddress += 1 elif theobject.commandType == C_COMMAND: f2.write('111' + compTable[theobject.comp] + destTable[theobject.dest] + jumpTable[theobject.jump] +'\n') romAddress += 1 elif theobject.commandType == L_COMMAND: SymbolTable[theobject.symbol] = romAddress elif theobject.commandType == 0: if theobject.hasMoreCommands() == False: break theobject.advance(f1) continue else: sys.exit("Exception: invalid command type encountered, exiting program...") if theobject.hasMoreCommands() == False: break theobject.advance(f1)