Smart City solutions with Fable/F# (Part I)

Probably there is no better way to get someone attention than by just using a pair of a frontier concept (Smart City) and the niche one (F#), especially those from the later group.

To be honest, there is no abuse in the title, althought I‘m not going to write about the smart city concepts you may me accustomed to/expect to hear like transportation optimization , waste management, lights, ecology etc., at least not directly.

I will rather focus on problems related to cities that are the perfect subject of the smart city famous phrase “cities that want to rediscover themselves”. Hence whenever I use term Smart City you should rather think of terms like Smart Citizens, Collaborative Governance, Living City or Digital Twins

My city (Wrocław/Poland) is among them. City that has a tough history but also anourmous opportunities. Every serious change is a challenge that needs probably months, if not years. City that thanks to technology wish to understand identity, common goals, discover problems, main needs of the residents and solve them with a limited budget.

Smart City is not a typical frontier technology. It is not like a blockchain which has well established and ready technology and where advocates are trying to adapt and find some solutions other than cryptocurrencies. So the technology is there but lacks a good level of domain experts that can figure out the real, handy purpose, anything that is not a scam.

With smart cities it is the opposite situation. There is many, many domain experts since decates but they do not know what the technology behind should be. I observe the smart city realm on social media and every week new people join the groups, claiming to be the domain experts. Those people have many ideas but also have no idea how to implement them or just gain data 
needed to push through their concept.

We need to change it and give experts the tool to play with. A tool, where they can specify requirements and do the experiments. A real data lab!

And this is exactly description of a web portal I’ve been doing in my free time for a couple of weeks now. Yes, a couple of weeks…free time…it all means that it is early prototype.

I started this project in .NET Core & TypeScript however I’m about to move to SAFE stack. Some part is already written with Fable. With the platform you can write applications and experiments using city domain specific language, which is (obviously) created in F#.

Typical application or experiment on the platform consists of three steps:

  • data gathering: simple form for user inputs (optional and often done once)
  • code editor where smart city experts can see or write custom algorithm for their experiment
  • result dashboard: for now I’m havily using d3, maps (mapbox, & Azure maps) and turf.js

The data-flow is as follows:

  1. Open City Data as a main source of data
  2. Application written in F# with core part (algorithm) optionally defined by users with F# DSL to tackle particular city problem
  3. Results are consumed by city experts or the business
  4. Results also become new Open Dity Data as well — this is the cornerstone assumption: currently open data are limited and the goal of the data lab is to create many more useful data sources for other adepts

Data lab is not only oriented around open city data, static (demography, share economy stations etc) or dynamic (live data from REST API’s) but also uses several other third-party data (weather and air pollution from sensors and anything IoT-related).

Ok, but what are the real city problems to solve here ? Let’s go through some examples:

  1. Zoning. I mean dynamic regionalization, the real life zone of the citizen. It is not so obvious concept at a first glance and I will provide more details on post related to this sample later (actually the best approach will be to just show the code). In general, dynamic zoning is about areas we live (home), work, learn and relax. Most dwellers lives in different boroughs than work or education. Proper zoning schema is crutial for many applications: job, flat matching but also many activities related to self-governance
  2. Budget participation: very popular topic in many urban areas. But it is also very controvercial too (like “we are giving you 1% of the budget, you decide for what and btw: keep in mind you have the co-rule power!”)
  3. Algorithm as a transparency proof. Similar to smart contracts in blockchain where everyone is sure how particular thing is calculated. Consider air pollution: there is so many indexes. Especially in Poland institutions use custom indexes to “mitigate” the worst impact to the public. “Good air” index in Poland may be “Terrible air” in Germany. Calculation method should be clear for domain experts in a form of simple algorithm, and domain experts can write their own
  4. Searching portals: this in fact has huge business impact and market opportunity. Job, flat ,doctors portals typically are nation-wide and the only city aspect they have is a standard map positioning. Using real city data with entire data lab may be a real killer feature

I will go through this applications in following posts with focus more on the code as there is a lot of challenges I have to solve and share, to name a few:

  • move to SAFE stack
  • move from cold to hot Fable compilation of user algorithms: here I still have a lot to learn and I need to dive into Fable Repl2 codebase which is awesome foundation for my work
  • extend city-related DSL language in F#

The code name for the project is CityMeter.