Skip to content

Commit

Permalink
用來測試分析頁面, 還沒完成
Browse files Browse the repository at this point in the history
  • Loading branch information
doremi committed May 29, 2012
1 parent 0309a17 commit 6e661a1
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ class
sleep
clock
ptr
count
count
analysis
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TARGET = notify notify2 ass1 bsf itoa fsm jump clock ptr count
TARGET = notify notify2 ass1 bsf itoa fsm jump clock ptr count analysis

all:$(TARGET)

Expand Down Expand Up @@ -32,6 +32,9 @@ ptr:ptr.cpp
count:count.c
gcc -Wall -o $@ $< -g

analysis:analysis.cpp
g++ -Wall -std=c++0x -o $@ $< -g

clean:
rm -rf $(TARGET)

54 changes: 54 additions & 0 deletions analysis.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <stdio.h>
#include <vector>
#include <time.h>
#include <stdint.h>

using namespace std;

struct Record {
int time;
int meter;
};

vector<Record> days[2];

void make_record(int day, int time, int meter)
{
Record record;
record.time = time;
record.meter = meter;
days[day].push_back(record);
}

void list_day(int day)
{
printf("=== Day %d ===\n", day+1);
auto it = days[day].begin();
for (; it != days[day].end(); ++it) {
printf("Time: %02d, meter: %d\n", it->time, it->meter);
}
}

void analysis()
{
int day = 0;
for (uint32_t i = 1; i < days[day].size(); ++i) {
Record prev = days[day][i-1];
Record curr = days[day][i];
printf("ave time: %d, avg meter: %f\n",
(curr.time+prev.time)/2, (double)(curr.meter-prev.meter)/((curr.time-prev.time)*60));
}
}

int main()
{
make_record(0, 8, 5);
make_record(0, 12, 10);
make_record(0, 19, 20);
make_record(0, 22, 25);
list_day(0);

analysis();

return 0;
}

0 comments on commit 6e661a1

Please sign in to comment.