Android Open Source - Android-Counter-App Statistic Model






From Project

Back to project page Android-Counter-App.

License

The source code is released under:

Apache License

If you think the Android project Android-Counter-App listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
  Statistic Model/*from   www .j ava 2 s.  com*/
  
  This class defines the methodology for interpreting the Calendar
  objects stored in CounterModels.
  
  Copyright 2014 David Yee

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
 */

package ca.ualberta.cs.asn1;

import java.util.Calendar;

/*
 * StatisticModel contains helper methods to assist in parsing the 
 * calender date objects. The methods simply return integer values at 
 * given date intervals (ie: hours, dates, months, and years) that 
 * reflect the amount of counts that are related to the given 
 * parameters.
 */
public class StatisticModel {
      private CounterModel data;
      private int startYear;
      private int endYear;

      public StatisticModel(CounterModel data) {
    super();
    this.data = data;
    
    if(this.data.getDate().size() > 0){
        // get first year
        this.startYear = data.getDate().get(0).get(Calendar.YEAR);
        
        // get last year
        this.endYear = data.getDate().get(this.data.getDate().size() - 1).get(Calendar.YEAR);
    }
  }
  
  public Integer findCountsPerMonth(int month, int year){
      int result = 0;
      for(int i=0; i<data.getDate().size(); i++){
          if(data.getDate().get(i).get(Calendar.YEAR) == year 
                  && data.getDate().get(i).get(Calendar.MONTH) == month)
              result++;
      }
      return result;
  }
  
  public Integer findCountsPerWeek(int week, int month, int year){
      int result = 0;
            for(int i=0; i<data.getDate().size(); i++){
                if(data.getDate().get(i).get(Calendar.YEAR) == year 
                        && data.getDate().get(i).get(Calendar.MONTH) == month 
                        && data.getDate().get(i).get(Calendar.WEEK_OF_MONTH) == week)
                    result++;
            }
            return result;
  }
  
  public Integer findCountsPerDay(int day, int month, int year){
            int result = 0;
            for(int i=0; i<data.getDate().size(); i++){
                if(data.getDate().get(i).get(Calendar.YEAR) == year 
                        && data.getDate().get(i).get(Calendar.MONTH) == month 
                        && data.getDate().get(i).get(Calendar.DATE) == day)
                    result++;
            }
            return result;
        }
  
  public Integer findCountsPerHour(int hour, int day, int month, int year){
            int result = 0;
            for(int i=0; i<data.getDate().size(); i++){
                if(data.getDate().get(i).get(Calendar.YEAR) == year 
                        && data.getDate().get(i).get(Calendar.MONTH) == month 
                        && data.getDate().get(i).get(Calendar.DATE) == day
                        && data.getDate().get(i).get(Calendar.HOUR_OF_DAY) == hour)
                    result++;
            }
            return result;
        }
  
  /*
   * This function converts a given integer month value to a string.
   * The calendar class defines the 12 months in a year starting at 0 for 
   * January.
   */
  public String numberToMonth(Integer month){
          if(month >= 0 && month < 12){
              final String[] monthNames = {"January", "February", "March", "April", 
                                            "May", "June", "July", "August",
                                            "September", "October", "November", "December"};
              return monthNames[month];
          }
          else{
              return null;
          }
  }
  
  public int getStartYear(){
      return startYear;
  }
  public int getEndYear(){
      return endYear;
  }
}




Java Source Code List

ca.ualberta.cs.asn1.CounterActivity.java
ca.ualberta.cs.asn1.CounterListAdapter.java
ca.ualberta.cs.asn1.CounterModel.java
ca.ualberta.cs.asn1.CounterSaveModel.java
ca.ualberta.cs.asn1.StatisticActivity.java
ca.ualberta.cs.asn1.StatisticModel.java