def subscribe_weather(): """ Request json:- { "email": <email> "city": <city> } :return: """ # try: # Request with no form data is bad. logger = AppLogger().get_logger() if not request.form: logger.error("No Form Data") abort(400) # Request with either email or city not present is bad. if "email" not in request.form or "city" not in request.form: logger.error("email or city not present in data") abort(400) email = request.form["email"] if not validate_email(email): logger.error("email invalid") abort(400) city = request.form['city'] if len(city) == 0: logger.error("city is empty") record = SubscriptionRecord(email, city) agent = file_agent.FileAgent() agent.add_record(record) return "SUCCESS"
def get_cities(): """ Gets the list of cities. :return: """ logger = AppLogger().get_logger() city_json = {} # try: with open(os.path.join("data_store", "top_city_list.json"), "r") as cities: city_json = json.load(cities) return jsonify(city_json)
from rest_framework.views import APIView from rest_framework.response import Response from rest_framework import status, permissions from transaction.serializers.transaction import CreateTransactionSerializer,ListTransactionSerializer from transaction.controller.transaction_controller import TransactionController from utils.config import Errors from utils.app_logger import AppLogger logger = AppLogger(tag="RFID Views") class Transaction(APIView): def put(self, request, *args, **kwargs): logger.info("********** Inside Transaction API **********") logger.info("Request data: %s" % request.data) transaction_id = kwargs.get('transaction_id') code= None msg = None if not transaction_id: code, msg = Errors.Missing.TRANSACTION_ID_MISSING response = {"status": code, "message": msg} return Response(response, status=status.HTTP_400_BAD_REQUEST) validation_check_response = CreateTransactionSerializer( data=request
import traceback from transaction.repository.transaction_repository import TransactionRepository from utils.app_logger import AppLogger logger = AppLogger(tag='Transaction Controller') transaction_repository = TransactionRepository() class TransactionController(object): @staticmethod def create_transaction_record(**kwargs): logger.info("Inside create transaction controller method") transaction, err = transaction_repository.create_transaction_record( **kwargs) if err is not None: return None, err logger.info("Exiting create transaction controller method") return transaction, None @staticmethod def calculate_sum_of_linked_transactions(transaction_id): logger.info( f"Calculating sum of linked transaction with transaction id : {transaction_id}" ) total_amount = 0 parent_transaction_filters = {"id": transaction_id} parent_transaction, err = TransactionController.get_transaction(
from torch import cuda from models.bert.bert_classification import BERTClass from utils.app_logger import AppLogger import numpy as np from sklearn.metrics import accuracy_score import json, time, os, torch import pandas as pd device = 'cuda' if cuda.is_available() else 'cpu' logger = AppLogger.getInstance() root_dir = "/home/charan/DATA/311_Data/multi-level-classification" def setup_model(no_class_1, no_class_2, label_cat, label_type): bert_model = BERTClass(no_class_1, no_class_2, label_cat) bert_model.to(device) return bert_model def get_optimizer(bert_model): learning_rate = 1e-05 adam_optimizer = torch.optim.Adam(params=bert_model.parameters(), lr=learning_rate) return adam_optimizer def loss_fn(outputs, targets): return torch.nn.BCEWithLogitsLoss()(outputs, targets) def train(epoch, training_loader, model, optimizer, model_directory):
import traceback from transaction.models import * from utils.app_logger import AppLogger from utils.config import Errors logger = AppLogger(tag='Transaction Repository') class TransactionRepository(object): @staticmethod def create_transaction_record(**kwargs): try: logger.info(f"Creating Transaction with : {kwargs}") transaction = Transaction.objects.create(**kwargs) logger.info(f"Transaction Created Successfully.") return transaction.to_dict(), None except Exception as e: logger.debug(traceback.format_exc(e)) raise e @staticmethod def get_transaction(**filters): try: logger.info(f"Fetching Transaction with filters: {filters}") transaction = Transaction.objects.filter(**filters).first() transaction = transaction.to_dict() if transaction else None logger.info(f"Transaction : {transaction}") return transaction, None except Exception as e: logger.debug(traceback.format_exc(e))