Beispiel #1
0
    def get(self):
        helper = Helper(current_app.logger)
        games, jp_result = helper.get_jackpot_matches()
        datas = []
        for result in games:
            pos, sub_type_id, odds, game_id, match_id, start_time,\
                parent_match_id, away_team, home_team = result

            datas.append({
                'pos': pos,
                'sub_type_id': sub_type_id,
                'odds_keys': odds,
                'game_id': game_id,
                'match_id': match_id,
                'start_time': start_time.strftime("%Y-%m-%d %H:%M"),
                'parent_match_id': parent_match_id,
                'away_team': away_team,
                'home_team': home_team
            })
        resp = {
            "data": datas,
            'meta': {
                'jackpot_event_id': jp_result[0],
                'jackpot_type': jp_result[1],
                'bet_amount': float(jp_result[2]),
                'jackpot_amount': float(jp_result[3]),
                'total_games': jp_result[4],
                'name': 'Correct Score Jackpot',
                'type': 'correctscore'
            }
        }
        return make_response(json.dumps(resp), 200)
	def test_LogisticRegression(self):
		helper = Helper()

		# Load up data
		iris = load_iris()
		X_train, y_train, X_test, y_test = iris.data[:120], iris.target[:120], iris.data[120:], iris.target[120:]

		# Bring in the default RandomForestClassifier model
		model_name = 'lr'
		actual_model = helper.getBuiltModel(model_name)

		# Explicity create the model we expect to get from getBuiltModel call
		expected_model = LogisticRegression(random_state=0)

		# Make sure the models are the same type before continuing
		self.assertEqual( type(actual_model), type(expected_model) )

		# Train this default model on the iris dataset
		actual_model.fit(X_train, y_train)
		
		# Get default model accuracy on testing set
		actual_accuracy = actual_model.score(X_test, y_test)

		# Complete the same process, however we make the model explicitly
		expected_model.fit(X_train, y_train)
		expected_accuracy = expected_model.score(X_test, y_test)

		# Make sure that the accuracy reported from both models is the same
		self.assertEqual( actual_accuracy, expected_accuracy )
Beispiel #3
0
    def post(self):
        data = self.params()
        helper = Helper(current_app.logger)
        sport_id = data.get('id')
        page = data.get('page') or 1
        limit = data.get('limit') or 10
        categories = helper.get_active_categories(sport_id, page, limit)
        datas = []
        for cat in categories:
            category_id, category_name = cat
            cat_data = {
                'category_id':
                category_id,
                'category_name':
                category_name.decode('unicode_escape').encode('utf-8')
            }
            competitions = helper.get_competitions(category_id)
            c_datas = []
            for c in competitions:
                competition_id, competition_name = c
                c_datas.append({
                    'competition_id':
                    competition_id,
                    'competition_name':
                    competition_name.decode('unicode_escape').encode('utf-8')
                })
            cat_data['competitions'] = c_datas

            datas.append(cat_data)

        return make_response(json.dumps(datas), 200)
