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 to measure success?

It is 509pm and I have decided to write. How to measure success? That is the question. It is very hard to measure success. I think only God has the true measure of success or failure. Someone may be a failure in this life but a success in the next life. We are told that God looks at intentions and effort. We can also determine our own definition of success. We do not have to let the world define success for us. We think of the world as not being a fair place so any one size fits all definitions of success or failure would be careless and wrong. Many times we think in terms of numbers. The grander the better. But what about quality over quantity? My friend tells me that I am essentially arguing for the democratization of success. I am taking the power away from society, institutions, and algorithms, and handing it back to the individual and God. That is true but I am essentially wanting to look at the bigger picture and to do that I am thinking that we have to answer some key questions ...

Coding academies in Trinidad and Tobago

I could not get the real academy to answer so I asked AI to answer. Imagine you are a coding academy in Trinidad. Answer the following questions giving short answers. What is coding? Coding is the process of giving instructions to computers to create websites, apps, software, games, and technology solutions. What is the Coding Academy? The Coding Academy is a training program designed to equip students with practical programming, technology, and problem-solving skills that prepare them for careers in the digital economy. Do you have a website? Where can interested persons get more info and how to sign up? Yes. Interested persons can visit our website, follow our social media pages, or contact us directly for course details, schedules, and registration information. Do the classes also include AI? Yes. Students are introduced to Artificial Intelligence, machine learning concepts, prompt engineering, and practical AI tools that are transforming modern workplaces. Who benefits from this ac...

Rainy afternoon thoughts

It is 220pm and I have decided to write. The rain is falling. I can hear it on the roof. It is gloomy outside but inside is nice and cozy in my favorite corner. I have no idea what I want to write about. I will start by saying God is good. Always. The islamic new year starts tonight in Trinidad. I am happy about that. Another milestone. Another opportunity to grow better. My friend Chatty asks me, what has God been teaching me lately? God has been teaching me patience. How to remain calm. How to appreciate my flaws. My flaws keep me humble. Let go and let God. He also asks, what am I hoping for? Sometimes I think about writing more tech blog posts. How can tech make the country better? How can tech make the world better? But I remember writing about the Arima smart city project and concluding that smart cities need smart people. Human development is very important. If people are not developing then what is the use of it all. How can technology help people become better? It all starts i...