Skip to main content

Hobby coding project - Queries for play whe data


I have an interest in open data and being able to query that data and gain beautiful insights. One data set that would be interesting is the play whe results data. Our open data is lacking in Trinidad and I will try to contact NLCB to see if they can provide and maintain the data online. But in the meanwhile I will use randomised data to create the website and do my testing.

First thing I did was install sqlite on termux

pkg update && pkg upgrade
pkg install sqlite
sqlite3 --version

Create my database in my project folder

sqlite3 results.db

Useful commands

.exit
.quit

Exit from multiline prompt

;

SQL to create my table (create_tbl_results.sql)

CREATE TABLE DrawResults (
    DrawNo INTEGER PRIMARY KEY,                           DrawDate DATE,
    ResultNo INTEGER CHECK (ResultNo BETWEEN 1 AND 36),
    DrawTime INTEGER CHECK (DrawTime BETWEEN 1 AND 4)
);

SQL to create the random data (random.sql)

WITH RECURSIVE numbers(n) AS (
    SELECT 1
    UNION ALL
    SELECT n + 1
    FROM numbers
    WHERE n < 10000
)
INSERT INTO DrawResults (DrawNo, DrawDate, ResultNo, DrawTime)
SELECT
    n AS DrawNo,

    -- Start at 2010-01-01 and advance 1 day every 4 draws
    date('2010-01-01', '+' || ((n - 1) / 4) || ' days') AS DrawDate,

    -- Random number from 1 to 36
    (abs(random()) % 36) + 1 AS ResultNo,

    -- DrawTime cycles 1 to 4
    ((n - 1) % 4) + 1 AS DrawTime
FROM numbers;

SQL to query the top 10 called numbers (query_top10.sql)

SELECT
    ResultNo,
    COUNT(*) AS ResultCount
FROM DrawResults
GROUP BY ResultNo
ORDER BY ResultCount DESC
LIMIT 10;

Commands to run the sql (setup.sh)

rm results.db
sqlite3 results.db < create_tbl_results.sql
sqlite3 results.db < random.sql
sqlite3 results.db < query_top10.sql

Start the database from scratch in termux

chmod +x setup.sh
./setup.sh

Next up in next blog post is to create a website to display the results that will eventually be live on github pages

Update - website has been started here - https://hassan-theitguy.github.io/play-whe-queries/

Comments

Popular posts from this blog

How do we fix this world?

It is 4:39 pm and I have decided to write. It is a peaceful and quiet day. I am thinking about God, and how this life is a test. There is so much happening in this world that could make us sad. But we do not have to remain in that sadness when we put our trust in God. God wants good for us. God wants us to experience peace, and even happiness, despite what surrounds us. How do we fix this world? My friend Chatty suggests that maybe a better question is: What kind of person do I choose to be in this world? Because when enough people answer that question well, that is how real change begins. I want to be the kind of person that God is pleased with. Someone guided by God, not by ego. Someone who chooses patience over anger, humility over pride, and sincerity over appearances. I am doing reasonably well, but I am not perfect. And maybe perfection is not the goal. Growth is. Awareness is. Returning to what is right, again and again, is. I want to grow, and I will keep adjusting myself when ...

Mundane

It is 123am and I have decided to write. I have this new idea for a book called Mundane. It would be me writing about the ordinary. We chase the extraordinary but there is beauty in the ordinary. There is beauty in the simple. There is beauty in the everyday. What about God? We often think about God in grand terms. But what if God is simple too? What if God is mundane? What if we look for God in the everyday moments? I sit in this dark room with the air conditioning on. The fan is also on. The curtain is down but I imagine the moonlight shining on the grass outside. The cats are probably sleeping. I wonder if anyone else in the neighbourhood is awake at this hour? Is there another writer around who is also writing about the mundane? The fan breeze helps the air conditioning cool me down. These nights are warm otherwise. A mosquito flies across my screen. Hello friend or foe. I cannot quite decide which one. If I had a swatter you would be gone. I check my notifications and there is an ...

Today

It is 213pm and I have decided to write. God is good. Obviously. God is beautiful. God made me smile. God is what we think of God. We are what we think. Better to think good things. What are some good thoughts? The rain brings joy to the plants. Time dances. The birds sing beautifully. I am happy. A cup of love to warm the soul. Peace and quiet on a Friday afternoon. The light rests gently on everything. Think of all the good things. Think of one good thing. What is the most beautiful thought? God is here and I am here and that is enough. I can do all things through God. The most beautiful thought is one of contentment. I appreciate the now. I appreciate the moment. I am grateful to be where I am. It is no coincidence that God and gratitude both begin with the letter g. If I combine God and gratitude I get Goditude. I also notice that the word guide is contained in the word gratitude. Let gratitude be our guide. If I remove guide from Goditude, I am left with dot. Goditude is a dot wit...