Beispiel #4
0
 def post(self):
     #user_id,device_id,fcm_token,update_token=True/False
     data = request.get_json()
     current_app.logger.info(
         "Scorepesa mobile app device register api args %r" % data)
     scorepesa_cfgs = LocalConfigParser.parse_configs("SCOREPESAAPP")
     scorepesa_bonus_cfgs = LocalConfigParser.parse_configs("SCOREPESA")
     try:
         http_code = 200
         current_app.logger.info("device registeration data..... %r" % data)
         helper = Helper(current_app.logger)
         result = helper.scorepesa_app_register_device(data)
         current_app.logger.info(
             "mobile device registration response... {0}".format(result))
         if not result:
             http_code = 500
             result = 'ERROR'
         if result and data.get("update_token") is False:
             #award bonus
             if (helper.award_bonus_to_profile(data)):
                 #sent app notification/sms
                 data[
                     'msg'] = "Congratulations! you have been awarded a bonus worth KES {0}. Now win big with.".format(
                         scorepesa_bonus_cfgs['registration_bunus_amount'])
                 data['sc'] = "101010"
                 helper.push_notification(data)
                 helper.send_message(data)
     except JWTError as e:
         current_app.logger.error(
             "Exception on device registration.... %r " % e)
         http_code = 400
         result = "Invalid request."
     resp = make_response(json.dumps(result), http_code)
     return resp
	def test_AdaBoostRegressor(self):
		helper = Helper()

		# Load up data
		X, y = load_boston(return_X_y=True)
		X_train, y_train, X_test, y_test = X[:405], y[:405], X[405:], y[405:]

		# Bring in the default RandomForestClassifier model
		model_name = 'ab:regressor'
		actual_model = helper.getBuiltModel(model_name)

		# Explicity create the model we expect to get from getBuiltModel call
		expected_model = AdaBoostRegressor(random_state=0)

		# Make sure the models are the same type before continuing
		self.assertEqual( type(actual_model), type(expected_model) )

		# Train this default model on the iris dataset
		actual_model.fit(X_train, y_train)
		
		# Get default model accuracy on testing set
		actual_accuracy = actual_model.score(X_test, y_test)

		# Complete the same process, however we make the model explicitly
		expected_model.fit(X_train, y_train)
		expected_accuracy = expected_model.score(X_test, y_test)

		# Make sure that the accuracy reported from both models is the same
		self.assertEqual( actual_accuracy, expected_accuracy )
	def test_init(self):
		helper = Helper()

		model_name = 'rf:classifier'
		model = helper.getDefaultModel(model_name)
		self.assertEqual( model, RandomForestClassifier ) 
		
		args = helper.getDefaultArgs(model_name)
		self.assertEqual( args, {'random_state':0} )
		
		model = model(**args)
		self.assertEqual( type(model), RandomForestClassifier )

		
		helper.setRandomState(1)

		model_name = 'dt:regressor'
		model = helper.getDefaultModel(model_name)
		self.assertEqual( model, DecisionTreeRegressor ) 
		
		args = helper.getDefaultArgs(model_name)
		self.assertEqual( args, {'random_state':1} )
		
		model = model(**args)
		self.assertEqual( type(model), DecisionTreeRegressor )
Beispiel #7
0
    def post(self):
        data = self.get_params()
        current_app.logger.info("Reading my bets request => %r" % data)
        helper = Helper(current_app.logger)
        data = helper.get_mybets(data.get('token'),
                                 data.get('page') or 1,
                                 data.get('limit') or 10)
        current_app.logger.info("Reading my bets get_mybets => %r" % data)
        datas = []
        for d in data:
            created, bet_id, total_matches, jackpot_bet_id, total_odd, bet_message, bet_amount, possible_win, status = d
            value = {
                'created': created,
                'bet_id': bet_id,
                'total_matches': total_matches,
                'jackpot_bet_id': jackpot_bet_id,
                'total_odd': float(total_odd),
                'bet_message': bet_message,
                'possible_win': float(possible_win),
                'status': status,
                'bet_amount': float(bet_amount)
            }
            datas.append(value)

        current_app.logger.info("Reading my bets get_mybets FINAL String  %r" %
                                datas)
        resp = make_response(json.dumps(datas), 200)
        return resp
Beispiel #8
0
 def post(self):
     #version_number
     data = request.get_json()
     current_app.logger.info(
         "Scorepesa mobile app change version api args %r" % data)
     scorepesa_cfgs = LocalConfigParser.parse_configs("SCOREPESAAPP")
     try:
         http_code = 200
         current_app.logger.info(
             "scorepesa app api change version data %r" % data)
         helper = Helper(current_app.logger)
         message = {"vnum": data.get('version_number')}
         result = helper.scorepesa_app_update_version(message)
         current_app.logger.info(
             "mobile change version response... {0}".format(result))
         if not result:
             http_code = 500
             result = 'ERROR'
     except JWTError as e:
         current_app.logger.error("Exception on version check ..... %r " %
                                  e)
         http_code = 400
         result = "Invalid request."
     resp = make_response(json.dumps(result), http_code)
     return resp
