Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //helper class methods:
- public ArrayList<Entry> date_products_values(String variant) {
- Cursor c = null;
- //initialize arrays
- ArrayList<Entry> values = new ArrayList<>();
- product_labels.clear();
- SQLiteDatabase db = this.getReadableDatabase();
- //open query cursor
- c = db.rawQuery("select p_name ,sum('" + variant + "') as sum \n" +
- "from total_sales\n" +
- "group by product_id ORDER BY sum('" + variant + "') DESC", null);
- int i = 0;
- if (c != null) {
- try {
- while (c.moveToNext()) {
- //get total sum of variant
- Double sum = c.getDouble(1);
- //get top 10
- if (product_labels.size() < 10) {
- product_labels.add(mFormat.format(sum).replace(".0", "") + " " + c.getString(c.getColumnIndex("p_name")));
- values.add(new Entry(Float.valueOf(String.valueOf(sum)), i));
- } else {
- //tried this to get other products as well
- if (!product_labels.contains("Others")) {
- product_labels.add(mFormat.format(sum).replace(".0", "") + " Others");
- values.add(new Entry(Float.valueOf(String.valueOf(sum)), i));
- }
- }
- Log.d("sum_product_values_", String.valueOf(sum) + "/" + c.getString(c.getColumnIndex("p_name")));
- i++;
- }
- } finally {
- c.close();
- }
- }
- return values;
- }
- public ArrayList<String> product_labels() {
- return product_labels;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement