def change_action(request, post_id): post = get_object_or_404(Post, id=post_id) try: obj = model.objects.get( user=request.user, post=post, ) obj.delete() except model.DoesNotExist: model.objects.create( user=request.user, post=post, ) return to_json(post)
def rate_fnc(request, id, value): """Rate function""" value = +1 if value else -1 obj = get_object_or_404(cls, id=id) if request.get_profile.check_access(permission): if action(obj, request.user, value): return to_json(obj) else: return { 'error': _(u'Rating allowed once a time') } else: return { 'error': _(u'Permission denied'), }
#def main(): import numpy as np #from utils.json import from_json, to_json parser = ArgumentParser(description='Take hdf MC files' 'as input and write out a set of oscillated event counts. ', formatter_class=RawTextHelpFormatter) parser.add_argument('-o', '--outfile', dest='outfile', metavar='FILE', type=str, action='store',default="event_rate.json", help='file to store the output') parser.add_argument('-i', '--indir', dest='indir', metavar='FILE', type=str, action='store',default="/data/PINGU/multiNestProcessed/atmoweights/", help='file to store the output') parser.add_argument('-v', '--verbose', action='count', default=0, help='set verbosity level') args = parser.parse_args() #Set verbosity level set_verbosity(args.verbose) #default bins czbins=np.linspace(-1,0,21) ebins=np.logspace(0,2,81) #get a map event_rate_maps=get_oscillated_event_count_map_direct_from_MC_using_neutrinoflux_HDF( ebins, czbins, args.indir+'/numu_v3cuts_newfiles_*xx_stdproc.hdf5', args.indir+'/nue_v3cuts_newfiles_*_*xx_stdproc.hdf5', args.indir+'/nutau_v3cuts_newfiles_*_*xx_stdproc.hdf5',0.5,0.0024) #write the map to_json(event_rate_maps,args.outfile)
def send_message_to_group(self, token, message): payload = {"groupId": GROUPID, "body": message} response = requests.post(MOORSE_URL + API_URL + "/v2/whatsApp/groups/sendMessage", verify=False, data=json.dumps(payload), headers={'content-type': 'application/json', 'Authorization': token}) response = json.to_json(response.text) return response['data']
help= '''Input flux file in Honda format. ''', default = os.path.expandvars('$PISA/resources/flux/frj-solmin-mountain-aa.d')) parser.add_argument('-o', '--outfile', dest='outfile', metavar='FILE', type=str, action='store', help='file to store the output', default='flux.json') parser.add_argument('-v', '--verbose', action='count', default=0, help='set verbosity level') args = parser.parse_args() #Set verbosity level set_verbosity(args.verbose) logging.debug("Using %u bins in energy from %.2f to %.2f GeV"% (len(args.ebins)-1,args.ebins[0],args.ebins[-1])) logging.debug("Using %u bins in cos(zenith) from %.2f to %.2f"% (len(args.czbins)-1,args.czbins[0],args.czbins[-1])) #Instantiate a flux model flux_model = HondaFluxService(args.flux_file) #get the flux flux_maps = get_flux_maps(flux_model,args.ebins,args.czbins) #Store parameters along with flux_maps (none so far) flux_maps['params'] = {} #write out to a file to_json(flux_maps, args.outfile)
def auth(self, user, password): payload = {'login': user, 'senha': password } headers = {'content-type': 'application/json'} response = requests.post(MOORSE_URL + AUTH_URL, verify=False, data=json.dumps(payload), headers=headers) response = json.to_json(response.text) return response['data']
def send_message_to_contact(self, token, message): payload = {'from': YOUR_TRIAL_NUMBER, 'to': DESTINATION_NUMBER, 'body': message} response = requests.post(MOORSE_URL + API_URL+"/v2/whatsApp/sendMessage", verify=False, data=json.dumps(payload), headers={'content-type': 'application/json', 'Authorization': token}) response = json.to_json(response.text) return response['data']
def post__json(self): return to_json(self.post)
def user__json(self): return to_json(self.user)
def author__json(self): return to_json(self.authr)
def blog__json(self): return to_json(self.blog)
action='store',default="osc_flux.json", help='file to store the output') parser.add_argument('-v', '--verbose', action='count', default=0, help='set verbosity level') args = parser.parse_args() #Set verbosity level set_verbosity(args.verbose) outfile = args.outfile flux_maps = args.flux_file osc_param_dict = vars(args) osc_param_dict.pop('outfile') osc_param_dict.pop('flux_file') units = ['eV^2','eV^2','rad','rad','rad','rad'] for param, unit in zip(osc_param_dict.keys(),units): logging.debug("%10s: %.4e %s"%(param,osc_param_dict[param],unit)) logging.info("Getting osc prob maps") osc_flux_maps = get_osc_flux(flux_maps,args.deltam21,args.deltam31,args.theta12, args.theta13,args.theta23,args.deltacp) #Merge the new parameters into the old ones osc_flux_maps['params'] = dict(flux_maps['params'].items() + osc_param_dict.items()) #Write out logging.info("Saving osc prob maps to file: %s",outfile) to_json(osc_flux_maps, outfile)