Beispiel #9
0
 def post(self):
     data = self.params()
     helper = Helper(current_app.logger)
     profile_id = helper.validate_token(data.get('token'))
     if not profile_id:
         message = {
             "status": 401,
             "error": {
                 "status": 401,
                 "message": "Unauthorized"
             }
         }
     else:
         scorepesa = Scorepesa(current_app.logger)
         balance, bonus = scorepesa.get_account_balance(
             {'profile_id': profile_id})
         message = {
             "status": 200,
             "data": {
                 "balance": balance,
                 'bonus': bonus,
                 'points': 0
             }
         }
     resp = make_response(json.dumps(message), 200)
     return resp
	def test_LinearDiscriminantAnalysis(self):
		helper = Helper()
		# Test with dataset type: sklearn DataBunch
		# Load up data
		iris = load_iris()
		X_train, y_train, X_test, y_test = iris.data[:120], iris.target[:120], iris.data[120:], iris.target[120:]

		# Bring in the default LinearDiscriminantAnalysis model
		model_name = 'lda'
		actual_model = helper.getBuiltModel(model_name)

		# Explicity create the model we expect to get from getBuiltModel call
		expected_model = LinearDiscriminantAnalysis()

		# Make sure the models are the same type before continuing
		self.assertEqual( type(actual_model), type(expected_model) )

		# Train this default model on the iris dataset
		actual_model.fit(X_train, y_train)
		
		# Get default model accuracy on testing set
		actual_accuracy = actual_model.score(X_test, y_test)

		# Complete the same process, however we make the model explicitly
		expected_model.fit(X_train, y_train)
		expected_accuracy = expected_model.score(X_test, y_test)

		# Make sure that the accuracy reported from both models is the same
		self.assertEqual( actual_accuracy, expected_accuracy )

		# Test with dataset type: pandas DataFrame
		# Load up data
		iris_df = load_iris(as_frame=True).frame
		X = iris_df.loc[:, iris_df.columns != 'target']
		y = iris_df['target']
		X_train, y_train = X.iloc[:120], y.iloc[:120]
		X_test, y_test =   X.iloc[120:], y.iloc[120:]

		# Bring in the default LinearDiscriminantAnalysis model
		model_name = 'lda'
		actual_model = helper.getBuiltModel(model_name)

		# Explicity create the model we expect to get from getBuiltModel call
		expected_model = LinearDiscriminantAnalysis()

		# Make sure the models are the same type before continuing
		self.assertEqual( type(actual_model), type(expected_model) )

		# Train this default model on the iris dataset
		actual_model.fit(X_train, y_train)
		
		# Get default model accuracy on testing set
		actual_accuracy = actual_model.score(X_test, y_test)

		# Complete the same process, however we make the model explicitly
		expected_model.fit(X_train, y_train)
		expected_accuracy = expected_model.score(X_test, y_test)

		# Make sure that the accuracy reported from both models is the same
		self.assertEqual( actual_accuracy, expected_accuracy )
Beispiel #11
0
 def post(self):
     helper = Helper(current_app.logger)
     data = self.params()
     msisdn = clean_msisdn(data.get('mobile'))
     code = data.get('code')
     ok = helper.verify_code(msisdn, code)
     if ok:
         profile_data = helper.get_profile_data(msisdn)
         token = helper.create_hash_token(msisdn,
                                          profile_data[0],
                                          remember=0)
     if ok and token:
         message = {
             'success': {
                 'status': 201,
                 "message": "Verification code has been sent to your phone"
             },
             'token': token
         }
     else:
         message = {
             'error': {
                 'status':
                 401,
                 "message":
                 "Verification failed. Kindly check code and try again or click resend code to receive new code"
             }
         }
     return make_response(json.dumps(message), 200)
Beispiel #12
0
 def get(self):
     helper = Helper(current_app.logger)
     sports = helper.get_active_sports()
     datas = []
     for sport in sports:
         sport_id, sport_name = sport
         datas.append({"sport_name": sport_name, 'sport_id': sport_id})
     return make_response(json.dumps(datas), 200)
Beispiel #13
0
 def get(self):
     helper = Helper(current_app.logger)
     tab = request.args.get('tab', 'Mechi Kali')
     limit = request.args.get('limit', 7) or 7
     page = request.args.get('page', 1) or 1
     match_id = request.args.get('id', None)
     games_result = helper.get_matches(tab, page, limit, match_id)
     datas = prepare_match_data(games_result)
     return make_response(json.dumps(datas), 200)
Beispiel #14
0
 def post(self):
     data = self.params()
     helper = Helper(current_app.logger)
     limit = data.get('limit', 10) or 10
     page = data.get('page', 1) or 1
     competition_id = data.get('id', None)
     games_result = helper.get_competition_matches(competition_id, page,
                                                   limit)
     datas = prepare_match_data(games_result)
     return make_response(json.dumps(datas), 200)
