Пример #1
0
def autoPopRoomsByPropKey(request, prop_key=None):
    import json
    config = Config()
    propSvc = PropertyService(config)
    result = []
    if prop_key:
        temp = propSvc.fetchRoomsByPropertyKey(prop_key)
        if temp:
            # reformat for jQuery datatables
            for rooms in temp:
                # process beds
                beds = ''
                for val in rooms['beds']:
                    beds += val + ', '
                beds = beds[0:-2]
                room_config = config.getConfig('rooms')
                link = '<a target="_blank" href="' + room_config[
                    'details_url'] + rooms['roomTypeKey'] + '/">Details</a>'
                result.append({
                    'type': rooms['type'],
                    'view': rooms['view'],
                    'beds': beds,
                    'available': rooms['numAvailable'],
                    'link': link
                })
    return HttpResponse(json.dumps(result), content_type='application/json')
Пример #2
0
def index(request):
    config = Config()
    conn = Connection(config.getConfig('db'))
    db = conn.getDatabase('biglittle')
    main = render_to_string('home.html')
    home = render_to_string('layout.html', {'contents': main})
    return HttpResponse(home)
Пример #3
0
 def write_cache(self, key, value):
     info = self.read_cache()
     info.update({key: value})
     config = Config()
     fn = config.getConfig('cache_file')
     fh = open(fn, 'w')
     result = fh.write(json.dumps(info))
     fh.close()
     return result
Пример #4
0
 def del_cache(self, key):
     info = self.read_cache()
     if key in info:
         del info[key]
     config = Config()
     fn = config.getConfig('cache_file')
     fh = open(fn, 'w')
     result = fh.write(json.dumps(info))
     fh.close()
     return result
Пример #5
0
 def var_export(self, obj, ret_val=False):
     if ret_val == False:
         pprint.pprint(obj)
         return None
     config = Config()
     fn = config.getConfig('temp_file')
     temp = sys.stdout  # store original stdout object for later
     sys.stdout = open(fn, 'w')  # redirect all prints to this log file
     pprint.pprint(obj)
     sys.stdout.close()  # ordinary file object
     sys.stdout = temp  # restore print commands to interactive prompt
     return open(fn, 'r').read()
Пример #6
0
def index(request):
    config = Config()
    conn   = Connection(config.getConfig('db'))
    db     = conn.getDatabase()
    html   = '<h1>Welcome to Book Someplace!</h1>'
    html  += '<hr>'
    html  += '<ul>'
    import pprint
    for item in db.common.find() :
        html  += '<li>' +  pprint.saferepr(item) + '</li>'
    html  += '</ul>'
    main   = render_to_string('home.html')
    home   = render_to_string('layout.html', {'contents' : main})
    return HttpResponse(home)
Пример #7
0
 def read_cache(self, key=None, del_after_read=False):
     config = Config()
     fn = config.getConfig('cache_file')
     info = {}
     val = None
     if os.path.exists(fn):
         raw_info = open(fn, 'r').read().strip()
         if len(raw_info) > 1:
             info = json.loads(raw_info)
     if key:
         if key in info:
             val = info[key]
             if del_after_read:
                 self.del_cache(key)
     else:
         val = info
     return val
 def __init__(self):
     stemmer = PorterStemmer()
     stop_words = get_stop_words()
     conf = Config("config/system.config")
     lstm_model_path = conf.getConfig("PATHS", "tf_model")
     word2_vec_model = conf.getConfig("PATHS", "word_vec_model")
     self.max_seq = conf.getConfig("MODEL_PARAMS", "sentence_length")
     self.vec_dim = conf.getConfig("MODEL_PARAMS", "word_vec_dim")
     self.input_dim = conf.getConfig("MODEL_PARAMS", "feature_vector_dim")
     num_layers = conf.getConfig("MODEL_PARAMS", "num_layers")
     class_size = conf.getConfig("MODEL_PARAMS", "class_size")
     rnn_size = conf.getConfig("MODEL_PARAMS", "rnn_size")
     word_model = gensim.models.Word2Vec.load(word2_vec_model)
     self.model = Model(self.max_seq, self.input_dim, num_layers,
                        class_size, rnn_size)
     self.sess = tf.Session()
     saver = tf.train.Saver()
     saver.restore(self.sess, lstm_model_path)
            t = line.split()[2]
            #print line.split()
            if t.endswith('B-L'):
                tag.append(np.array([1, 0, 0]))
            elif t.endswith('I-L'):
                tag.append(np.array([0, 1, 0]))
            elif t.endswith('O'):
                tag.append(np.array([0, 0, 1]))
    assert (len(sentence) == len(sentence_tag))

    pkl.dump(sentence, open(output_embed, 'wb'))
    pkl.dump(sentence_tag, open(output_tag, 'wb'))
    print("Done................................")


