Skip to content

Commit

Permalink
handle server errors more gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
camillol committed Nov 21, 2011
1 parent 28cc80c commit 5b1f8c7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Data.pde
Expand Up @@ -134,6 +134,7 @@ class WebDataSource {
{
try {
InputStream is = createInput(request);
if (is == null) return null;
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
StringBuffer buf = new StringBuffer();
String line = null;
Expand Down Expand Up @@ -165,6 +166,9 @@ class WebDataSource {
catch (JSONException e) {
println (e);
}
catch (NullPointerException e) {

}
}
return countries;
}
Expand Down
8 changes: 5 additions & 3 deletions TopArtistView.pde
Expand Up @@ -16,6 +16,7 @@ class CountryChooser extends Button implements ListDataSource {
boolean showing = false;
int chosen = 0;
ListBox countryListbox;
List<Country> countries;

CountryChooser(float x_, float y_, float w_, float h_)
{
Expand All @@ -36,6 +37,7 @@ class CountryChooser extends Button implements ListDataSource {
{
showing = !showing;
if (showing) {
countries = data.getCountries(); /* if it failed to load, we only want to retry when the menu is reopened */
countryListbox.x = mouseX - lx;
countryListbox.y = mouseY - ly + h;
rootView.subviews.add(countryListbox);
Expand All @@ -45,15 +47,15 @@ class CountryChooser extends Button implements ListDataSource {

String getText(int index) {
if (index == 0) return "Any country";
else return data.countries.get(index - 1).name;
else return countries.get(index - 1).name;
}
Object get(int index) {
if (index == 0) return null;
else return data.countries.get(index - 1);
else return countries.get(index - 1);
}
int count() {
try {
return data.getCountries().size() + 1;
return countries.size() + 1;
}
catch (NullPointerException e) {
return 1;
Expand Down
2 changes: 1 addition & 1 deletion cs424p4.pde
Expand Up @@ -24,7 +24,7 @@ void setup()
smooth();

/* load data */
if (true) data = new WebDataSource("http://localhost:3000/");
if (false) data = new WebDataSource("http://localhost:3000/");
else data = new WebDataSource("http://radiogaga.heroku.com/");

/* setup UI */
Expand Down
12 changes: 12 additions & 0 deletions datasets/lastfm-dataset-360K/makeindices.sql
Expand Up @@ -44,3 +44,15 @@ create index top_artists2_no_age_artist_id_idx on top_artists2_no_age(artist_id)
cluster top_artists2_no_age_artist_id_idx on top_artists2_no_age;

alter table countries2 rename to countries;


create table top_artists2_no_age_no_country as
select artist_id, gender, sum(plays) as plays from top_artists2_no_age
group by artist_id, gender
order by artist_id;

create index top_artists2_no_age_no_country_artist_id_idx on top_artists2_no_age_no_country(artist_id);
cluster top_artists2_no_age_no_country_artist_id_idx on top_artists2_no_age_no_country;


create index top_artists2_age_country_id_idx on top_artists2(age,country_id);

0 comments on commit 5b1f8c7

Please sign in to comment.