Skip to content

Instantly share code, notes, and snippets.

View MatheusrdSantos's full-sized avatar

Matheus Santos MatheusrdSantos

  • Natal, Brazil
View GitHub Profile
@MatheusrdSantos
MatheusrdSantos / code.py
Created August 30, 2021 10:01
Build wikipedia network
todo_lst = [(0, SEED)]
todo_set = set(SEED)
done_set = set()
g = nx.DiGraph()
layer, page = todo_lst[0]
# a consulta será realizada até o nível 1
while layer < 2:
# remove a página atual da lista de páginas pendentes
@MatheusrdSantos
MatheusrdSantos / cql_cities.cql
Created April 25, 2021 19:38
Creation script for cassandra cities database
CREATE KEYSPACE cities WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 2};
CREATE TABLE IF NOT EXISTS city_per_country (
id uuid,
name text,
country text,
state text,
population int,
PRIMARY KEY (country, population, id)
) WITH CLUSTERING ORDER BY (population DESC);
@MatheusrdSantos
MatheusrdSantos / mysql_cities.sql
Created April 25, 2021 19:36
Creation script to store cities
CREATE DATABASE IF NOT EXISTS cities_db;
CREATE TABLE IF NOT EXISTS Countries (
id int NOT NULL AUTO_INCREMENT,
name varchar(255) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS States (
id int NOT NULL AUTO_INCREMENT,
version: "2.3"
services:
mysql1:
image: mysql
container_name: mysql1
hostname: mysql1
mem_limit: 6144M
mem_reservation: 1536M
ports:
- "3306:3306"
@MatheusrdSantos
MatheusrdSantos / docker-compose.yml
Created April 25, 2021 18:40
Cassandra cluster docker
version: "2.3"
networks:
cassandra-final:
services:
cass1:
image: cassandra
container_name: cass1
hostname: cass1
mem_limit: 2048M
mem_reservation: 512M
@MatheusrdSantos
MatheusrdSantos / plot.py
Last active October 20, 2020 22:40
Plot social distancing
fig, ax = plt.subplots(nrows=1,ncols=6,figsize=(25,4))
states = ['SP', 'RJ', 'AM', 'CE', 'BA', 'RN']
for i, state in enumerate(states):
state_data = data_br_merged.loc[data_br_merged['state']==state]
data_moving_average = state_data.rolling(window=7).mean().dropna()
data_mean = data_moving_average.apply(normalize, df=data_moving_average, axis=1)[['residential_normalized', 'new_cases_normalized']]
data_mean.plot(legend=True, ax=ax[i])
ax[i].set_title(state,fontsize=12,ha='right')
ax[i].set_xticklabels(["", "Mar","", "", "", "Oct"])
@MatheusrdSantos
MatheusrdSantos / code.py
Last active October 2, 2020 18:16
Adding styles to plot
# iterate over the selected states and prepare the plot
for i, state in enumerate(states):
other_states = data_br_unstack[item].rolling(window=7).mean().dropna()
# the dates must be converted to integers
other_states.index = mdates.date2num(other_states.index)
other_states.plot(legend=False,color=[(0.7,0.7,0.7)],linewidth=1, alpha=0.4, ax=ax[i])
selected_state = data_br_unstack[item][state].rolling(window=7).mean().dropna()
# the dates must be converted to integers
selected_state.index = mdates.date2num(selected_state.index)