Skip to content
Snippets Groups Projects
Commit 82680673 authored by Tamas Bunth's avatar Tamas Bunth
Browse files

Add additional related stuff to git

parent 6f93e627
No related branches found
No related tags found
No related merge requests found
drop table if exists battery_usage cascade;
drop table if exists dim_user cascade;
drop table if exists dim_statistics cascade;
drop table if exists dim_time cascade;
create table battery_usage
(
ID int8 NOT NULL,
battery INTEGER,
time_surid int8,
user_surid int8,
statistics_surid int8,
PRIMARY KEY (ID)
);
create table dim_user (
surid int8 not null,
id int8 not null,
email varchar(255),
password varchar(255),
token varchar(255),
android_version INTEGER,
birth_date TIMESTAMP,
device_type VARCHAR(255),
primary key (id)
);
create table dim_statistics (
surid int8 not null,
id int8 not null,
location_dist DOUBLE PRECISION,
brightness INTEGER,
wifi_on BOOLEAN,
mobil_data_on BOOLEAN,
bluetooth_on BOOLEAN,
nfc_on BOOLEAN,
sleep_time INTEGER,
battery_temp DOUBLE PRECISION,
mobile_data_usage INTEGER,
wifi_data_usage INTEGER,
process_count INTEGER
);
CREATE TABLE dim_time (
surid int8 not null,
actual_time timestamp not null,
is_night BOOLEAN not null,
is_weekend BOOLEAN not null
);
\ No newline at end of file
curl -X POST --header 'Content-Type: application/json' \
--header 'Accept: */*' \
--header "Authorization: $1" \
-d '{
"battery": 97,
"bluetoothOn": true,
"brightness": 20,
"location": {
"latitude": 49.090638,
"longitude": -126.947656
},
"mobilDataOn": true,
"nfcOn": true,
"sleepTime": 15,
"wifiOn": true,
"isWifiOn": true,
"isBluetoothOn": true,
"isNfcOn": true,
"isMobilDataOn": true
}' 'http://localhost:8090/api/data'
This diff is collapsed.
- dim_user_data: distinct
SELECT
data.battery,
data.actual_time,
us.android_version,
us.birth_date,
us.device_type,
data.id,
data.user_id,
data.location_lat,
data.location_long,
data.brightness,
data.wifi_on,
data.mobil_data_on,
data.bluetooth_on,
data.nfc_on,
data.sleep_time,
data.battery_temp,
data.mobile_data_usage,
data.wifi_data_usage,
COUNT(proc.mobile_data_id) as process_count
FROM
mobil_data as data
INNER JOIN mobil_user as us ON data.user_id = us.id
INNER JOIN process as proc ON proc.mobile_data_id = data.id
WHERE
data.is_charging = TRUE
GROUP BY data.id, us.android_version,us.birth_date,
us.device_type;
\ No newline at end of file
CREATE TABLE kiszopo_test (
battery INTEGER,
actual_time TIMESTAMP not null,
android_version INTEGER,
birth_date TIMESTAMP,
device_type VARCHAR(255),
location_lat DOUBLE PRECISION,
location_long DOUBLE PRECISION,
brightness INTEGER,
wifi_on BOOLEAN,
mobil_data_on BOOLEAN,
bluetooth_on BOOLEAN,
nfc_on BOOLEAN,
sleep_time INTEGER,
battery_temp DOUBLE PRECISION,
mobile_data_usage INTEGER,
wifi_data_usage INTEGER,
process_count INTEGER
);
\ No newline at end of file
# Connect to database
sudo su - postgres
\connect mobildata
# Show relations
\d
# Kilépés
\q
File added
Postgres:
create database anal_data
\connect anal_data
SELECT * FROM pg_catalog.pg_tables;
{
"battery": 97,
"bluetooth_on": true,
"brightness": 20,
"id": 3,
"location_lat": 49.090638,
"location_long": -126.947656,
"mobil_data_on": true,
"nfc_on": true,
"sleep_time": 15,
"user_id": 1,
"wifi_on": true
},
/home/wastack/tmp/nifi-1.4.0/logs
/var/log/postgresql
sudo bin/nifi.sh install dataflow
sudo -u postgres psql
\connect anal_data
\l <- list databases
\t <- list tables
Or:
SELECT * FROM pg_catalog.pg_tables;
Run sql file:
\i /home/wastack/intellij/onlab/MobilDataServer/adattarhaz1.sql
\i /home/wastack/intellij/onlab/MobilDataServer/star_scheme1.sql
adatbázis nevek:
anal_data
mobildata
sudo apt-get install build-dep python-psycopg2
easy_install psycopg2
postgresql+psycopg2://postgres:postgres@localhost:5432/anal_data
select * from kiszopo_test;
Superset
--------
virtualenv venv
. ./venv/bin/activate
superset runserver -d
username: wastack
password: postgres
Analitikus
----------
Ténytábla:
- battery
- ido_id
- statistics_id
- user_id
### Első szint
- Idő:
Naptári dátum
Nap megnevezése
Hét hanyadik napja
Hónap megnevezése
Évszám
Ünnep
Karácsony
Húsvét
Napszakasz
Nap hanyadik órája
- User:
Android verzió
Születési dátum
Születési év
Eszköz típusa
Samsung jelző
Huawei jelző
Nexus jelző
Oneplus jelző
- Statisztics:
adat kód (eredeti ID)
Elmozdulás: 10 percre átlagolva, eltelt időre normalizálva
Fényerő
WifiOn
MobilDataOn
BlueToothOn
NFCon
sleep_time
battery_temp DOUBLE PRECISION,
mobile_data_usage: abban az időszakban
wifi_data_usage
actual_time TIMESTAMP not null,
Eltelt idő, az előző adatfelvétel óta.
is_charging BOOLEAN
Futó appok száma
Fut-e Facebook jelző
drop table if exists battery_fact cascade;
drop table if exists dim_time cascade;
drop table if exists dim_statistics cascade;
drop table if exists dim_user_data cascade;
CREATE TABLE battery_fact (
battery INTEGER NOT NULL,
time_id INT8,
user_id INT8,
statistics_id INT8,
PRIMARY KEY (statistics_id)
);
CREATE TABLE dim_time (
sur_id SERIAL NOT NULL PRIMARY KEY,
stat_id INT8 NOT NULL,
calendar_datetime TIMESTAMP NOT NULL,
day_of_week_name VARCHAR(20),
day_of_week INTEGER,
month_name VARCHAR(20),
month INTEGER,
jear INTEGER,
holiday BOOLEAN,
christmas BOOLEAN,
day_period INTEGER,
hour_of_day INTEGER
);
alter table battery_fact
add CONSTRAINT time_id_foreign_key
FOREIGN KEY ("time_id")
REFERENCES dim_time;
CREATE TABLE dim_user_data (
sur_id SERIAL NOT NULL PRIMARY KEY,
user_id INT8 NOT NULL,
android_api_version INTEGER,
birth_year INTEGER,
birth_date DATE,
device_type VARCHAR(50),
is_samsung BOOLEAN,
is_nexus BOOLEAN,
is_huawei BOOLEAN,
is_oneplus BOOLEAN
);
alter table battery_fact
add CONSTRAINT user_id_foreign_key
FOREIGN KEY ("user_id")
REFERENCES dim_user_data;
CREATE TABLE dim_statistics (
sur_id SERIAL NOT NULL PRIMARY KEY,
stat_id INT8 NOT NULL,
movement INTEGER,
brightness INTEGER,
wifi_on BOOLEAN,
mobil_data_on BOOLEAN,
bluetooth_on BOOLEAN,
nfc_on BOOLEAN,
sleep_time INTEGER,
battery_temp DOUBLE PRECISION,
mobile_data_usage INTEGER,
wifi_data_usage INTEGER,
is_charging BOOLEAN,
process_count INTEGER,
is_facebook_on BOOLEAN
);
alter table battery_fact
add CONSTRAINT statistics_id_foreign_key
FOREIGN KEY ("statistics_id")
REFERENCES dim_statistics;
\ No newline at end of file
select *
FROM
battery_fact as fact
INNER JOIN dim_time as tim ON tim.sur_id = fact.time_id
INNER JOIN dim_statistics as stat ON stat.sur_id = fact.statistics_id
INNER JOIN dim_user_data as usi ON usi.sur_id = fact.user_id;
\ No newline at end of file
/*INSERT INTO battery_fact (battery,
time_id,
user_id,
statistics_id)
SELECT *, 2
FROM
(select DISTINCT tim.sur_id
FROM
dim_time as tim
WHERE tim.stat_id = 76) as fuckme
UNION ALL
(select DISTINCT use.sur_id
FROM
dim_user_data as use
WHERE use.user_id = 1 LIMIT 1)
UNION ALL
(select DISTINCT stat.sur_id
FROM
dim_statistics as stat
WHERE stat.stat_id = 76);*/
INSERT INTO battery_fact (battery,
time_id,
user_id,
statistics_id)
SELECT 23, fuckme.sur_id, fuckmehard.sur_id, fuckmeveryhard.sur_id
FROM
(select DISTINCT tim.sur_id
FROM
dim_time as tim
WHERE tim.stat_id = 76) as fuckme
,
(select DISTINCT use.sur_id
FROM
dim_user_data as use
WHERE use.user_id = 1 LIMIT 1) as fuckmehard
,
(select DISTINCT stat.sur_id
FROM
dim_statistics as stat
WHERE stat.stat_id = 76) as fuckmeveryhard;
\ No newline at end of file
INSERT INTO battery_fact (battery,
time_id,
user_id,
statistics_id)
SELECT ${battery}, fuckme.sur_id, fuckmehard.sur_id, fuckmeveryhard.sur_id
FROM
(select DISTINCT tim.sur_id
FROM
dim_time as tim
WHERE tim.stat_id = ${stat_id}) as fuckme
,
(select DISTINCT use.sur_id
FROM
dim_user_data as use
WHERE use.user_id = ${user_id} LIMIT 1) as fuckmehard
,
(select DISTINCT stat.sur_id
FROM
dim_statistics as stat
WHERE stat.stat_id = ${stat_id}) as fuckmeveryhard;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment