11

Bugs: echo "$my_variable" | my_command can behave unexpectedly if the variable starts with one of the echo options. You can do my_command <<< "$my_variable" instead. unset $IFS does not unset IFS. For that you need unset IFS. Simplifications: You shouldn't need to set IFS - read will save the full input to the variable anyway (see help [r]ead). A ...


10

Since the code is about implementing mathematical formulas I would make an exception and completely ignore the usual naming conventions. Instead, I would use the exact symbols as that document. This would mean a little bit copy/paste because it's difficult to write symbols like [ϕ, λ, θ] but the compiler can work with unicode. I find that code like this: ...


8

GooglePlaces.search could return empty list instead of null. It would save you a few null checks in clients. (Effective Java, Second Edition, Item 43: Return empty arrays or collections, not nulls) Be careful about Double.toString: urlString.append("&location="); urlString.append(Double.toString(latitude)); urlString.append(","); urlString.append(...


8

I want to focus principally on this section of your code: $mascow_sub_area = array(//'Aviamotornaya','Avtozavodskaya','Akademicheskaya','Aleksandrovskiy_Sad', 'Alekseevskaya', 'Alma-Atinskaya','Altufevo','Annino','Arbatskaya','Aeroport','Babushkinskaya','Bagrationovskaya','Barrikadnaya','Baumanskaya','Begovaya','Belorusskaya','Belyaevo','Bibirevo','...


8

The problems start with this code being fairly unreadable. A few simple rules can help: Every comma is followed by a space: xi, yi instead of xi,yi. Every binary operator like + is surrounded by a space on each side: int(round((xi[i] - xEast) / res, 0) + 1) instead of int(round((xi[i]-xEast)/res,0)+1). If an expression becomes to complicated, assign ...


8

You do quite a lot or repetition. Using str.format you should be able to make your code smaller by using a comprehensions or map. Doing these inside a ''.join can allow you to reduce a lot of your code. And if you make a list to iterate over you can do this all in two comprehensions. I also think you should make a comprehension to get the layer name from ...


8

I can't explain the discrepancy with the online conversion tool without seeing the source code for the latter. 1. Review The comment for the ellipsoid parameters should give the units for the semi-major axis. Also, I think "reciprocal flattening" would be a better description of the second parameter, given that you use the name rf later on in the code. The ...


8

var agents = db.GetAgents(); if(agents == null || agents.Count == 0) { Console.WriteLine("No Results"); } You should exit your application/code block when you detect an invalid state. Here even if "No Results" is printed, the app will still run into a NullReferenceException or IndexOutOfRangeException in the next few steps. Also, talking of ...


8

public const double lowerLatitude = 49.8333333 * Mathf.Deg2Rad; Huh? Mathf.Deg2Rad is a float. Either use Math.PI / 180 or change the type of lowerLatitude to float, but don't work with low-precision values and then implicitly claim that the result is high-precision. static double MLower { get => M(lowerLatitude);} This (and all the other similar lines)...


7

The worst thing you are doing that I am able to see by skimming through your code is this: you read from the database on the main thread instead of using the Loader API. In general, this is discouraged, because it may render the application UI unresponsive, depending on the amount of work the underlying database must perform to satisfy your query. You indeed ...


7

It's not really clear why Odometer is a class. You only ever create one instance of it, and don't actually need any of the instance attributes. The only thing you could sensibly store as a class/instance attribute, the Geod instance, you actually recreate on every call. Also, the error handling seems a bit odd - why return anything if you haven't actually ...


7

I'd like to approach this answer as a refactoring exercise. I'm going to iteratively improve your code little-by-little until the final result. 1. Remove unnecessary declarations and deletions The declarations before the for group in ... of formula_score4, etc., and the del formula_score4[:], etc., at the end, are unnecessary. The formula_scoreX variables ...


7

In geoload.py use with..as to ensure it is closed, even if any code in-between raises an exception: with open("locations.data") as filehandle: ... In geodump.py, this is a code-smell: for row in cur: ''' row[0]: target row[1]: address row[2]: lat & long ''' It just asks for you to do: for target, _, data ...


7

You can simplify geoload by using the requests package. In fact it says this in the urllib documentation: See also: The Requests package is recommended for a higher-level HTTP client interface. Doing this single handedly changes: print 'Resolving', address url = SERVICE_URL + urllib.urlencode( {"sensor": "false", "address": address}) print '...


7

If this were a problem on the Euclidean plane, and not on the surface of the Earth, then it could be solved exactly by computing the Voronoi diagram for the set of airport locations, and intersecting the Voronoi regions with the bounding polygon for the state boundary. The most distant point will be one of the vertices of the intersected polygons. A Voronoi ...


6

To accept user input for dates, DateTime::Format::Natural is a nice CPAN module to use. It spares you from having to input dates using the Unix epoch format and the tortured use of Perl-Bash-Perl to generate the table. (Defining a subroutine would also have helped you generate the whole table in Perl.) Perl has some features for writing numeric literals ...


6

If after adding the index on latitude and longitude you still see poor performance, trim the query down to the bare minimum to isolate the source. Remove all of the joins and the where clause referencing those tables. Once it's doing just the distance calculation (which should be move to a deterministic stored function), you can get a better time measurement....


6

Style Your docstring at the top of the seq function should be moved underneath the function signature, like this: def seq(start, end, step): """Function to iterate with decimal step size""" ... The variable map, should be written like this, to improve clarity and readability: map = Basemap( projection="merc", resolution = 'h', ...


6

One function per file? I know you can do better than that. Compare geoload.py with: import urllib import sqlite3 import json SERVICE_URL = "http://maps.googleapis.com/maps/api/geocode/json?" def main(dbfile='geodata.sqlite', datafile='locations.data'): conn = get_connexion(dbfile) with open(datafile) as filehandle: for line in filehandle:...


6

You can greatly simplify this code by introducing a helper function that calculates the area_score for one of the categories. Let's take the first category as an example. You do three times the same job, with a different expression each time. This can be put into a function that takes an expression and returns the total area for that expression: def ...


5

Let's start with part I : Don't repeat yourself You can define small functions to avoid duplicating code for all signals. Also, you can use the relevant data structure to store information. For instance, the strength of the signal go by 3, let's put them in the same object (let's say a list to keep things simple). Finally, your attempt to write function ...


5

I see no index on the latitude and longitude columns of the location table. Try CREATE INDEX location_latlng ON `location` (`latitude`, `longitude`); If it's still slow, then add the output of EXPLAIN SELECT to your question.


5

Superficial issues """Function to iterate…""" is a docstring, which belongs inside the function definition, not before it. """Divide global area into grid cells""" should be written as a comment (# Divide global area into grid cells). The way you formatted map = Basemap(…) makes it hard to see that it's one statement over five lines. The four ...


5

With numpy and its meshgrid functions, you don't have to do any looping at all, although under the hood looping similar to yours is going on (but in C, and thus much faster). Here's a numpy version of your function: import numpy as np def distance_on_sphere_numpy(coordinate_array): """ Compute a distance matrix of the coordinates using a ...


5

Instead of doing SELECT TOP 10 * FROM ... you should only retrieve the columns needed which in your case is LineName. var name = "" doesn't need to be there, if you just return firstOrDefault.LineName and for no result/exception return string.Empty. While we are at var firstOrDefault I would like to say that using var here is just wrong because it isn't ...


5

I was writing a review along the lines of what @scottbb has suggested when I noticed that the formula that your code produces didn't make sense: CASE WHEN "Layer_1a_Score" = 4 OR "Layer_1b_Score" = 4 OR "Layer_1c_Score" = 4 OR "Layer_1d_Score" = 4 OR "Layer_1e_Score" = 4 OR "Layer_1f_Score" = 4 OR ...


5

Naming and interface Please avoid mixing English (calculate-distance) with Portuguese (raio). The code should be in English; write your comments in whatever language you prefer. ltd and lgt seem like awkward abbreviations; lat and lon or lat and lng seem more conventional. The latter is what Google uses for the Maps and Android APIs, for example. ...


5

Unless you know for sure that the degrees, minutes, and seconds are always going to be 2 digits each, this approach will cause issues. I would recommend using 3 separate inputs for each value and automatically tabbing over to the next one when the first one is filled. If you do know they will always be 2 digits, why not just concat the value with + instead ...


5

Precision in numeric calculus is usually handled by the decimal module. Compare: >>> 1.001 + 0.0001 1.0010999999999999 >>> Decimal('1.001') + Decimal('0.0001') Decimal('1.0011') However, trigonometric functions would convert a decimal.Decimal back to a float, thus defeating the purpose. However, the decimal module provide some recipe to ...


5

NB: This review assumes Perl5, specifically the Unicode features in 5.12 (released 2010) and later. 1. the parsing could be simpler and more featureful Much code is devoted to handling delimiters that we're only going to throw away. Explicit N/S/E/W should override -lonlat but don't. The sole error message ("malformed input") is vague and happens ...


Only top voted, non community-wiki answers of a minimum length are eligible