Beispiel #1
0
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
#

from DatabaseClient import DatabaseClient

client = DatabaseClient(hostname=None)
client('drop btable dan_kiva;')
client('create btable dan_kiva from data/kiva.csv;')
client(
    'import samples data/kiva_flat_table_model_500.pkl.gz into dan_kiva iterations 500;'
)
print client('select * from dan_kiva limit 5;')

fields_of_interest = [
    'partner_status',
    'partner_rating',
    'delinquent',
    'default_rate',
    'loan_amount',
    'gender_ratio',
]
#! /Users/jon/anaconda3/bin/python3
"""
This file tests the functionality of the DatabaseClient class
It performs the following actions

"""

import random
from DatabaseClient import DatabaseClient

dbClient = DatabaseClient()

print("Resetting the database")
dbClient.reset_database()

print("Adding some data")
dataDict = dict()
types = ["electric", "gas", "wind", "solar"]
datetime = "12:00 10/21/19",
usages = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]

dataDict['type'] = 'electric'

for i in range(100):
    print("Uploading random data #{}/100".format(i))
    dataDict[i] = dict()
    dataDict[i]['type'] = random.choice(types)
    dataDict[i]['dt'] = datetime
    dataDict[i]['usage'] = random.choice(usages)
    dbClient.add_data_from_dict(dataDict[i])
print("Data has been added")