Beispiel #15
0
    def process_response(self):
        data = self.params()
        current_app.logger.info("Login requesrt eceived: %r" % data)
        msisdn = clean_msisdn(data.get('msisdn'))
        if not msisdn:
            return {
                "status": 401,
                "message": "Invalid username and or password",
                'token': ''
            }
        password = data.get("password")
        if not password:
            return {
                "status": 401,
                "message": "Invalid username and or password",
                'token': ''
            }
        helper = Helper(current_app.logger)
        profile_data = helper.get_profile_data(msisdn)
        if not profile_data:
            return {
                'status': 401,
                "message": "Invalid username and or password",
                'token': ''
            }
        real_pass = profile_data[1]
        if not checkpw(password, real_pass):
            return {
                "status": 401,
                "message": "Invalid username and or password",
                'token': ''
            }
        token = helper.create_hash_token(msisdn,
                                         profile_data[0],
                                         remember=data.get('remember'))
        if not token:
            return {
                "status": 401,
                "message": "Could not create token",
                'token': ''
            }

        return {
            "status": 200,
            "user": {
                'token': token,
                'profile_id': str(profile_data[0]),
                'balance': float(profile_data[3]),
                'msisdn': msisdn,
                'bonus': float(profile_data[4])
            }
        }
Beispiel #16
0
def main(_):
    FLAGS = flags.FLAGS
    pp.pprint(flags.FLAGS.__flags)
    print(tf.__version__)

    # load data
    data = input_data.read_data_sets("MNIST_data/", one_hot=True)
    helper = Helper(FLAGS)
    FLAGS = helper.setup_directories()

    set_seed(42)
    test_data = test_batch(data, 1000, FLAGS)
    train(FLAGS, data, test_data)
Beispiel #17
0
    def post(self):
        helper = Helper(current_app.logger)
        data = self.params()
        current_app.logger.info("Android code request with data => %r" % data)
        msisdn = clean_msisdn(data.get('mobile'))
        network = get_network_from_msisdn_prefix(msisdn)
        helper = Helper(current_app.logger)
        code, profile_id = helper.get_existing_code(msisdn)
        if code:
            profile_data = helper.get_profile_data(msisdn)
            token = helper.create_hash_token(msisdn,
                                             profile_data[0],
                                             remember=0)

            message = "Namba yako ya uthibitisho wa akaunti yako ya Scorepesa"\
               " ni %s. Ingiza namba kwenye tovuti kukamilisha mchakato huu" % (code, )
            outbox_id = helper.create_outbox(profile_id, msisdn, network,
                                             message)
            send_notification(msisdn, outbox_id, network, message)
            message = {
                'success': {
                    'status': 200,
                    'id': profile_id,
                    "message": "Verification code has been sent to your phone",
                    'code': code
                },
                'token': token
            }
        else:
            message = {
                'error': {
                    'status':
                    401,
                    "message":
                    "Verification code could not be resent. Kindly check your mobile number and try again"
                }
            }
        return make_response(json.dumps(message), 200)
	def test_getBuiltModel(self):
		helper = Helper()

		model_name = 'rf:classifier'
		actual = helper.getBuiltModel(model_name)
		expected = RandomForestClassifier(random_state=0)
		self.assertEqual( type(actual), type(expected) )

		try:
			model_name = 'jonathan'
			model = helper.getBuiltModel(model_name)

			fail(self)
		except ValueError as ve:
			self.assertEqual( str(ve), 'No default model found for jonathan')
	def test_setRandomState(self):
		helper = Helper()

		self.assertEqual( helper.random_state, 0 )

		try:
			helper.setRandomState( 'cheeseburger' )

			# This should never run!
			self.assertEqual(0, 1)
		except ValueError as ve:
			self.assertEqual( str(ve), 'Random state must be an integer: cheeseburger' )

		helper.setRandomState(101)

		self.assertEqual( helper.random_state, 101 )
Beispiel #20
0
def main(_):
    FLAGS = flags.FLAGS
    pp.pprint(flags.FLAGS.__flags)

    # load data
    data = DataSet(dataset=FLAGS.dataset, modes=FLAGS.modes)
    helper = Helper(FLAGS)
    FLAGS = helper.setup_directories()

    opt_methods = load_opt_arrays(FLAGS)

    for i, opt in enumerate(FLAGS.opt_methods.split(" ")):
        learning_rate = float(FLAGS.learning_rates.split(" ")[i])
        opt_methods = train(opt, opt_methods, data, helper, FLAGS, learning_rate)

    helper.print_opt_methods(opt_methods)
Beispiel #21
0
 def get(self):
     current_app.logger.info(
         "Scorepesa mobile app check version request....")
     scorepesa_cfgs = LocalConfigParser.parse_configs("SCOREPESAAPP")
     try:
         http_code = 200
         helper = Helper(current_app.logger)
         result = helper.scorepesa_app_check_current_version()
         current_app.logger.info(
             "scorepesa app api version response .....{0}".format(result))
     except Exception as e:
         current_app.logger.error("Exception on version check ..... %r " %
                                  e)
         http_code = 400
         result = "Invalid request."
     resp = make_response(json.dumps(result), http_code)
     return resp
