Skip to content

Instantly share code, notes, and snippets.

View QuantVI's full-sized avatar

QuantVI

View GitHub Profile
@QuantVI
QuantVI / qwerty.py
Created September 28, 2018 20:43
How to share your code
# This is a comment
# I typed this directly into http://gist.github.com
a = " ".join(["It's",'easy','to','use','to','share','code.'])
print(a)
@QuantVI
QuantVI / class_example_00.py
Last active October 29, 2018 11:58
From Codecademy Intensive - Programming with Python - extended example from the lesson on Python Classes.
class Student:
def __init__(self,name,year):
self.name= name
self.year=year
self.grades = []
def __repr__(self):
return "{nn} in year {yy}".format(nn=self.name,yy=self.year)
def add_grade(self,grade):
# User class.
# Tome Rater object contains Users
class User(object):
def __init__(self, name, email):
self.name = name
self.email = str(email)
self.books = {}
def get_email(self):
# print(self.email)
from TomeRater import *
Tome_Rater = TomeRater()
#Create some books:
book1 = Tome_Rater.create_book("Society of Mind", 12345678)
novel1 = Tome_Rater.create_novel("Alice In Wonderland", "Lewis Carroll", 12345)
#novel1.set_isbn(9781536831139)
nonfiction1 = Tome_Rater.create_non_fiction("Automate the Boring Stuff", "Python", "beginner", 1929452)
nonfiction2 = Tome_Rater.create_non_fiction("Computing Machinery and Intelligence", "AI", "advanced", 11111938)
@QuantVI
QuantVI / python_oop.py
Created November 6, 2018 12:34
OOP with Restaurants, Franchises, and Businesses
class Menu:
def __init__(self, name, items, start_time, end_time):
self.name = name
self.items = items
self.start_time = start_time
self.end_time = end_time
def __repr__(self):
sent = "{} Menu: served {} to {}"
return sent.format(self.name,self.start_time,self.end_time)
@QuantVI
QuantVI / cluster_reviewers.py
Created May 27, 2019 23:18
Quick Test of KMeans in Scikit Learn
# Data taken from
# https://archive.ics.uci.edu/ml/datasets/Tarvel+Review+Ratings
# there is an error in the dataset for User 2713
#the row is shifted, and one value is mis-entered.
"""
Data Set Information:
This data set is populated by capturing user ratings from Google reviews.
Reviews on attractions from 24 categories across Europe are considered.
Google user rating ranges from 1 to 5 and average user rating
@QuantVI
QuantVI / scribe_report_v2.py
Created July 23, 2019 22:27
The scribe takes in JSON output from ElasticSearch results. It then dynamically transforms the output into tabular format, writing the data straight to an Excel file using an applicable Excel module.
# -*- coding: utf-8 -*-
desc1 = ''' The scribe takes in JSON output from ElasticSearch results.
It then dynamically transforms the output into tabluar format,
writing the data straight to an Excel file using an applicable
Excel module.'''
# See report version 1 "scribe_report.py" for code comments on the core build
# verison 1 code now in excel_printer.py
import json
@QuantVI
QuantVI / excel_printer.py
Created July 23, 2019 22:35
Determine if the JSON result is 1 of 3 types, that over 12 different ElasticSearch queries could return. Parse based on this general type, and put the results into a readable format in Excel.
# -*- coding: utf-8 -*-
# import json
# import openpyxl
# This next section can be its own script if necessary
# begin dont_overwrite ----
ret_values = ['unknown','level_1','level_2','multi_s']
def detectStructure (jsondata):
@QuantVI
QuantVI / count_email_per_yr.json
Created July 23, 2019 23:00
ElasticSearch query: emails per year. Example of an aggregation query returning results in JSON format. These result were passed to "Excel Printer" via "Scribe Report", two other gists you'll find here.
{ "size": 0,
"query": {
"term": {"propertyId":"{{property_id}}"}
},
"aggs": {
"email_recency": {
"date_histogram" : {
"field": "checkinDate",
"interval": "year",
"format" : "yyyy-MM-dd"
@QuantVI
QuantVI / res_per_Yr_with_conf_status.json
Created July 23, 2019 23:00
ElasticSearch query: guest reservations per year, with confirmation status. Example of an aggregation query returning results in JSON format. These result were passed to "Excel Printer" via "Scribe Report", two other gists you'll find here.
{ "size": 0,
"query": {
"term": {"propertyId":"{{property_id}}"}
},
"aggs": {
"reservation_over_time": {
"date_histogram" : {
"field": "checkinDate",
"interval": "year",
"format" : "yyyy-MM-dd"