Uk Postcode lookup field with covering a range of districts - user-interface

Need some efficient solution of district range selector for an area in UK. Lets say I selected Manchester which covers many small districts like M1,M2,M3.....M20, M30... My users can be sharing responsibility of some of the districts of Manchester like from M1 to M10 and another user with M11 to M21. Also they can have multiple areas like Manchester(M), Aberdeen(AB) and so on and the range will be needed even then.
How to develop the interface for it so that it should create minimum load on mysql DB as well as handy for user to add a lots of areas with their desired district range.
All selected range postcodes will be added in DB and postcode info will be matched against each one so that the person responsible can be referenced.
For more idea: http://screencast.com/t/6qwCVhKA
thanks in advance

It sounds like you should be breaking the postcodes down into area, district and sector. So you have
area | district | sector
------------------------
M | M1 | M1 0AA
M | M2 | M2 0AA
M | M3 | M3 0AA
etc, this will enable you to reference by whatever level you want.
It's described in more detail on page 17 of this and on wikipedia, which is actually very accurate.

Related

How to handle scenario of same city with multiple names

Ok, I have a list with some contacts on it filled by respective persons. But persons living in same city might write different names of cities(that I don't have any control on sice the names of cities may change with changing government).
For example:
NAME CITY
John Banaglore
Amit Bengaluru
Here both the Bangalore and the Bengaluru refer to the same city. How can I make sure(my be programatically) that my system does not consider as two different cities but one, while traversing the list.
One solution I could think of is to have a notion of unique ids attached to each city, but that requires recreating the list and also I have to train the my contacts about the unique id notion.
Any thoughts are appreciated.
Please feel free to route this post to any other stackexchange.com site if you think it does not belong here or update the tags.
I would recommend creating a table alias_table which maps city aliases to a single common name:
+------------+-----------+
| city_alias | city_name |
+------------+-----------+
| Banaglore | Bangalore |
| Bengaluru | Bangalore |
| Bangalore | Bangalore |
| Mumbai | Bombay |
| Bombay | Bombay |
+------------+-----------+
When you want do any manipulation of the table in your OP, you can join the CITY column to the city_alias column above as follows:
SELECT *
FROM name_table nt INNER JOIN alias_table at
ON nt.CITY = at.city_alias
I think the best way is to provide selection from a list of existing Cities and do not allow to enter it by the user manually.
But if you have data already it is more reliable to use alias table proposed by #Tim Biegeleisen
In addition, some automation could be added, as an example, to check is it correct to ignore 2 words difference in a case when it is not first letter by put it on the aliases table with mark as candidate for future review.
Here is examples of reasons for exclusion of first letter:
Kiev = Kyiv
Lviv != Kiev

Order By any field in Cassandra

I am researching cassandra as a possible solution for my up coming project. The more I research the more I keep hearing that it is a bad idea to sort on fields that is not setup for sorting when the table was created.
Is it possible to sort on any field? If there is a performance impact for sorting on fields not in the cluster what is that performance impact? I need to sort around or about 2 million records in the table.
I keep hearing that it is a bad idea to sort on fields that is not setup for sorting when the table was created.
It's not so much that it's a bad idea. It's just really not possible to make Cassandra sort your data by an arbitrary column. Cassandra requires a query-based modeling approach, and that goes for sort order as well. You have to decide ahead of time the kinds of queries you want Cassandra to support, and the order in which those queries return their data.
Is it possible to sort on any field?
Here's the thing with how Cassandra sorts result sets: it doesn't. Cassandra queries correspond to partition locations, and the data is read off of the disk and returned to you. If the data is read in the same order that it was sorted in on-disk, the result set will be sorted. On the other hand if you try a multi-key query or an index-based query where it has to jump around to different partitions, chances are that it will not be returned in any meaningful order.
But if you plan ahead, you can actually influence the on-disk sort order of your data, and then leverage that order in your queries. This can be done with a modeling mechanism called a "clustering column." Cassandra will allow you to specify multiple clustering columns, but they are only valid within a single partition.
So what does that mean? Take this example from the DataStax documentation.
CREATE TABLE playlists (
id uuid,
artist text,
album text,
title text,
song_order int,
song_id uuid,
PRIMARY KEY ((id),song_order))
WITH CLUSTERING ORDER BY (song_order ASC);
With this table definition, I can query a particular playlist by id (the partition key). Within each id, the data will be returned ordered by song_order:
SELECT id, song_order, album, artist, title
FROM playlists WHERE id = 62c36092-82a1-3a00-93d1-46196ee77204
ORDER BY song_order DESC;
id | song_order | album | artist | title
------------------------------------------------------------------------------------------------------------------
62c36092-82a1-3a00-93d1-46196ee77204 | 4 | No One Rides For Free | Fu Manchu | Ojo Rojo
62c36092-82a1-3a00-93d1-46196ee77204 | 3 | Roll Away | Back Door Slam | Outside Woman Blues
62c36092-82a1-3a00-93d1-46196ee77204 | 2 | We Must Obey | Fu Manchu | Moving in Stereo
62c36092-82a1-3a00-93d1-46196ee77204 | 1 | Tres Hombres | ZZ Top | La Grange
In this example, if I only need to specify an ORDER BY if I want to switch the sort direction. As the rows are stored in ASCending order, I need to specify DESC to see them in DESCending order. If I was fine with getting the rows back in ASCending order, I don't need to specify ORDER BY at all.
But what if I want to order by artist? Or album? Or both? Since one artist can have many albums (for this example), we'll modify the PRIMARY KEY definition like this:
PRIMARY KEY ((id),artist,album,song_order)
Running the same query above (minus the ORDER BY) produces this output:
SELECT id, song_order, album, artist, title
FROM playlists WHERE id = 62c36092-82a1-3a00-93d1-46196ee77204;
id | song_order | album | artist | title
------------------------------------------------------------------------------------------------------------------
62c36092-82a1-3a00-93d1-46196ee77204 | 3 | Roll Away | Back Door Slam | Outside Woman Blues
62c36092-82a1-3a00-93d1-46196ee77204 | 4 | No One Rides For Free | Fu Manchu | Ojo Rojo
62c36092-82a1-3a00-93d1-46196ee77204 | 2 | We Must Obey | Fu Manchu | Moving in Stereo
62c36092-82a1-3a00-93d1-46196ee77204 | 1 | Tres Hombres | ZZ Top | La Grange
Notice that the rows are now ordered by artist, and then album. If we had two songs from the same album, then song_order would be next.
So now you might ask "what if I just want to sort by album, and not artist?" You can sort just by album, but not with this table. You cannot skip clustering keys in your ORDER BY clause. In order to sort only by album (and not artist) you'll need to design a different query table. Sometimes Cassandra data modeling will have you duplicating your data a few times, to be able to serve different queries...and that's ok.
For more detail on how to build data models while leveraging clustering order, check out these two articles on PlanetCassandra:
Getting Started With Time Series Data Modeling - Patrick McFadin
We Shall Have Order! - Disclaimer - I am the author

ElasticSearch: facet for price dependent on date range

I have a database of services with prices and I want to search on service name and show facet with price ranges and counts. Searching on such database would be simple, nevertheless the price is dependent on date and thus can fluctuate.
Service 1 | 1.1.-15.2. $50 | 16.2.-10.5. $80 | 11.5.-20.7. $90
Service 2 | 1.1.-14.2. $60 | 15.2.-11.5. $90 | 12.5.-21.7. $80
Service 3 | 1.1.-18.2. $70 | 19.2.-17.5. $50 | 18.5.-25.7. $70
I would like to provide a search based on name and date range when user is looking for a service:
Filter example: 'car washing' between 1.2. - 15.3.
RESULT
Display: services with given text that are provided in the given date range
Facet Price group: $0-$50 (23), $50-$100 (14), $100-$150 (5)
- number of services within price bucket
REMARKS
I believe this is easy when price would be static, but I find it hard when it is dependent on provided date range. For example how to deal when user defines a date range that overlaps 2 different prices of a matched service? Can ElasticSearch take the lowest price for example? How to deal with such case in ES?

Rendering a three level data hierarchy into an HTML table with ASP.NET

Say I had some Airport, Aeroplane, Passenger and Seat classes in C#. Passenger has the id of an Aeroplane and Aeroplane has the id of an Airport. Passenger also has the id of a Seat.
How would I write a linq query to build them into a hierarchy then render them into an HTML table?
I need it to look some like:
1 2 3
Gatwick
747 July Kim Ben
767 Neal Toby
A380 Becky
Hong Kong
747 Gary Steve Gary
MiG-35 Ted
etc..
(Seat numbers are along the top)
I've been scratching my head in front of LinqPad for ages but I can only get one level in the hierarchy. I guess I may need to use nested GridViews or maybe write a custom control to render the resulting object but am not sure of the best approch.
Ideally I'd like to get all the data with a single query (a previous programmer has done it using one query per cell and the page takes a minute to load!)
Many thanks
This would require 2 LINQ queries:
You have to group by seat number (or get seat numbers using .Distinct()). Use this to output the columns;
Then group by airport, then airplane, then in each airplane grouping, you have the passengers - you .Join() them with your seats collection.
passengers
.GroupBy(p => p.Aeroplane)
.GroupBy(p => p.Airport)
.Join(seats, p=>p.Seat, s=>s, (p,s)=>new { Passenger = p, Seat = seat })
That will give you an array of passengers and their respective seat in each aeroplane and then in each airport.

Google API Map of cities based on database

I'm wondering is there a possibility to create dynamic map of cities based on my database?
For example i have few cities in my db eg:
1 | Warsaw
2 | Cracov
3 | Poznan
4 | Poznan
5 | Poznan
6 | Warsaw
7 | Berlin
8 | Berlin
etc. This is based on registered users, and as you can see for example i have 2 users from Berlin, 2 from Warsaw, 1 from Cracov and 3 from Poznan. Now i'd like to count how many times unique city name is repeated. And i'd like to make an dynamic map based on this which will looks something like thad i've made in graphic editor
If count of city is bigger, then circle on it is bigger and it means that more people from that city where registered on my page. I'm looking for kind of that solution. It can me different and frpm different page but it has to be dynamic and change on every refresh, for example someone noew have registeres - whe i refresh it will add new city to map or if city exists before circle on it will be bigger.
Hope you understand me and you will help me ;)
regards
Darek

Resources