The Mastodon ecosystem is really nice. The concept of Fediverse bringing in decentralized social network is a breath of fresh air. I created NiftyBot account in botsin.space – a dedicated server for Mastodon Bots.
What is NiftyBot?
- It is a Mastodon Bot Account
What does it do?
- It posts updates about Indian Markets
- Currently it posts NSE closing report at 4.01 PM everyday. Sample post below
How does it work?
It is a Python script running in AWS Lambda.
A scheduler tiggers the Lambda Function at 4.01 every Monday – Friday. The lambda function is a Python Script that fetches the necessary details from NSE’s output data and posts to Mastodon.
Some asked about if this bot is open source. Obviously, you see the source right here. 🙂 Still I will add the license here.
The above source code is released into the Public Domain. You can do what ever you want with it.
How much does it cost to run this Bot?
The AWS Lambda Free tier comes with 1 Million requests and 400,000 GBSec, which is a combination of how much memory we use and the time taken by our process. Since I have used the CloudWatch Scheduler Event as the trigger, I am using 20-22 requests, the Python function takes about 60 MB to run so running at the lowest memory of 128MB block, and usually completes in around 2600-2700 msec. The metrics says my worst billed event so far is about 0.3375 GBSec. With about 20-22 trading days in a month, I might use a total of 8-10 GBSeconds, leaving enough room to run many more bots like this one 🙂
Hexagonal maps are useful for creating data visualisations of data points that are a representation of quantities that require equal sized polygons. For example Election Maps. While geographic map of the assembly and parliamentary constituencies might be used for visualising election results, it is a false one. The constituencies are created based on the number of people in a region under the principal of a representative for every X number of people. In such a scenario, using a geographic representation for a place like Chennai, which is made of 3 parliamentary constituencies, doesn’t give us the same perception as the 3 constituencies Kanniyakumari, Thoothukudi, and Thirunelveli put together. But in reality that’s what it actually means.
- Geographic Representation – Skewed representation of the base data. Unequal real estate for equal (approx) number of people
- Hexagonal Representation – Correct representation of the base data. Equal real estate for equal number of people.
Now that we have the Parliamentary constituencies in Hex Map form, why not have the Districts as well.
If you need the base data to create your own maps. The GeoJSON files for the same are available here https://github.com/tecoholic/Geographic-Data
Water has become one thing that has everyone in Tamil Nadu talking about. So, I sat down to visualize the #dams of #TamilNadu
Software: QGIS for Data Processing, Affinity Designer for prettifying
PM Modi visited Tamil Nadu on 27th January 2019 for the AIIMS Hospital ground breaking ceremony. Twitter was trending with #GoBackModi and #TNWelcomesModi and I was curious about the number of times has PM Modi visited Tamil Nadu before.
The PM India site has a neat list of all the visits http://www.pmindia.gov.in/en/pm-visits/?visittype=domestic_visit
So, I created a map out of it.
This map was replaced after some errors were discovered in the base data.
I was going through the Census 2011 data once again and Erode district’s low Schedule Caste (SC) literacy rate caught my eyes. It is not a very lagging state when in overall literacy. But its SC literacy was less than the least literate district of Dharmapuri. So I added the data to the TN Districts shapefile and visualised it to see how lagging are the SC community across the districts.
Here are the maps
In an earlier map, the gap of Thoothukudi was mentioned as -14%, while the actual gap is around 6% due to a typo during the data processing. The map has been updated to reflect the change.
- Kongu Belt (Coimbatore, Tiruppur, Erode) is the worst. ~~The Gounder (land owning) community has ensured their position and the social ladder and ensured the peasantry remained uneducated and illiterate.~~
Update: While there might be an element of truth to it, the maps alone are not indicative of the inference. I have made the above observation based on the number of issue that have appeared on the media like the Mid-day meal staff harassment, two tumbler system etc.,
- Dharmapuri is a peculiar case, it has the lowest overall literacy in TN, but it is also the only district where SC community is more literate than the general population.
- Kanniyakumari which tops the overall literacy rates also tops the SC literacy. In fact the SC community of Kanniyakumari is more literate than the general population of almost all other districts. I think it would be an interesting place of humanities research in the area of literacy, education and caste.
I published the Tamilnadu district wise literacy map some days ago and @tshrinivasan asked if I can write a blog on how to do it, and here it is now.
What are we going to do?
We are going to create India’s State Wise Literacy Map. It will be a Choropleth map ℹ️ just like the Tamilnadu one.
Things we need
- QGIS – An Open Source software that will be used to process the geographic data and create the map. Download and install it from https://qgis.org/ for your operating system.
- Base map – The digital map of India with its state boundaries as a shapefile. ℹ️ You search the internet for “India states shapefile”, there are a number of sources where you can find this. I am going to use the one from the Hindustan Times public repository. [shapefiles/india/state_ut/india_2000-2014_state.zip] ⬇️Download, Unzip the file and keep it ready. I am choosing the pre-Telangana map because the literacy data is from 2011 which is pre-Telangana.
- Data on literacy levels of the Indian states. An internet search for “India states literacy csv” would give a number of results. I am going to use the one from the Census 2011 website. ⬇️Download
Get the data ready
We have 2 sources of data:
- Geographic data which we downloaded from the Hindustan Times
- The Literacy data from the Census 2011 website
Both the datasets need to be joined to create the map. Let us do that:
- Open QGIS and create a new project. From menu select Project -> New Project
- Add the map using Layer -> Add Layer -> Add Vector Layer. Browse to the location of the downloaded shapefile, select the india_2000-2014_state.shp file and click Add.
- You will be asked to select the coordinate system. Select WGS84 and click OK. Once the layer is added close the Add layer button.
- Now you should have the map loaded to the main area, and should see the legend entry for the data layer like this.
- Now right click on the layer and select Open Attribute Table
- You will notice it has only two columns – the id and the state name. We are going to create a new column and add the literacy rates from the census data. In the Attribute Table, click the yellow pencil icon (first one in the icon bar) to start editing.
- Click the Add Column button and add the literacy column with type decimal.
- Now enter the literacy rates from the excel sheet into the newly added column. Sidenote: There is an automated way to combine the data without having to manually enter the data if you have the data in a delimited text file like CSV. It involves adding a something called a Data Layer. We will take the manual route to keep it simple.
- Once you have added the literacy values. Click Save Edits icon (Ctrl+s). Now click the “Yellow Pencil” button again to stop editing. This is very important. Otherwise, you might unknowingly click at some place and change the geometry of the state boundaries.
- Now you should have the data in the attribute table like this.
- Close the Attribute Table.
Styling the map
- In the Layers sidebar right click on the map layer and select Properties.
- In the Properties window, select Symbology from the side menu.
- In the Styling window make the following changes.
- A – Change the style from “Single Symbol” to Graduated
- B – Select “literacy” as the column
- C – Set Precision to your liking (it denotes the decimal points of the values to be shown in the map legend). I prefer 0 or 1 usually.
- D – Choose a Color Ramp to your liking. I am choosing the one suitable for Wikipedia based on the Wikipedia Conventions.
- E – Set the mode to “Pretty Breaks”. Now as soon as you select this, the “Classes” tab right above it should be populated automatically. If not, use F.
- F – If your classes didn’t appear automatically, click the “Classify” button.
- Once you are satisfied with the Legend precision and the color ramp, click OK to see your styled Choropleth map.
Note: The properties dialog provides a huge number of options to do a number of things including labels. Refer to a QGIS manual or tutorials on the web for related information.
Exporting the map
Now we have the styled map according to our liking ready. We need to export it to an image so that we can share it across.
- Click the “New Print Layout” button. Enter a name, I named mine “export” and click ok.
- You will get the Layout window with an empty page.
- From the menu, select Add Item -> Add map. Click and drag the cursor to the required size.
- (Optional) There is a lot of white space around the map inside the box. We can make the map a little bigger by reducing the scale. On the right side switch to the Item Properties tab and reduce the value for Scale. (Mine was 17485874 and I changed it to 12500000).
- Click Add Item -> Add Legend. Click and drag the cursor to create the Legend. India’s maps usually use the Bay of Bengal for that, I am going to do the same.
- You will notice that the legend title says the layer name. But what we really want it to say is “Literacy Rate”. There are two ways to fix that. Choose the one that appeals to you.
- On the right in the Item Properties tab, under Main Properties, you can enter a title as “Literacy Rate”
- On the right in the Item Properties tab, under Legend Items, double-click on the layer name and enter “Literacy Rate”
- Now there is some extra white space on the right. Let us clean that up. On the right side select Layout tab, scroll down to Resize Layout to content and click Resize Layout. Now the page should have been resized to only the map.
- From menu click Layout -> Export as Image. Enter the filename in your desired location and save it. You could also export as PDF if you want to print.
Note: Apart from just the map and legend you can do a lot more complex things with the layout manager. Again, refer to a QGIS manual and other tutorials on the internet to fully learn about them.
On 16th October 2011, I have uploaded a map of Tamilnadu District wise Literacy levels to Wikipedia. It was used in the article about Tamilnadu for a long time, then moved to the Education in Tamilnadu article when a separate article was created. But the map was not in line with the Wikipedia Map Conventions. So, took some time this week and updated the map.