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

Possible fix to issue #3 (days tab) #8

Merged
merged 1 commit into from
Nov 30, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.tierep.notificationanalyser.models;

import android.content.Context;
import android.util.Log;

import com.j256.ormlite.android.apptools.OpenHelperManager;
import com.j256.ormlite.table.TableUtils;
Expand Down Expand Up @@ -30,6 +31,8 @@ public class DemoDataGenerator {
private List<Date> dates = new ArrayList<Date>();
private Random random = new Random();
private boolean hasGenerated = false;
private int notificationsAmount = 500;
private List<Integer> dayToSkip = Arrays.asList(23, 24, 25, 26, 27, 28);

public DemoDataGenerator(Context context) {
this.context = context;
Expand All @@ -53,14 +56,25 @@ public DemoDataGenerator(Context context) {
apps.add(new AppMock(new Application("com.foursquare.robin", false), empty));
apps.add(new AppMock(new Application("com.linkedin.android", false), empty));

Date date = new Date();
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(date.getTime());
cal.set(Calendar.HOUR_OF_DAY, 18);
cal.set(Calendar.MINUTE, 0);
for (int i = 0; i < 5000; i++) {

for (int i = 0; i < notificationsAmount; i++) {
cal.add(Calendar.HOUR, random.nextInt(2) * (-1));
cal.add(Calendar.MINUTE, random.nextInt(30));

dates.add(cal.getTime());
if (dayToSkip != null && !dayToSkip.contains(cal.get(Calendar.DAY_OF_MONTH)) ){
dates.add(cal.getTime());
Log.d("Added to dates: ", cal.getTime().toString());
}
else{
i--;
}


}
}

Expand All @@ -79,7 +93,7 @@ public void Generate(boolean emptyFirst) {
daoApp.create(app.application);
}

for (int i = 0; i < 5000; i++) {
for (int i = 0; i < notificationsAmount; i++) {
AppMock a = GenerateApplication();
NotificationItem ntf = new NotificationItem(a.application.getPackageName(), dates.get(i), GenerateApplicationMessage(a));
daoNtf.create(ntf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -110,13 +111,44 @@ public void onResume() {
super.onResume();
ListView listHistory = (ListView) this.getActivity().findViewById(R.id.list_view_history);
try {

//rawData list does not contain days where we had no notifications
List<NotificationDateView> rawData = this.getChartData(getResources().getInteger(R.integer.chart_items));
ArrayList<String> xVals = new ArrayList<String>(rawData.size());
ArrayList<BarEntry> yVals = new ArrayList<BarEntry>(rawData.size());
//add days without notifications to finalData list
List<NotificationDateView> finalData = new ArrayList<NotificationDateView>();
for (int i = 0; i < rawData.size(); i++) {
Date currentDate = rawData.get(i).Date;
finalData.add(finalData.size(), rawData.get(i));
if (i < rawData.size() - 1) {
Calendar nextRawDate = Calendar.getInstance();
nextRawDate.setTime(rawData.get(i + 1).Date);
nextRawDate.set(Calendar.HOUR_OF_DAY, 0);
nextRawDate.set(Calendar.MINUTE, 0);
nextRawDate.set(Calendar.SECOND, 0);
nextRawDate.set(Calendar.MILLISECOND,0);

Calendar nextCalendarDate = Calendar.getInstance();
nextCalendarDate.setTime(rawData.get(i).Date);
nextCalendarDate.add(Calendar.DAY_OF_YEAR, 1);
nextCalendarDate.set(Calendar.HOUR_OF_DAY, 0);
nextCalendarDate.set(Calendar.MINUTE, 0);
nextCalendarDate.set(Calendar.SECOND, 0);
nextCalendarDate.set(Calendar.MILLISECOND,0);

while (!nextCalendarDate.equals(nextRawDate)){
NotificationDateView emptyEntry = new NotificationDateView();
emptyEntry.Date = nextCalendarDate.getTime();
finalData.add(finalData.size(), emptyEntry);
nextCalendarDate.add(Calendar.DAY_OF_YEAR, 1);
}
}
}

ArrayList<String> xVals = new ArrayList<String>(finalData.size());
ArrayList<BarEntry> yVals = new ArrayList<BarEntry>(finalData.size());
for (int i = 0; i < finalData.size(); i++) {
Date currentDate = finalData.get(i).Date;
xVals.add(i, getDateFormat().format(currentDate));
yVals.add(i, new BarEntry(rawData.get(i).Notifications.floatValue(), i, currentDate));
yVals.add(i, new BarEntry(finalData.get(i).Notifications.floatValue(), i, currentDate));
}
BarDataSet dataSet = new BarDataSet(yVals, "test");
BarData data = new BarData(xVals, dataSet);
Expand Down