Skip to content

Instantly share code, notes, and snippets.

@lockefox
lockefox / skill_trading_plot.r
Last active February 18, 2016 13:24
PROSPER Skill Trade/RMT Plotting script
library(RODBC)
library(ggplot2)
library(grid)
library(reshape)
library(scales)
library(data.table)
library(quantmod)
library(jsonlite)
library(cowplot)
library(plyr)
library(RODBC)
library(ggplot2)
library(grid)
library(reshape)
library(scales)
library(data.table)
library(quantmod)
library(jsonlite)
library(cowplot)
@lockefox
lockefox / PROSPER_CREST_markethistory.r
Last active July 1, 2016 19:13
Single Item CREST market history extraction - Like @EVEprosper
packages.list <- c("data.table",
"quantmod",
"jsonlite")
packages.new <- packages.list[!(packages.list %in% installed.packages()[,"Package"])]
if(length(packages.new)){
install.packages(packages.new)
}
library(data.table)
library(quantmod)
library(jsonlite)
#### Libraries ####
library(quantmod) #getSymbols/chartSeries
library(zoo) #rollmean/rollapply
library(plyr)
library(TTR)
library(prophet)
library(dplyr)
library(ggplot2)
library(ggthemes)
library(cowplot)
packages.list <- c(
"data.table",
"quantmod",
"jsonlite",
"prophet",
"dplyr",
"ggplot2",
"ggthemes",
"cowplot",
"zoo"
{
"killID": 64158479,
"solarSystemID": 30000157,
"killTime": "2017-08-19 16:28:48",
"moonID": 0,
"victim": {
"shipTypeID": 583,
"characterID": 94315372,
"characterName": "Canatana Jovakko",
"corporationID": 1699307293,
@lockefox
lockefox / fetch_zkb_solo.py
Last active August 19, 2017 16:54
zkb vs pandas demo
import requests
import pymongo
req = requests.get('https://zkillboard.com/api/losses/solo/')
req.raise_for_status()
recent_solo_losses_raw = req.json() #200 latest events
conn = pymongo.MongoClient(MONGO_CONNECTION_STRING)
conn.db.zkb.insert(recent_solo_losses_raw)
import pymongo
import pandas as pd
conn = pymongo.MongoClient(MONGO_CONNECTION_STRING)
exclude_data = {'_id': False, 'attackers': False, 'items': False}
raw_data = list(conn.db.zkb.find({}, projection=exclude_data))
kill_df = pd.DataFrame(raw_data)
## Split out JSON-blob columns into their own tables ##
# Rotates out key/value pairs into their own columns
position_df = pd.DataFrame(list(kill_df['position']))
victim_df = pd.DataFrame(list(kill_df['victim']))
zkb_df = pd.DataFrame(list(kill_df['zkb']))
## Merge pivoted data back into source frame ##
# row-index has not changed, append-horizontally
combined_df = pd.concat([kill_df, position_df, victim_df, zkb_df], axis=1)
data_columns = ['killID', 'solarSystemID', 'killTime', 'moonID']
pivot_column = 'items'
index_column = 'killID'
## Make source DataFrame ##
raw_df = pd.DataFrame(raw_data)
## Row-by-row rotate and append desired data ##
result_df = None
for row in raw_df.itertuples():