Skip to content

Instantly share code, notes, and snippets.

View van-william's full-sized avatar

William VanBuskirk van-william

View GitHub Profile
@van-william
van-william / tulip-to-lambda-to-fivetran.py
Last active September 28, 2023 16:55
lambda function to query tulip tables and write to fivetran
import json
from tulip_api import TulipAPI,TulipTable, CachedTulipTable
import pandas as pd
import numpy as np
from datetime import datetime
import os
def lambda_handler(event, context):
# instance url, api key, and api secret are stored as environment variables
instance_url = os.getenv('instance')
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
fig, ax = plt.subplots(figsize=(15, 5))
sns.lineplot(ax=ax, data=df_chapters, hue='book', linewidth=3, x='chapter', y='weighted_score')
plt.xlabel("Chapter #")
plt.ylabel("Avg. Sentiment")
plt.title("Gospels Analysis - Avg. Sentiment by Chapter\n(Higher Values are Positive Sentiment; Lower Values are Negative Sentiment)")
plt.show(fig)
import pandas as pd
import numpy as np
from transformers import pipeline
def sentiment_score_weight(sentiment):
label = sentiment['label']
score = float(sentiment['score'])
label_value = 1 if label == 'POSITIVE' else -1
weighted_score = label_value*score
return weighted_score
@van-william
van-william / bible_text_processing.py
Created January 15, 2023 04:22
This gist creates additional columns for the bible nlp project
def book_split(text):
book = text.split(' ')
return ' '.join(book[0:len(book)-1])
def chapter_split(text):
reference_list = text.split(' ')
chapter_verse = reference_list[-1].split(':')
return int(chapter_verse[0])
@van-william
van-william / bible_text_extraction.py
Created January 15, 2023 04:09
This gist shows how to read the Bible as a text file into a pandas dataframe
bible_url = 'https://bereanbible.com/bsb.txt'
with open('./data/bereanbible.txt', 'r') as f:
text = f.read()
response = requests.get(bible_url)
raw_bible = response.text
bible_list = raw_bible.splitlines()
bible_array = np.array([item.split('\t') for item in bible_list])
def printable_string(text):
filtered_string = ''.join(s for s in text if s in string.printable)
def sentiment_pipeline(text, model):
sentiment = model(text)
return pd.Series([sentiment[0]['label'], sentiment[0]['score']])
model = pipeline("sentiment-analysis")
df[['sentiment_label','sentiment_score']]=df['prompt'].apply(lambda x: sentiment_pipeline(text=x,model=model))
from sklearn.model_selection import train_test_split
def split_data(df: pd.DataFrame, parameters: Dict) -> Tuple:
"""Splits data into features and targets training and test sets.
Args:
data: Data containing features and target.
parameters: Parameters defined in parameters/data_science.yml.
Returns:
Split data.
%%writefile exploratory_data_analysis.py
import pandas as pd
import numpy as np
import seaborn as sns
## Python Code Here
@van-william
van-william / iot-iphone-stream.sql
Created July 15, 2022 01:48
Streaming Iot Plug and Play Telemetry to SQL server via Azure Stream Analytics
SELECT
geolocation.lat,
geolocation.lon,
geolocation.alt,
system.timestamp as "event_time"
INTO
[sql]
FROM
[iot]
@van-william
van-william / helium_stream_analytics.sql
Last active January 2, 2022 20:00
Azure Stream Analytics Query
SELECT
TRY_CAST(decoded.payload.TempC_SHT AS float) AS InternalTemp_C,
(TRY_CAST(decoded.payload.TempC_SHT AS float) * 9/5) + 32 AS InternalTemp_F,
TRY_CAST(decoded.payload.Hum_SHT AS float) AS InternalHum,
TRY_CAST(decoded.payload.TempC_DS AS float) AS ExternalTemp_C,
(TRY_CAST(decoded.payload.TempC_DS AS float) * 9/5) + 32 AS ExternalTemp_F,
TRY_CAST(EventProcessedUtcTime AS datetime) AS ProcessTimeUTC,
TRY_CAST(EventEnqueuedUtcTime AS datetime) AS QueueTimeUTC,
EventProcessedUtcTime AS ProcessedTimeRaw,
EventEnqueuedUtcTime AS EnqueuedTimeRaw,