def init_settings(settings_): global settings updated_settings = update(settings, settings_, UPDATE_RECURSION_EXCLUDED) updated_settings = update(updated_settings, _get_local_config(), UPDATE_RECURSION_EXCLUDED) settings = updated_settings
def loop(): while True: try: inputline = input() except (KeyboardInterrupt, EOFError): break inputline = inputline.split(" ") update(inputline)
def update_wrapper(infoname, priorname, outname, outavgname): G = update(infoname, priorname) for e in G.edges(): print G[e[0]][e[1]]['params'] print e, stats.gamma(G[e[0]][e[1]]['params'][0], scale=G[e[0]][e[1]]['params'][1]).stats(moments='m') nx.write_edgelist(G,outname) A = G.copy() for e in A.edges(): p = stats.gamma(G[e[0]][e[1]]['params'][0], scale=G[e[0]][e[1]]['params'][1]).stats(moments='m') # if p == nan: A[e[0]][e[1]]['weight'] = 0 A[e[0]][e[1]]['weight'] = p nx.write_weighted_edgelist(A,outavgname,delimiter=',')
def run_plot(): if model.get() == 'Chose model': print('Chose model and run again.') return s, counter, r = update(int(e1.get()), int(e2.get()), str(distribution.get()), str(model.get()), float(e3.get()), float(e4.get()), float(e5.get())) nr_clusters = len(np.unique(s[counter - 1, :])) print("Number of clusters", nr_clusters) if c.get() == 1: # Plot radii at t = 0 start_position = start(int(e1.get()), int(e2.get()), str(distribution.get())) rad = radius(int(e1.get()), int(e2.get()), float(e4.get()), float(e5.get()), str(model.get()), float(e3.get()), start_position) rad_fig = plt.figure('Radii at t = 0') ax = rad_fig.add_subplot(111) line, = ax.plot(start_position, rad, lw=2) ax.set_xlabel("Agent position (continuous)") ax.set_ylabel("Radii (continuous)") if p.get() == 1: # Plot opinion dynamics for i in range(counter): plt.figure('Opinion dynamics') plt.plot(np.reshape(s[i, 0:int(e1.get())], (1, int(e1.get()))), np.full((1, int(e1.get())), i), 'ro', markersize=9) plt.plot([0, int(e2.get())], [i, i], '-k') plt.xlabel('Agent position (continuous)') plt.ylabel('Time (discrete)') plt.yticks(np.arange(0, counter, 1)) values, index, numbers = np.unique(s[i, :], return_index=True, return_counts=True) if i == 0: continue for j in range(len(values)): plt.text(values[j], i, numbers[j], fontsize=14) plt.show if p_horizontal.get() == 1: plt.figure('Opinion dynamics vertical') t = np.linspace(0, counter - 1, counter) for agent in range(int(e1.get())): plt.plot(t, s[:, agent]) plt.xlabel('Time (discrete)') plt.ylabel('Agent position (continuous)') plt.show
writecsv(file_name, sdata) gpio.output(led1, 0) time.sleep(0.1) domain = "https://api.solardata2.tk" url = domain + "/api/inverter/stats/add" print(url) while True: try: base_path = os.path.dirname(os.path.abspath( inspect.getfile(inspect.currentframe()))) + "/" print(base_path) restart.reboot() update(base_path) print(slave_ids) for slave_id in slave_ids: for i in registers.keys(): initmodbusandread(i) timesend = str(dt.readTime().strftime("%Y-%m-%d %H:%M:%S")) # timesend = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") print(timesend) # onoff() print(uid + "{0:0=2d}".format(slave_id)) data = setData(uid, slave_id, registers, timesend, vers) sdata = setCsvData(uid, slave_id, registers, timesend, vers) headers = {'Content-type': 'application/json'} senddata(file_name, url, sdata, headers, data, vers) time.sleep(10*20)
def updateQuestions(self): update()
def get_oreilly_rss_feed(publisher, url): f = feedparser.parse(url) return book.get_book(publisher, f.entries[0].title , f.entries[0].summary, f.entries[0].link) try: publisher = 'O''Reilly Media' logging.info("BEGIN O'REILLY") ebook = get_oreilly_rss_feed(publisher, OREILLY_FEED_RSS) ebook.put() logging.info("O'REILLY OK") update(publisher, true) except: logging.exception("O'REILLY ERROR:", sys.exc_info()[0]) update(publisher, false) try: publisher = 'Microsoft Press' logging.info("BEGIN MSPRESS") ebook = get_oreilly_rss_feed(publisher, MS_FEED_RSS) ebook.put() logging.info("MSPRESS OK") update(publisher, true) except:
def main(): # Prompts users for a file name containing the graph structure. graph_name = input('Graph Structure File: ') node_list = read_graph(graph_name) # Prompts users for a file name containing the possibles values of the nodes. val_name = input('Node Value File: ') node_list = read_val(val_name, node_list) # Prompts users for a file name containing the probabilities. prob_name = input('Probability File: ') node_list = read_prob(prob_name, node_list) # Initializes the graph structure. evidence, node_list = initialize(node_list) exit_flag = False while not exit_flag: # Resets the nodes and evidence to their initial values. node_list = read_graph(graph_name) node_list = read_val(val_name, node_list) node_list = read_prob(prob_name, node_list) evidence, node_list = initialize(node_list) # Prompts the user for a node and value of interest. int_node = input('Input the node of interest and its value (ex: A1): ') # Prompts the user for all the evidence. evi_nodes = input('Input all evidence nodes (ex: B1 C0 D1). If there is no evidence, type None: ') if evi_nodes == 'None': # Gets the name and value associated with the node of interest. interest_name, interest_val = name_val(int_node) # Since there is no evidence, we need only the marginal distribution given no evidence, which we # initialized as 'Empty.' cond_prob = node_list[interest_name].cond[interest_val]['Empty'] print('The conditional probability of', int_node, 'given no evidence is', '{0:0.4f}.'.format(cond_prob)) else: # Gets the name and value associated with the node of interest. interest_name, interest_val = name_val(int_node) # Updates the network for every evidence given. evidence_list = evi_nodes.split(' ') for e in evidence_list: evidence, node_list = update(e, node_list, evidence) # Creates a list of the evidence. evi_list = list() for v in evidence: evi_list.append(v + str(evidence[v])) # Gets the conditional probability given the evidence. try: cond_prob = node_list[interest_name].cond[interest_val][tuple(sorted(evi_list))] # If the exact conditional probability doesn't exist, then a message wasn't sent, so we have to # use a different metric. except KeyError: # Gets a list of all the conditional probabilities. cond_list = list(node_list[interest_name].cond[interest_val].keys()) # Scores each conditional probability by the number of shared indices with the evidence. score_dict = score(evi_list, cond_list) # The one with the most amount of similar indices is the one that we want. condition = max(score_dict, key=score_dict.get) cond_prob = node_list[interest_name].cond[interest_val][condition] print('The conditional probability of', int_node, 'given', evi_nodes, 'is', '{0:0.4f}.'.format(cond_prob)) # Cycling exit prompt, for convenience. exit_prompt = input('Would you like to make another query? (Y or N): ') if exit_prompt == 'Y': exit_flag = False else: exit_flag = True
def fire3(self): update()
assert response["statusCode"] == 200 body = json.loads(response["body"]) logger.debug(body) assert body["data"] == { "createdAt": "2020-04-12T12:00:01+00:00", "updatedAt": "2020-04-12T12:00:01+00:00", "uuid": str(dynamo_document.uuid), } def test_update_{{cookiecutter.model_name_slug}}_document(dynamo_document): event = { "body": json.dumps({"updated_at": "2020-04-12T12:00:01+00:00"}), "pathParameters": {"uuid": dynamo_document.uuid}, } response = update(event, None) assert response == { "body": {% raw %}f'{{"uuid": "{dynamo_document.uuid}"}}',{% endraw %} "statusCode": 200, "headers": {"Access-Control-Allow-Origin": "*"}, } def test_delete_{{cookiecutter.model_name_slug}}_document(dynamo_document): event = { "body": None, "pathParameters": {"uuid": dynamo_document.uuid}, } response = delete(event, None) assert response == { "body": None,
def updaterun(self): if getinfo(): update(getupdatefile(infodic)) else: print 'No update!'
import logging import urllib from xml.etree.ElementTree import parse import feedparser import sys import book import update APRESS_FEED_RSS = 'http://www.apress.com/index.php/dailydeals/index/rss' PUBLISHER = 'Apress' def get_apress_rss_feed(): f = feedparser.parse(APRESS_FEED_RSS) return book.get_book(publisher, f.entries[0].title, f.entries[0].description, f.entries[0].link) try: logging.info("BEGIN APRESS") ebook = get_apress_rss_feed() ebook.put() logging.info("APRESS OK") update(PUBLISHER, true) except: logging.exception("APRESS ERROR:", sys.exc_info()[0]) update(PUBLISHER, false)
def print_date_time(): with app.app_context(): update()
def __init__(self, arguments): ## manager config self.__author__ = 'Jonathan Argentiero <*****@*****.**>' # github self.__githubuser__ = 'jonathanargentiero' self.__githubrepo__ = 'puppa' self.__repositoryurl__ = 'https://github.com/'+self.__githubuser__+'/'+self.__githubrepo__ self.__repositorytags__ = 'https://api.github.com/repos/'+self.__githubuser__+'/'+self.__githubrepo__+'/git/refs/tags' self.__puppagitlocation__ = 'dist/' # filename self.__filename__ = arguments[0] # version : python puppa --version self.__version__ = '0.3' # doc : python puppa self.__doc__ = (Fore.MAGENTA + 'PUPPA!' + Style.RESET_ALL)+'\n' self.__doc__ += (Fore.BLUE + 'your updatable application package' + Style.RESET_ALL)+'\n' self.__doc__ += 'Run "python puppa --help" for a list of commands.' # help : python puppa --help self.__help__ = (Fore.RED + 'All the commands are listed below!' + Style.RESET_ALL)+'\n' self.__help__ += 'Usage:\n' self.__help__ += 'python puppa [options] [arguments]\n\n' self.__help__ += 'Options:\n' self.__help__ += ' -h, --help print this commands list\n' self.__help__ += ' -v, --version print version\n' self.__help__ += ' -p, --path print path location of the puppa\n' self.__help__ += ' -a, --author print author info\n' self.__help__ += ' update [version] updates the puppa from git repository\n' self.__help__ += ' purge purges the puppa\n' self.__help__ += '\n'+(Fore.YELLOW + 'WARNING: purging the puppa is permanent!' + Style.RESET_ALL)+'\n' ## manager logic # python puppa if len(arguments) < 2: print self.__doc__ return None command = arguments[1] # python puppa [options] [arguments] if command == 'update': # python puppa update update(self,arguments) elif command == 'purge': # python puppa purge print (Fore.YELLOW + 'WARNING!' + Style.RESET_ALL)+' This will delete permanently the puppa! Continue? [y/N]' choice = raw_input().lower() if choice in ['yes','y', 'ye']: purge(self) elif choice in ['no','n', '']: return None else: sys.stdout.write((Fore.RED + 'UNVALID!' + Style.RESET_ALL)+" please respond with 'yes' or 'no'\n") return None elif command == '-h' or command == '--help': # python puppa --help print self.__help__ return None elif command == '-v' or command == '--version': # python puppa --version print 'v'+self.__version__ return None elif command == '-p' or command == '--path': # python puppa --help print self.getCurrentEntryPath() return None elif command == '-a' or command == '--author': # python puppa --version print (Fore.GREEN + self.__author__ + Style.RESET_ALL) else: # python puppa something print (Fore.RED + 'COMMAND NOT VALID!' + Style.RESET_ALL) print self.__help__ return None
if(len(sys.argv)==1): # Display help sys.exit(1) WORKDIR = settings.getWorkdir() for ARGS in sys.argv[1:]: if(os.access("packages.rules"+os.sep+ARGS+".json", os.R_OK) == True): INSTDIR = packages.getInstdir(ARGS) if( os.access(WORKDIR+INSTDIR, os.W_OK) == False): if( os.access(WORKDIR+INSTDIR, os.F_OK) == False): print( "Trying to update...") MIRROR = settings.getMirror() if( MIRROR == None): sys.exit(1) MIRROR=MIRROR[0] from update import * if ( os.access("packages.rules"+os.sep+ARGS+".json", os.R_OK) == True): update(ARGS, MIRROR, WORKDIR) elif( os.path.isdir("packages.rules"+os.sep+ARGS) == True): LIST = os.listdir("packages.rules"+os.sep+ARGS) for FILES in LIST: update(FILES, MIRROR, WORKDIR) elif( ARGS != sys.argv[0]): print( "Package '"+ARGS+"' doesn't exist!") sys.exit(1) else: print( "Cannot write to '"+INSTDIR+"' !") sys.exit(1) else: CXX = check(ARGS, WORKDIR=WORKDIR) compile(ARGS, CXX=CXX, WORKDIR=WORKDIR)
def updatecustomers(): print("update.....:") nationalcode=input("NationalCode: ") customername=input("CustomerName: ") update(customername,nationalcode)