Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Additional chart providers added.

  • Loading branch information...
commit 10c6ecfa677bb8821da61f3e1cf26f9d372f07ab 1 parent ce0284f
@mnemonia authored
View
29 LetsMakeRobotsBarometer/src/com/letsmakerobots/donation/Donations.java
@@ -30,6 +30,10 @@ public void setDonations(Collection<Donation> donations) {
}
public Collection<Donation> getByDate(){
+ return internalGetByDate(donations);
+ }
+
+ private Collection<Donation> internalGetByDate(Collection<Donation> theDonations){
Comparator<Donation> c = new Comparator<Donation>() {
DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd");
@Override
@@ -45,12 +49,12 @@ public int compare(Donation d1, Donation d2) {
return 0;
}
};
- List<Donation> sortedDonations = new ArrayList<Donation>(donations);
+ List<Donation> sortedDonations = new ArrayList<Donation>(theDonations);
Collections.sort(sortedDonations,c);
return sortedDonations;
}
- public Collection<Donation> summarizeDonationsByDate(){
+ public Collection<Donation> getSummarizeDonationsByDate(){
Map<String,Double> map = new HashMap<String, Double>();
for (Donation d : getByDate()) {
if(!map.containsKey(d.getDate())){
@@ -69,8 +73,24 @@ public int compare(Donation d1, Donation d2) {
d.setAmount(""+e.getValue());
don.add(d);
}
- return don;
+ return internalGetByDate(don);
+ }
+
+ public Collection<Donation> getCumulativeDonationsByDate(){
+ Collection<Donation> result = new ArrayList<Donation>();
+ Collection<Donation> internalGetByDate = getSummarizeDonationsByDate();
+ double amount = 0.0;
+ for (Donation donation : internalGetByDate) {
+ amount += Double.parseDouble(donation.getAmount());
+
+ Donation newDonation = new Donation();
+ newDonation.setAmount(""+amount);
+ newDonation.setDate(donation.getDate());
+ result.add(newDonation);
+ }
+ return result;
}
+
public int summarizeDonations(){
double sum = 0;
@@ -80,4 +100,7 @@ public int summarizeDonations(){
return (int)sum;
}
+ public int getEstimatedTotalAmount() {
+ return 10000;
+ }
}
View
6 LetsMakeRobotsBarometer/src/com/letsmakerobots/donation/Main.java
@@ -10,7 +10,9 @@
import javax.xml.bind.Unmarshaller;
import com.letsmakerobots.donation.barometer.DonationBarometer;
-import com.letsmakerobots.donation.barometer.impl.DonationProgressImpl;
+import com.letsmakerobots.donation.barometer.impl.DonationPieChart;
+import com.letsmakerobots.donation.barometer.impl.DonationSparkLine;
+import com.letsmakerobots.donation.barometer.impl.DonationVerticalBarChart;
public class Main {
@@ -30,7 +32,7 @@ public static void main(String[] args) throws Exception {
donations = new Donations();
donations.setDonations(ds);
- DonationBarometer barometer = new DonationProgressImpl(); //new DonationBarometerImpl();
+ DonationBarometer barometer = new DonationPieChart();//new DonationVerticalBarChart();//new DonationSparkLine();//new DonationProgressImpl(); //new DonationBarometerImpl();
File out = new File("c:/out.html");
PrintWriter p = new PrintWriter(out);
p.print(barometer.create(donations));
View
49 LetsMakeRobotsBarometer/src/com/letsmakerobots/donation/barometer/impl/DonationPieChart.java
@@ -0,0 +1,49 @@
+package com.letsmakerobots.donation.barometer.impl;
+
+import java.util.Collection;
+
+import com.letsmakerobots.donation.Donation;
+import com.letsmakerobots.donation.Donations;
+import com.letsmakerobots.donation.barometer.DonationBarometer;
+
+public final class DonationPieChart implements DonationBarometer {
+
+ @Override
+ public String create(Donations donations) {
+ Collection<Donation> byDate = donations.getSummarizeDonationsByDate();
+
+ StringBuffer b = new StringBuffer();
+ b.append("<html>\n");
+ b.append(" <head>\n");
+ b.append(" <script type='text/javascript' src='https://www.google.com/jsapi'></script>\n");
+ b.append(" <script type='text/javascript'>\n");
+ b.append(" google.load('visualization', '1', {packages:['imagepiechart']});\n");
+ b.append(" google.setOnLoadCallback(drawChart);\n");
+ b.append(" function drawChart() {\n");
+ b.append(" var data = new google.visualization.DataTable();\n");
+ b.append(" data.addColumn('string', 'Task');\n");
+ b.append(" data.addColumn('number', 'Hours per Day');\n");
+ b.append(" data.addRows("+(1+byDate.size())+");\n");
+ int i = 0;
+ for (Donation donation : byDate) {
+ b.append(" data.setValue("+i+", 0, '"+donation.getDate()+"');\n");
+ b.append(" data.setValue("+i+", 1, "+donation.getAmount()+");\n");
+ i++;
+ }
+ b.append(" data.setValue("+i+", 0, 'Missing');\n");
+ b.append(" data.setValue("+i+", 1, "+donations.getEstimatedTotalAmount()+");\n");
+ b.append("\n");
+ b.append(" var chart = new google.visualization.ImagePieChart(document.getElementById('chart_div'));\n");
+ b.append(" chart.draw(data, {width: 430, height: 240, title: 'LMRv4 Donations'});\n");
+ b.append(" }\n");
+ b.append(" </script>\n");
+ b.append(" </head>\n");
+ b.append("\n");
+ b.append(" <body>\n");
+ b.append(" <div id=\"chart_div\"></div>\n");
+ b.append(" </body>\n");
+ b.append("</html>\n");
+ return b.toString();
+ }
+
+}
View
10 LetsMakeRobotsBarometer/src/com/letsmakerobots/donation/barometer/impl/DonationProgressImpl.java
@@ -20,17 +20,17 @@ public String create(Donations donations) {
b.append(" function drawChart() {\n");
b.append(" var data = new google.visualization.DataTable();\n");
b.append(" data.addColumn('string', 'Day');\n");
- b.append(" data.addColumn('number', 'LMRv4 Development Costs');\n");
+ //b.append(" data.addColumn('number', 'LMRv4 Development Costs');\n");
b.append(" data.addColumn('number', 'Your Donations');\n");
- Collection<Donation> byDate = donations.summarizeDonationsByDate();
+ Collection<Donation> byDate = donations.getSummarizeDonationsByDate();
b.append(" data.addRows("+byDate.size()+");\n");
int i = 0;
double sum = 0.0;
for (Donation amount : byDate) {
- b.append(" data.setValue("+i+", 0, '"+amount.getDate()+"');\n");
- b.append(" data.setValue("+i+", 1, 30000);\n");
+ b.append(" data.setValue("+i+", 0, '"+amount.getDate().substring("2012-".length(), amount.getDate().length())+"');\n");
+ //b.append(" data.setValue("+i+", 1, 30000);\n");
sum += Double.parseDouble(amount.getAmount());
- b.append(" data.setValue("+i+", 2, "+sum+");\n");
+ b.append(" data.setValue("+i+", 1, "+sum+");\n");
i++;
}
b.append("\n");
View
46 LetsMakeRobotsBarometer/src/com/letsmakerobots/donation/barometer/impl/DonationSparkLine.java
@@ -0,0 +1,46 @@
+package com.letsmakerobots.donation.barometer.impl;
+
+import java.util.Collection;
+
+import com.letsmakerobots.donation.Donation;
+import com.letsmakerobots.donation.Donations;
+import com.letsmakerobots.donation.barometer.DonationBarometer;
+
+public final class DonationSparkLine implements DonationBarometer {
+
+ @Override
+ public String create(Donations donations) {
+ StringBuffer b = new StringBuffer();
+ b.append("<html>\n");
+ b.append(" <head>\n");
+ b.append(" <script type=\"text/javascript\" src=\"https://www.google.com/jsapi\"></script>\n");
+ b.append(" <script type=\"text/javascript\">\n");
+ b.append(" google.load(\"visualization\", \"1\", {packages:[\"imagesparkline\"]});\n");
+ b.append(" google.setOnLoadCallback(drawChart);\n");
+ b.append("\n");
+ b.append(" function drawChart() {\n");
+ b.append(" var data = new google.visualization.DataTable();\n");
+ b.append(" data.addColumn(\"number\", \"Your Donations\");\n");
+ Collection<Donation> byDate = donations.getCumulativeDonationsByDate();
+ b.append(" data.addRows("+byDate.size()+");\n");
+ int i = 0;
+ for (Donation donation : byDate) {
+
+ b.append(" data.setValue("+i+",0,"+donation.getAmount()+");\n");
+ i++;
+ }
+ b.append("\n");
+ b.append(" var chart = new google.visualization.ImageSparkLine(document.getElementById('chart_div'));\n");
+ b.append(" chart.draw(data, {width: 120, height: 40, showAxisLines: false, showValueLabels: false, labelPosition: 'left'});\n");
+ b.append(" }\n");
+ b.append(" </script>\n");
+ b.append(" </head>\n");
+ b.append("\n");
+ b.append(" <body>\n");
+ b.append(" <div id=\"chart_div\"></div>\n");
+ b.append(" </body>\n");
+ b.append("</html>\n");
+ return b.toString();
+ }
+
+}
View
40 LetsMakeRobotsBarometer/src/com/letsmakerobots/donation/barometer/impl/DonationVerticalBarChart.java
@@ -0,0 +1,40 @@
+package com.letsmakerobots.donation.barometer.impl;
+
+import com.letsmakerobots.donation.Donations;
+import com.letsmakerobots.donation.barometer.DonationBarometer;
+
+public final class DonationVerticalBarChart implements DonationBarometer {
+
+ @Override
+ public String create(Donations donations) {
+ StringBuffer b = new StringBuffer();
+ b.append("<html>\n");
+ b.append(" <head>\n");
+ b.append(" <script type=\"text/javascript\" src=\"https://www.google.com/jsapi\"></script>\n");
+ b.append(" <script type=\"text/javascript\">\n");
+ b.append(" google.load(\"visualization\", \"1\", {packages:[\"columnchart\"]});\n");
+ b.append(" google.setOnLoadCallback(drawChart);\n");
+ b.append(" function drawChart() {\n");
+ b.append(" var data = new google.visualization.DataTable();\n");
+ b.append(" data.addColumn('string', 'Project');\n");
+ b.append(" data.addColumn('number', 'LMRv4 Development Costs');\n");
+ b.append(" data.addColumn('number', 'Your Donations');\n");
+ b.append(" data.addRows(1);\n");
+ b.append(" data.setValue(0, 0, 'LMRv4');\n");
+ b.append(" data.setValue(0, 1, "+donations.getEstimatedTotalAmount()+");\n");
+ b.append(" data.setValue(0, 2, "+donations.summarizeDonations()+");\n");
+ b.append("\n");
+ b.append(" var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));\n");
+ b.append(" chart.draw(data, {width: 400, height: 240, is3D: false, title: 'Live Status of LMRv4 Donations'});\n");
+ b.append(" }\n");
+ b.append(" </script>\n");
+ b.append(" </head>\n");
+ b.append("\n");
+ b.append(" <body>\n");
+ b.append(" <div id=\"chart_div\"></div>\n");
+ b.append(" </body>\n");
+ b.append("</html>\n");
+ return b.toString();
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.