Beispiel #22
0
    def post(self):
        data = self.params()
        helper = Helper(current_app.logger)
        bet_data, slip_data = helper.get_bet_details(data.get('token'),
                                                     data.get('bet_id'),
                                                     data.get('page'),
                                                     data.get('limit'))
        datas = []
        created, bet_id, total_matches, jackpot_bet_id, total_odd, bet_message, bet_amount, possible_win, status = bet_data
        bet_details = {
            'created': created,
            'bet_id': bet_id,
            'total_matches': total_matches,
            'jackpot_bet_id': jackpot_bet_id,
            'total_odd': float(total_odd),
            'bet_message': bet_message,
            'possible_win': float(possible_win),
            'status': status,
            'bet_amount': float(bet_amount)
        }
        for slip in slip_data:

            current_app.logger.info("Slip %r" % slip)
            created, bet_id, sub_type_id, odd_value, bet_amount, possible_win, status, win, game_id, start_time, away_team, home_team, bet_pick, bet_type, winning_outcome = slip
            slip_value = {
                'created': created,
                'bet_id': bet_id,
                'sub_type_id': sub_type_id,
                'odd_value': float(odd_value),
                'bet_amount': float(bet_amount),
                'possible_win': float(possible_win),
                'status': status,
                'win': win,
                'game_id': game_id,
                'start_time': start_time,
                'away_team': away_team,
                'home_team': home_team,
                'bet_type': bet_type,
                'bet_pick': bet_pick,
                'winning_outcome': winning_outcome
            }
            datas.append(slip_value)
        result = {'data': datas, 'meta': {'bet_info': bet_details}}
        resp = make_response(json.dumps(result), 200)
        return resp
	def test_setDefaultArgs(self):
		helper = Helper()

		model_name = 'rf:classifier'
		default_arguments = {'max_depth': 4, 'random_state': 0}

		helper.setDefaultArgs(model_name, default_arguments)

		self.assertEqual( helper.getDefaultArgs(model_name), default_arguments )

		try:
			model_name = 'jefferey'
			default_arguments = {'num_of_kids': 3, 
				'close_with_kids': False, 
				'kids_call': False,
				'happy_marriage': False}

			helper.setDefaultArgs(model_name, default_arguments)

			fail(self)
		except ValueError as ve:
			self.assertEqual( str(ve), 'Default model cannot be found: jefferey')

		try:
			model_name = 'rf:classifier'
			default_arguments = list([5, 10, 15, 20])

			helper.setDefaultArgs(model_name, default_arguments)

			fail(self)
		except ValueError as ve:
			self.assertEqual( str(ve), 'Arguments must be in dictionary format, not <class \'list\'> type!')


		# While there will be an error thrown if the model cannot be found, there is no
		#  way to check if the arguments are valid right now, so we will error later if 
		#  the model cannot be built

		model_name = 'rf:classifier'
		default_arguments = {'whatever_sort_of_args': True}
		helper.setDefaultArgs(model_name, default_arguments)
		self.assertEqual( helper.getDefaultArgs(model_name), default_arguments )
