Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6387439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:09:09+00:00 2026-05-25T03:09:09+00:00

]i have this graph that shows the last 7 records from my sqlite database,

  • 0

]i have this graph that shows the last 7 records from my sqlite database, it works.

but i will like to know the absolute last 7 days.

enter image description here

this is my codes

if ([appDelegate.drinksOnDayArray count] >=7)
    {
        drunked = 7;
    }
    else {
        drunked = [appDelegate.drinksOnDayArray count];
    }


    if (drunked !=0) 
    {   
        if (drunked<7) {
        for (int i=drunked; i<7; i++) {

            //DayOfDrinks *drinksOnDay = [appDelegate.drinksOnDayArray objectAtIndex:i-1];

            NSString * dayString= [NSString stringWithFormat:@"Nil"];//[NSDate stringForDisplayFromDateForChart:drinksOnDay.dateConsumed];

            [dayArray addObject:dayString];//X label for graph the day of drink.

            }
        }

        for(int i=drunked; i>0; i--) 
        {
            DayOfDrinks *drinksOnDay = [appDelegate.drinksOnDayArray objectAtIndex:i-1];

            NSString * dayString= [NSDate stringForDisplayFromDateForChart:drinksOnDay.dateConsumed];

            [dayArray addObject:dayString];//X label for graph the day of drink.

            drinksOnDay.isDetailViewHydrated = NO;

            [drinksOnDay hydrateDetailViewData];

            NSNumber *sdNumber =  drinksOnDay.standardDrinks; // pass value over to Standard Drink Numbers

            //[sdArray addObject: sdNumber]; 

            float floatNum = [sdNumber floatValue]; // convert sdNumber to foat

            [sdArray addObject:[NSNumber numberWithFloat:floatNum]];//add float Value to sdArray
    }




    //Get max value using KVC


    fMax = [[sdArray valueForKeyPath:@"@max.floatValue"] floatValue];


    //Ceiling the max value
    imax = (int)ceilf(fMax);

    //Odd check to make even by checking right most bit
    imax = (imax & 0x1) ? imax + 1 : imax;

    NSMutableArray *array = [NSMutableArray arrayWithCapacity:(imax / 2) + 1];

    //Assuming all numbers are positive 

    for(int i = 0; i <= imax; i +=2)
    {
        [array addObject:[NSString stringWithFormat:@"%d", i]];
    }

    NSLog(@"Array Value %@", array);

    NSLog(@"Day Array%@", dayArray);



    NSString *sData[drunked];// = malloc(7 * sizeof(NSString *));
    for (int i=0; i<drunked; i++) 
    {
        DayOfDrinks *drinksOnDay = [appDelegate.drinksOnDayArray objectAtIndex:i];
        sData[i] = [NSString stringWithFormat:@"%@",drinksOnDay.standardDrinks];

    }
    NSLog(@"sdArray %@",sdArray);
    if (drunked<7) {
        for (int i=drunked; i<7; i++) {
            sData[i]=[NSString stringWithFormat:@"0"];
        }
    }

my sqlite statement

- (void) hydrateDetailViewData {

    //If the detail view is hydrated then do not get it from the database.
    if(isDetailViewHydrated) return;

    self.standardDrinks = [NSDecimalNumber zero];
    NSDecimalNumber *decimal = [NSDecimalNumber zero];

    if(detailStmt == nil) {
        const char *sql = "SELECT volume, percentage FROM consumed WHERE DATE(datetime) = ?";
        if(sqlite3_prepare_v2(database, sql, -1, &detailStmt, NULL) != SQLITE_OK)
            NSAssert1(0, @"Error while creating detail view statement. '%s'", sqlite3_errmsg(database));
    }

    sqlite3_bind_text(detailStmt, 1, [[NSDate stringFromDate:self.dateConsumed withFormat:@"yyyy-MM-dd"] UTF8String], -1, SQLITE_TRANSIENT);

    static NSDecimalNumberHandler* roundingBehavior = nil;

    if (roundingBehavior == nil) {
        roundingBehavior = 
        [[NSDecimalNumberHandler alloc] initWithRoundingMode:NSRoundPlain scale:1 raiseOnExactness:NO raiseOnOverflow:NO raiseOnUnderflow:NO raiseOnDivideByZero:NO];
    }       

    while(sqlite3_step(detailStmt) == SQLITE_ROW) {
        double volumeDN = sqlite3_column_double(detailStmt, 0);
        double percentageDN = sqlite3_column_double(detailStmt, 1);
        double drinks = ((volumeDN/1000) * percentageDN);
        NSDecimalNumber *drinksDec = [[NSDecimalNumber alloc] initWithDouble:drinks];
        NSDecimalNumber *countryRate = [[NSDecimalNumber alloc] initWithDouble:0.789];
        decimal = [decimal decimalNumberByAdding:[drinksDec decimalNumberByMultiplyingBy:countryRate]];
        //NSLog([NSString stringWithFormat:@"Standard Drinks - %@", self.standardDrinks]);
    }

    self.standardDrinks = [decimal decimalNumberByRoundingAccordingToBehavior:roundingBehavior];


    //Reset the detail statement so it can be used again without preparing the statement again.
    sqlite3_reset(detailStmt);

    //Set isDetailViewHydrated as YES, so we do not get it again from the database.
    isDetailViewHydrated = YES;
}


+ (void) getInitialDataToDisplay:(NSString *)dbPath {

    DrinkTabsAndNavAppDelegate *appDelegate = (DrinkTabsAndNavAppDelegate *)[[UIApplication sharedApplication] delegate];

    if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {

        const char *sql = "SELECT DATE(datetime) FROM consumed GROUP BY DATE(datetime) ORDER BY datetime DESC";
        sqlite3_stmt *selectstmt;
        if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {

            while(sqlite3_step(selectstmt) == SQLITE_ROW) {
                NSString *dateDrunk = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 0)];
                NSDate *theDate = [NSDate dateFromString:dateDrunk withFormat:@"yyyy-MM-dd"];
                DayOfDrinks *drinkDayObj = [[DayOfDrinks alloc] initWithDateConsumed:theDate];
                [drinkDayObj hydrateDetailViewData];
                //NSLog([NSDate stringFromDate:drinkDayObj.dateConsumed withFormat:@"yyyy-MM-dd"]);
                [appDelegate.drinksOnDayArray addObject:drinkDayObj];
                [drinkDayObj release];
            }
        }
    }
    else
        sqlite3_close(database); //Even though the open call failed, close the database connection to release all the memory.

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T03:09:09+00:00Added an answer on May 25, 2026 at 3:09 am

    Without going through those blocks of code, I’ll hazard a guess here:

    SELECT * FROM CONSUMED WHERE DATE BETWEEN ? AND ?
    

    Set up a date 7 days ago (7*24*60*60*1000 milliseconds ago), as well as now, and bind those to the question marks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a graph in an SSRS report that shows percentages. I achieved this
The situation is this: You have a Hibernate context with an object graph that
I have this RewriteRule that works too well :-) RewriteRule ^([^/]*)/$ /script.html?id=$1 [L] The
I have a Samurize config that shows a CPU usage graph similar to Task
What I have is a configuration file that looks like this: Item|Size|Directory|Data A|12|D_01|11/28/10 C|13|D_01|11/28/10
I have a column graph, that shows a trend of consumption over time, The
I have a flot graph that polls data via ajax from an XML document.
I have this object graph, I want to map: abstract Account (username, password, ...)
I have this code in jQuery, that I want to reimplement with the prototype
This is a follow on from my last question relating to plotting timestamps in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.