def _generate_default_event(self): event = Event(name='event', calendar=self.cal1) event.start = dt(2014, 4, 1, 12) event.end = dt(2014, 4, 1, 15) event.save() event.create_and_save_occurences() return event
def handle_noargs(self, **options): self.stdout.write('Checking for existing data ...') try: cal = Calendar.objects.get(name='Example Calendar', color='ff0000') self.stdout.write('It looks like you already have loaded this sample data, quitting.') sys.exit(1) except Calendar.DoesNotExist: self.stdout.write('No sample data found in db.') self.stdout.write('Install it...') self.stdout.write('Create User ...') user1 = User.objects.create_user('user1', '*****@*****.**', 'userpassword') user1.save() self.stdout.write('Create Example Calendar ...') cal = Calendar(name='Example Calendar', color='dddddd') cal.save() self.stdout.write('The Example Calendar is created.') event = Event(recurrence=None, name='Example Single Event', calendar=cal ) event.start = dt(2014, 5, 1, 17) event.end = dt(2014, 5, 1, 19) event.save() event.create_and_save_occurences() rec = Recurrence(frequency='DAILY', # start=datetime.datetime(2014, 3, 30, 13), count=10) rec.save() event = Event(recurrence=rec, name='Example Daily Event', calendar=cal) event.start = dt(2014, 5, 1, 13) event.end = dt(2014, 5, 1, 18) event.save() event.create_and_save_occurences() """
def finalize (self): fname = self.root if hasattr (self, 'source_fname'): notice = self.notice % (self.source_fname, dt()) else: notice = self.notice % ('%s at line %s' % (map_file, self.map_line), dt()) if self.template.strip().startswith ('{%'): # skip 1st line l = self.template.split ('\n', 1) l.insert (1, notice) s = '\n'.join (l) else: s = notice + self.template self.write (s, fname)
def save_doc (self, dselector, fname): # really should refactor to use %20 etc escapes, etc from html5lib import serialize s = u'<!DOCTYPE html>' + \ ie_shim + \ self.notice % (map_file, self.map_line, dt()) + \ '%s\n%s' % (serialize (self.d('head')[0], tree="lxml"), serialize (self.d('body')[0], tree="lxml")) + \ '\n</html>\n' self.write (s, fname)
def save_doc(self, dselector, fname): # really should refactor to use %20 etc escapes, etc from html5lib import serialize s = u'<!DOCTYPE html>' + \ ie_shim + \ self.notice % (map_file, self.map_line, dt()) + \ '%s\n%s' % (serialize (self.d('head')[0], tree="lxml"), serialize (self.d('body')[0], tree="lxml")) + \ '\n</html>\n' self.write(s, fname)
def init(self, name = None): t1 = time.time() if name is not None: where = 'WHERE name = "%s"' % (name) else: where = '' f = lambda table: [dict(zip(string.keys(),string)) for string in self.execute("SELECT * FROM %s %s" % (table, where)).fetchall()] server = [userclass.server(**string) for string in f(self.host_table)] backup = [userclass.backup(**string) for string in f(self.backup_table)] t2 = time.time() logger.info('initialize database complete' + dt(t1,t2)) return (server, backup)
def renew(self, server_list): t1 = time.time() if os.path.exists(self.dbpath) is True: shutil.copy(self.dbpath, self.dbpath + "~") self.dropTable(self.host_table) self.createTable() for name in server_list: nd = name.todict() column = ','.join(nd.keys()) values = ',:'.join(nd.keys()) self.execute('INSERT OR REPLACE INTO %s (%s) VALUES(:%s)' % (self.host_table, column, values), nd) self.commit() t2 = time.time() logger.info('update database complete' + dt(t1,t2))
def parse_list_record(list): record = {} fields = ['callid', 'queuename', 'agent', 'event', 'data1', 'data2', 'data3', 'data4', 'data5'] # hardcore parse to date try: time = int(list[0]) record['time'] = utils.dt(time) except: print list pass i = 1 len_list = len(list) for f in fields: value = '' if i < len_list: value = list[i] record[f] = value i += 1 return record
def parse_list_record(list): record = {} fields = [ 'callid', 'queuename', 'agent', 'event', 'data1', 'data2', 'data3', 'data4', 'data5' ] # hardcore parse to date try: time = int(list[0]) record['time'] = utils.dt(time) except: print list pass i = 1 len_list = len(list) for f in fields: value = '' if i < len_list: value = list[i] record[f] = value i += 1 return record
def _build_notice (self): return '{% spaceless %}{% comment %}\n' + \ self.notice % (map_file, self.map_line, dt()) + \ '\n{% endcomment %}{% endspaceless %}\n'
def save (self, dselector, fname): #u''.join ([lxml.html.tostring (e, encoding=unicode) for e in self.d]) self._save (self.notice % (map_file, self.map_line, dt()) + dselector.outerHtml(), fname)
def handler(signum, frame): if main_pid == os.getpid(): print("Shutting down at " + dt() + " ...") global stop_flag stop_flag = True
def finalize (self): fname = self.root self.content = self.notice % (map_file, self.map_line, dt()) + self.content self.write (None, fname)
def save_doc (self, dselector, fname): # really should refactor to use %20 etc escapes, etc self._save (u'<!DOCTYPE html>\n' + #self.notice % (map_file, self.map_line) + dselector.outerHtml(), fname) self.notice % (map_file, self.map_line, dt()) + self.d.outerHtml(), fname)
def _build_notice(self): return '{% spaceless %}{% comment %}\n' + \ self.notice % (map_file, self.map_line, dt()) + \ '\n{% endcomment %}{% endspaceless %}\n'
def save(self, dselector, fname): #u''.join ([lxml.html.tostring (e, encoding=unicode) for e in self.d]) self._save( self.notice % (map_file, self.map_line, dt()) + dselector.outerHtml(), fname)
def finalize(self): fname = self.root self.content = self.notice % (map_file, self.map_line, dt()) + self.content self.write(None, fname)
def global_forward(self, sample, batch_idx): mosaic, groundtruth, labels = sample mosaic, groundtruth, labels = mosaic.cuda( non_blocking=True), groundtruth.cuda( non_blocking=True), labels.cuda(non_blocking=True) # imgs, labels = sample # imgs, labels = imgs.cuda(non_blocking=True), labels.cuda(non_blocking=True) if (batch_idx + 1) % self.num_avg_batches == 0: make_step = True else: make_step = False if batch_idx % self.num_avg_batches == 0: zero_grad = True else: zero_grad = False noised = linrgb_to_srgb(bilinear(mosaic) / 255) / 0.6 groundtruth = linrgb_to_srgb(groundtruth / 255) / 0.6 denoised_imgs = denoiser(noised) denoiser_loss = denoise_criterion(denoised_imgs, groundtruth) imgs = 255 * denoised_imgs faceid_input = (imgs - 127.5) / 128 raw_logits = faceid(faceid_input) outputs = arcmargin(raw_logits, labels) faceid_loss = faceid_criterion(outputs, labels) loss = faceid_loss + denoiser_loss loss = loss / self.num_avg_batches denoiser_loss = float(denoiser_loss) faceid_loss = float(faceid_loss) # compute output if zero_grad: denoiser.zero_grad() faceid.zero_grad() arcmargin.zero_grad() loss.backward() # torch.nn.utils.clip_grad.clip_grad_norm_(faceid.parameters(), 10) # torch.nn.utils.clip_grad.clip_grad_norm_(denoiser.parameters(), 10) if make_step: optimizer.step() # _, predicted = torch.max(raw_logits.data, 1) # total += labels.size(0) # correct += int(predicted.eq(labels.data).sum()) grads = [] for par in list( filter(lambda p: p.grad is not None, denoiser.parameters())): grads.append(par.grad.data.norm(2).item()) cur_grad_dn_norm = np.sum(grads) grads = [] for par in list( filter(lambda p: p.grad is not None, faceid.parameters())): grads.append(par.grad.data.norm(2).item()) cur_grad_faceid_norm = np.sum(grads) grads = [] for par in list( filter(lambda p: p.grad is not None, arcmargin.parameters())): grads.append(par.grad.data.norm(2).item()) cur_grad_arcmargin_norm = np.sum(grads) cur_psnr = float( PSNR( linrgb_to_srgb(denoised_imgs / 255) / 0.6, linrgb_to_srgb(groundtruth / 255) / 0.6).mean()) cur_loss = denoiser_loss + faceid_loss self.tmp_logs_dict['denoiser_loss'].append(denoiser_loss) self.tmp_logs_dict['faceid_loss'].append(faceid_loss) self.total_loss += cur_loss # FIXME if batch_idx % 50 == 0: printoneline( dt(), 'Te=%d TLoss=%.4f batch=%d | denoise: %.4f faceid: %.4f | gradDN: %.4f gradID: %.4f gradM: %.4f psnr: %.4f' % (self.cur_epoch, self.total_loss / (batch_idx + 1), batch_idx, denoiser_loss, faceid_loss, cur_grad_dn_norm, cur_grad_faceid_norm, cur_grad_arcmargin_norm, cur_psnr))
def setUp(self): self.cal1 = Calendar(name='cal1', color='dddddd') self.cal1.save() self.events = (Event(name='e0'), Event(name='e1'), Event(name='e2'), Event(name='e3'), Event(name='e4'), Event(name='e5'), Event(name='e6')) # event that starts before and ends after on April 1 self.events[0].start = dt(2014, 3, 30, 15) self.events[0].end = dt(2014, 4, 4, 12) # event that starts and ends on April 1 self.events[1].start = dt(2014, 4, 1, 10) self.events[1].end = dt(2014, 4, 1, 17) # event that starts before and ends on April 1 self.events[2].start = dt(2014, 3, 30, 10) self.events[2].end = dt(2014, 4, 1, 12) # event that starts on and ends after April 1 self.events[3].start = dt(2014, 4, 1, 10) self.events[3].end = dt(2014, 4, 3, 12) # event that starts and ends after April 1 self.events[4].start = dt(2014, 3, 20, 10) self.events[4].end = dt(2014, 3, 25, 14) # event that starts and ends after April 1 self.events[5].start = dt(2014, 4, 3, 10) self.events[5].end = dt(2014, 4, 3, 14) # daily event with one occurence on April 1 self.events[6].start = dt(2014, 3, 25, 10) self.events[6].end = dt(2014, 3, 25, 14) self.events[6].recurrence = Recurrence(frequency='DAILY', count=10) for e in self.events: e.calendar = self.cal1 e.save() e.create_and_save_occurences()