Beispiel #24
0
    def process_api_outbox(self, data):
        try:
            _code = 200
            self.log.info("process api outbox request data..... %r" % data)

            helper = Helper(current_app.logger)

            message = {
                "msisdn": data.get("user").get('referrer_msisdn'),
                "profile_id": data.get("user").get('profile_id')
            }

            result = helper.get_outbox_messages(message)

            self.log.info(
                "mobile api got outbox messages response returning ...")
        except JWTError as e:
            self.log.error("Exception on fetch outbox messages api %r " % e)
            _code = 400
            result = "Invalid token provided."
        resp = make_response(result, _code)
        return resp
    def __init__(self, name='', models=[], exp_type=None, metrics=[]):
        self.helper = Helper()
        self.unnamed_model_count = 0
        self.random_state = 0
        self._valid_experiment_types = ['classification', 'regression']

        self.metrics_manager = MetricsManager()

        self.type_of_experiment = None
        if exp_type:
            if type(exp_type) != str:
                raise ValueError(
                    'Experiment type attribute must be string, not {}'.format(
                        str(type(exp_type))))

            if self.isValidExperimentType(exp_type):
                self.type_of_experiment = exp_type
            else:
                raise ValueError(
                    'The provided experiment type is not supported: \'{}\'\nOnly these experiment types are supported: {}'
                    .format(exp_type, self.getValidExperimentTypes()))

        if type(name) is str:
            if name != '':
                self.name = name
            else:
                self.name = 'unnamed_experiment'
        else:
            raise ValueError(
                'Experiment name attribute must be string, not {}'.format(
                    str(type(name))))

        # initialize the dictionary of models within the experiment
        self.models_dict = {}

        # Add the models (if any) that the user wants to use
        if type(models) is list:
            if len(models) > 1:
                # Then add all of the model objects to the experiment
                for model in models:
                    self.addModel(model)
            elif len(models) == 1:
                # Add the only model to the experiment list
                self.addModel(models)
        elif type(models) is dict:
            # Add all of the models with their corresponding names provided from the user
            for name in models.keys():
                self.addModel(model, name)
        elif type(models) is str:
            self.addModel(models)
        else:
            raise ValueError(
                'Models must be in list format if more than one is provided. Ex. models=[\'rf\', \'Decision Tree\', RandomForestClassifer()... ]'
            )

        # initialize the metrics list
        self.metrics = []

        if type(metrics) is list:
            self.metrics = metrics
        elif type(metrics) is str:
            self.metrics = [metrics]
        else:
            raise ValueError(
                '\'metrics\' argument must be string or list of strings. Ex: [\'accuracy\', \'prec\']. Cannot be {}'
                .format(str(type(metrics))))
 def __init__(self, parserFunction):
     self.util = Helper()
     self.parser = parserFunction
     pass
        assembled = parser(operation, operand1, operand2)
        return assembled

    def _defaultParser(self, operation, operand1, operand2):
        return f"{mc(operation)}{mc(operand1)}{mc(operand2)}"

    def _LDMParser(self, operation, operand1, operand2):
        instr2 = Helper.strToBinary16(operand2)
        return f"{mc(operation)}{mc(operand1)}\n{instr2}"

    def _SHParser(self, operation, operand1, operand2):
        print(operand1, operand2)
        immediateBin = Helper.strToBinary16(operand2, fill=5)
        return f"{mc(operation)}{mc(operand1)}{mc(operand1)}{immediateBin}"

    def _ORGParser(self, operation, operand1, operand2):
        return operation + operand1.rjust(
            16, '0')  # return it like 'ORG00000000100'

    def _SETParser(self, operation, operand1, operand2):
        print(
            "[Warning]: the operation set is not supported for current processor, it will be converted to move"
        )
        operation = "MOV"
        operand2 = '1'
        return self._defaultParser(operation, operand1,
                                   operand2)  # return it like 'ORG100'


h = Helper()
Beispiel #28
0
    def post(self):
        data = self.params()
        msisdn = data.get('msisdn', 0)
        if not msisdn or msisdn == 0:
            msisdn = data.get('mobile')

        if not msisdn or msisdn == 0:
            message = {
                "success": {
                    "status": 400,
                    "message": "Invalid phone number"
                }
            }
            return make_response(json.dumps(message), 200)
        scorepesa = Scorepesa(current_app.logger)
        profile_id, new = scorepesa.create_profile({"msisdn": msisdn}, 0)
        helper = Helper(current_app.logger)
        password_set = False
        if new:
            code = get_code()
            password = None
            #self.generate_pass_str(data.get('password'))
            message = "Namba yako ya uthibitisho wa akaunti yako ya Scorepesa"\
               " ni %s. Ingiza namba kwenye tovuti kukamilisha mchakato huu" % (code, )
            network = get_network_from_msisdn_prefix(msisdn)
            helper.create_profile_settings(profile_id, code, password)
            outbox_id = helper.create_outbox(profile_id, msisdn, network,
                                             message)
            send_notification(msisdn, outbox_id, network, message)
        elif data.get('password'):
            password = self.generate_pass_str(data.get('password'))
            password_set = helper.set_password(profile_id, password)

        if profile_id > 0 and new:
            message = {
                "success": {
                    "status": 201,
                    "message": "Account created success"
                }
            }
        elif password_set:
            message = {
                "message": "Account password set successfully",
                "status": 201
            }
        elif profile_id == -1:
            message = {
                "success": {
                    "status":
                    500,
                    "message":
                    "Encountered problem trying to create profile, Please try again later"
                }
            }
        else:
            message = {
                "success": {
                    "status":
                    200,
                    "message":
                    "Account alreay exists, proceed to login and play with scorepesa.com"
                }
            }

        return make_response(json.dumps(message), 200)