word_vec_dim = conf.getConfig("MODEL_PARAMS", "word_vec_dim")
sen_len = conf.getConfig("MODEL_PARAMS", "sentence_length")
word_vec_model = conf.getConfig("PATHS", "word_vec_model")
train_file = conf.getConfig("PATHS", "train_csv_path")
test_file_one = conf.getConfig("PATHS", "test_csv_path")
train_embedding = conf.getConfig("PATHS", "train_embedding")
train_tag = conf.getConfig("PATHS", "train_tag")
test_embedding = conf.getConfig("PATHS", "test_embedding")
test_tag = conf.getConfig("PATHS", "test_tag")

word2vec_model = gensim.models.Word2Vec.load(word_vec_model)

get_input(word2vec_model,
          word_vec_dim,
          train_file,
          train_embedding,
Пример #10
0
 def updateBorrowerListener(self, arg):
     # imports
     from decimal import Decimal
     from bson.decimal128 import Decimal128
     # init vars
     loan = arg['loan']
     amtPaid = arg['amtPaid']
     amtDueFromLoan = Decimal(0.00)
     amtPaidFromLoan = Decimal(0.00)
     amtDueFromUser = Decimal(0.00)
     amtPaidFromUser = Decimal(0.00)
     # build discrepancy log file name
     config = Config()
     log_fh = open(config.getConfig('discrepancy_log'), 'a')
     # current date
     from time import gmtime, strftime
     now = strftime('%Y-%m-%d', gmtime())
     # get amountDue and amountPaid totals from user instance
     borrowerKey = loan.get('borrowerKey')
     borrower = self.fetchUserByBorrowerKey(borrowerKey)
     if not borrower:
         log_fh.write(now + ' : User entry for ' + borrowerKey +
                      ' not found ' + "\n")
     else:
         # convert from NumberDecimal to Python decimal.Decimal
         amtDueFromUser = borrower.get('amountDue').to_decimal()
         amtPaidFromUser = borrower.get('amountPaid').to_decimal()
         # update amounts
         amtDueFromUser -= amtPaid
         amtPaidFromUser += amtPaid
         # perform update
         filt = {'userKey': borrower.getKey()}
         updateDoc = {
             '$set': {
                 'amountDue': Decimal128(str(amtDueFromUser)),
                 'amountPaid': Decimal128(str(amtPaidFromUser))
             }
         }
         self.collection.update_one(filt, updateDoc)
         # accuracy check: calculate amountDue and amountPaid totals from loan.payments
         for doc in loan.getPayments():
             amtDueFromLoan += doc['amountDue']
             amtPaidFromLoan += doc['amountPaid']
         # log any discrepancies but do not take any further action
         if amtDueFromUser != amtDueFromLoan:
             log_fh.write(now + ' : Amount due discrepancy for : ' +
                          borrower.getFullName() + ' : ' + borrowerKey +
                          "\n")
             log_fh.write('--data from "users" collection: ' +
                          str(amtDueFromUser) + "\n")
             log_fh.write('--data from "loans" collection: ' +
                          str(amtDueFromLoan) + "\n")
         if amtPaidFromUser != amtPaidFromLoan:
             log_fh.write(now + ' : Amount paid discrepancy for : ' +
                          borrower.getFullName() + ' : ' + borrowerKey +
                          "\n")
             log_fh.write('--data from "users" collection: ' +
                          str(amtPaidFromUser) + "\n")
             log_fh.write('--data from "loans" collection: ' +
                          str(amtPaidFromLoan) + "\n")
     log_fh.close()
Пример #11
0
sys.path.append(src_path)

# enable error display
import cgitb
cgitb.enable(display=1, logdir='../data')

# custom imports
from config.config import Config
from web.responder.html import HtmlResponder
from db.mongodb.connection import Connection
from sweetscomplete.domain.product import ProductService
from sweetscomplete.entity.product import Product

# create CustomerService instance
config = Config()
db_config = config.getConfig('db')
prod_conn = Connection(db_config['host'], db_config['port'], Product)
prod_service = ProductService(prod_conn, db_config['database'])

# HTML output
message = 'SORRY! Unable to find information on this product'
response = HtmlResponder('templates/details.html')

# check for form posting
import cgi
form = cgi.FieldStorage()

if 'product' in form:

    # get product key
    key = form['product'].value
Пример #12
0
import cgitb
cgitb.enable(display=1, logdir='../data')

# custom imports
from config.config import Config
from web.responder.html import HtmlResponder
from web.auth import SimpleAuth
from db.mongodb.connection import Connection
from sweetscomplete.domain.customer import CustomerService
from sweetscomplete.entity.customer import Customer
from sweetscomplete.domain.product import ProductService
from sweetscomplete.entity.product import Product

# create CustomerService instance
config       = Config()
db_config    = config.getConfig('db')
cust_conn    = Connection(db_config['host'], db_config['port'], Customer)
cust_service = CustomerService(cust_conn, db_config['database'])
prod_conn    = Connection(db_config['host'], db_config['port'], Product)
prod_service = ProductService(prod_conn, db_config['database'])

# init vars
auth     = SimpleAuth(cust_service, config.getConfig('session_storage'))
cust     = auth.getIdentity()

# HTML output
response = HtmlResponder('templates/select.html')
response.addInsert('%message%', '<br>')
response.addInsert('%ajax_url%', config.getConfig('ajax_url'))

# output
Пример #13
0
import redis
import sys
sys.path.append("../../..")
from config.config import Config
conf = Config()
configs = conf.getConfig()
class BjjsRedis:
    def __init__(self):
        self.conn = redis.Redis(host=configs.REDIS['host'], port=configs.REDIS['port'], db=0,password=configs.REDIS['pass'])

    def save(self,key,val,ex=None):
        self.conn.set(key,val,ex)

    def get(self,key):
        return self.conn.get(key)


if __name__ == '__main__':
    rr = BjjsRedis()
    rr.save("test","test1")

    print rr.get("test")

    if(rr.get("test")):
        print "exist"
    else:
        print "not exist"
Пример #14
0
import cgitb
cgitb.enable(display=1, logdir=".")

# custom imports
from config.config import Config
from web.responder.html import HtmlResponder
from web.auth import SimpleAuth
from db.mongodb.connection import Connection
from sweetscomplete.domain.customer import CustomerService
from sweetscomplete.entity.customer import Customer
from sweetscomplete.domain.purchase import PurchaseService
from sweetscomplete.entity.purchase import Purchase

# create CustomerService instance using configuration class
config = Config()
db_config = config.getConfig('db')
cust_conn = Connection(db_config['host'], db_config['port'], Customer)
cust_service = CustomerService(cust_conn, db_config['database'])
purch_conn = Connection(db_config['host'], db_config['port'], Purchase)
purch_service = PurchaseService(purch_conn, db_config['database'])

# init vars
auth = SimpleAuth(cust_service, config.getConfig('session_storage'))
cust = auth.getIdentity()
response = HtmlResponder('templates/history.html')

# get page number
import cgi
info = cgi.FieldStorage()

if 'page' in info:
import re
from nltk.tokenize import sent_tokenize
from nltk.tokenize import TweetTokenizer
from nltk.tokenize import word_tokenize
from nltk.stem import PorterStemmer
from config.config import Config
import random
from nltk import pos_tag
from utils.util import *
import csv

stemmer = PorterStemmer()
conf = Config("config/system.config")
training_data = conf.getConfig("PATHS", "training_data_path")
test_data = conf.getConfig("PATHS", "test_data")
train_csv_path = conf.getConfig("PATHS", "train_csv_path")
test_csv_path = conf.getConfig("PATHS", "test_csv_path")
max_seq_length = conf.getConfig("MODEL_PARAMS", "sentence_length")


def message_to_sentences(message, remove_stopwords=False):
    raw_sentences = sent_tokenize(clean_str(message))
    sentences = []
    for raw_sentence in raw_sentences:
        if "<" in raw_sentence and ">" in raw_sentence:
            tokens = sentence_to_token_list(raw_sentence)
            if len(tokens) <= max_seq_length:
                sentences.append(tokens)
        """
        elif "<" not in raw_sentence and ">" not in raw_sentence:
            tokens = sentence_to_token_list(raw_sentence)
Пример #16
0
                model.output_data: test_a_out
            })
            print("epoch %d:" % e)
            print('test_a score:')
            m = f1(pred, test_a_out, length)
            if m > maximum:
                maximum = m
                save_path = saver.save(sess, model_path)
                print("max model saved in file: %s" % save_path)
                pred, length = sess.run([model.prediction, model.length], {
                    model.input_data: test_b_inp,
                    model.output_data: test_b_out
                })
                print("test_b score:")
                f1(pred, test_b_out, length)


conf = Config("config/system.config")
model_path = conf.getConfig("PATHS", "tf_model")
input_dim = conf.getConfig("MODEL_PARAMS", "feature_vector_dim")
sentence_length = conf.getConfig("MODEL_PARAMS", "sentence_length")
class_size = conf.getConfig("MODEL_PARAMS", "class_size")
rnn_size = conf.getConfig("MODEL_PARAMS", "rnn_size")
num_layers = conf.getConfig("MODEL_PARAMS", "num_layers")
batch_size = conf.getConfig("MODEL_PARAMS", "batch_size")
epoch = conf.getConfig("MODEL_PARAMS", "epoch")

train(batch_size, sentence_length, input_dim, num_layers, class_size, rnn_size)

print "Training Done..............."