def help(): """Devolve a pagina de Ajuda""" window_id = str(get_window_id()) set_base_context(window_id) ctx_dict = get_context(window_id) ctx_dict['window_id'] = window_id ctx_dict['name'] = 'help' ctx_dict['title'] = 'Ajuda' code = """ <textarea rows="30" class="small-12 large-12 columns"> """ code += """ Ajuda Por Implementar... """ code += """ </textarea> """ ctx_dict['form'] = code set_context(window_id, ctx_dict) return ctx_dict
def popup_close(window_id): """A funçao que permite retornar o window_status a edit quando o popup fecha""" #print ('oi estou no popup_close') from utils import get_context as gtx ctx_dict = gtx(window_id) ctx_dict['window_status'] = 'edit' set_context(window_id, ctx_dict)
def about(): """Devolve a pagina about""" window_id = str(get_window_id()) set_base_context(window_id) ctx_dict = get_context(window_id) ctx_dict['window_id'] = window_id ctx_dict['name'] = 'about' ctx_dict['title'] = 'Sobre' code = """ <div class="small-12 large-12 columns"> <textarea rows="30" readonly> """ code += """ Sobre o ERP+ Versão 1.0 de 2015 O ERP + é uma plataforma de Gestão sobre a qual qualquer pessoa pode desenvolver objectos que suportem o seu negócio ou actividade. Bom trabalho Contactos: Dario Costa +238 983 04 90 """ code += """ </textarea> </div> """ ctx_dict['form'] = code set_context(window_id, ctx_dict) return ctx_dict
def main(): """Funçao index""" print('Init do main_route') window_id = str(get_window_id()) print(window_id) set_base_context(window_id) print('oi') ctx_dict = get_context(window_id) print(ctx_dict) ctx_dict['window_id'] = window_id ctx_dict['name'] = 'index' ctx_dict['title'] = 'ERP +' ctx_dict['form'] = '' print(ctx_dict) set_context(window_id, ctx_dict) return ctx_dict
def licence(): """Devolve a pagina da Licença""" window_id = str(get_window_id()) set_base_context(window_id) ctx_dict = get_context(window_id) ctx_dict['window_id'] = window_id ctx_dict['name'] = 'licence' ctx_dict['title'] = 'Licença' licence_file = open('/var/www/core/help/licence.txt', 'r', encoding='utf8') code = """ <textarea rows="30" class="small-12 large-12 columns"> """ code += licence_file.read() code += """ </textarea> """ ctx_dict['form'] = code set_context(window_id, ctx_dict) return ctx_dict
def secure(*args, **kargs): #print ('inicio do secure do verify_form_rights') from utils import get_context, set_context import objs window_id = kargs.get('window_id') #print (window_id) ctx_dict = get_context(window_id) #print ('ctx_dict no verify_form_rights', ctx_dict) model_name = ctx_dict.get('model_name') model = eval("""objs.{model_name}()""".format(model_name=model_name)) result = verify_rights(model=model, action=target.__name__) #print ('2') if result == True: return target(*args, **kargs) elif isinstance(result, list): ctx_dict['rights'] = result set_context(window_id, ctx_dict) #print ('fim do secure de form, vou carregar o objecto') return target(*args, **kargs) else: return result
def update(): """Devolve a pagina de Actualizaçao da Implementacao Local""" window_id = str(get_window_id()) set_base_context(window_id) ctx_dict = get_context(window_id) ctx_dict['window_id'] = window_id ctx_dict['name'] = 'update' ctx_dict['title'] = 'Actualização' code = """ <textarea rows="30" class="small-12 large-12 columns"> """ code += """ Actualização Por Implementar... """ code += """ </textarea> """ ctx_dict['form'] = code set_context(window_id, ctx_dict) return ctx_dict
def train(cfg): date_today = date.today().strftime("%b-%d-%Y") summary_writer = SummaryWriter(cfg.log_dir, flush_secs=5, filename_suffix=date_today) train_data = mx.gluon.data.vision.MNIST( train=True).transform_first(data_xform) train_loader = mx.gluon.data.DataLoader(train_data, shuffle=True, batch_size=cfg.batch_size) image_shape = train_data[0][0].shape # No initialization. Custom blocks encapsulate initialization and setting of data. net = Glow(image_shape, cfg.K, cfg.L, cfg.affine, cfg.filter_size, cfg.temp, cfg.n_bits) ctx = get_context(cfg.use_gpu) net = set_context(net, ctx) trainer = mx.gluon.Trainer(net.collect_params(), 'adam', {'learning_rate': cfg.lr}) n_samples = len(train_loader) update_interval = n_samples // 2 # store the loss with summary writer twice loss_buffer = LossBuffer() global_step = 1 for epoch in range(1, cfg.n_epochs + 1): for idx, (batch, label) in enumerate(train_loader): print(f'Epoch {epoch} - Batch {idx}/{n_samples}', end='\r') data = mx.gluon.utils.split_and_load(batch, ctx) with mx.autograd.record(): for X in data: z_list, nll, bpd = net(X) prev_loss = loss_buffer.new_loss(bpd.mean()) loss_buffer.loss.backward() trainer.step(1) if prev_loss is not None and global_step % update_interval == 0: loss = prev_loss.asscalar() summary_writer.add_scalar(tag='bpd', value=loss, global_step=global_step) global_step += 1 # Sample from latent space to generate random digit and reverse from latent if (epoch % cfg.plot_interval) == 0: x_generate = net.reverse()[0] x_generate = x_generate.reshape(1, *x_generate.shape) x_recon = net.reverse(z_list[-1])[0] x_recon = x_recon.reshape(1, *x_recon.shape) x_real = data[0][0].reshape(1, *data[0][0].shape) minim = -0.5 maxim = 0.5 x_generate = x_generate.clip(minim, maxim) x_generate += -minim x_recon = x_recon.clip(minim, maxim) x_recon += -minim x_real += -minim img = mx.nd.concatenate([x_real, x_generate, x_recon], axis=0).asnumpy() summary_writer.add_image(tag='generations', image=img, global_step=global_step) summary_writer.close()