Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LUA Recipes #15

Open
samibaig opened this issue May 13, 2024 · 0 comments
Open

LUA Recipes #15

samibaig opened this issue May 13, 2024 · 0 comments

Comments

@samibaig
Copy link
Collaborator

LUA script to get geocode of a place
qsv luau map "Geo" file:geolookup.luau place.csv | qsv table

BEGIN {

csv_indexed = qsv_autoindex();
geoid_lookup_headers = qsv_register_lookup("places_geoid", "dathere://places_geoid.csv", 10000)


}!

local city_name = col["NAME"]
for geoid, details in pairs(places_geoid) do
    if details["NAME"] == city_name then
        geoid_result = geoid
        break
    end
end
-- Return the geoid for the given city name
return {geoid_result};

LUA script to get population of a state
qsv luau map "population" file:populationlookup2.luau state.csv | qsv table

BEGIN {
    csv_indexed = qsv_autoindex();
    us_states_lookup_headers = qsv_register_lookup("us_states", "dathere://us-states-example.csv", 1000000)
}!

local state_name = col["Name"]:match("^%s*(.-)%s*$")


for abbreviation, details in pairs(us_states) do
    if details["Name"] == state_name then
        -- Remove commas from the population string and convert it to a number
        population_result =   details["Population (2019)"]
        break
    end
end

-- Return the population for the given state name
return {population_result};

LUA script to get area of a state
qsv luau map "area" file:arealookup.luau state.csv | qsv table

BEGIN {
    csv_indexed = qsv_autoindex();
    us_states_lookup_headers = qsv_register_lookup("us_states", "dathere://us-states-example.csv", 1000000)
}!

local state_name = col["Name"]:match("^%s*(.-)%s*$")


for abbreviation, details in pairs(us_states) do
    if details["Name"] == state_name then
        -- Remove commas from the population string and convert it to a number
        area_result =   details["area (square miles)"];
        break
    end
end

-- Return the area for the given state name

return {area_result};
@a5dur a5dur self-assigned this May 15, 2024
@a5dur a5dur removed their assignment May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants