00001 #ifndef TagsLife_TableDataSourceWeekMap_h
00002 #define TagsLife_TableDataSourceWeekMap_h
00003
00004 #include "Application/MediaTable/TableDataSource.h"
00005 #include "Tag.h"
00006
00007 #include "RemoteRetriever.h"
00008
00009 namespace Impala {
00010 namespace Application {
00011 namespace TagsLife {
00012
00013 using namespace MediaTable;
00014
00015 class TableDataSourceWeekMap : public TableDataSource
00016 {
00017 public:
00018 TableDataSourceWeekMap(Tag::weekStatsType &weekstats, int nrOfRows):
00019 TableDataSource()
00020 {
00021 Init();
00022 mWeekStats = weekstats;
00023 mTotalRows = nrOfRows;
00024 mRemoteRetriever = RemoteRetriever::GetInstance();
00025
00026
00027
00028 }
00029
00030 ~TableDataSourceWeekMap()
00031 {
00032 }
00033
00034
00035
00036 virtual String
00037 GetTextDataByID(String column, int row)
00038 {
00039 if (column == "flickrWeek" || column == "usage" || column == "views")
00040 return MakeString(GetIntDataByID(column, row));
00041 return "N/A";
00042 }
00043
00044 virtual int
00045 GetIntDataByID(String column, int row)
00046 {
00047 if (column == "flickrWeek") return row;
00048 if (mWeekStats.count(row) == 0) return 0;
00049 if (column == "usage") return (int)mWeekStats[row]->usage;
00050 if (column == "views") return (int)mWeekStats[row]->views;
00051 return 0;
00052 }
00053
00054 virtual int GetTotalRows() {
00055 return mTotalRows;
00056 }
00057
00058 virtual double
00059 GetNormalizedDataByID(String column, int row)
00060 {
00061 if (column == "contribution") {
00062 if(mWeekStats.count(row) == 0 || mWeekStats[row]->views == 0) return 0;
00063 return (double)mWeekStats[row]->mostPopularPhoto->views/(double)mWeekStats[row]->views;
00064 }
00065
00066 double v = row / (double)mTotalRows;
00067 if (column == "red")
00068 return v;
00069 if (column == "green")
00070 return 1.0 - v;
00071 if (column == "blue") {
00072 return (row % 10) / 10.0;
00073 }
00074
00075 return 0.0;
00076 }
00077
00078 virtual Array2dVec3UInt8*
00079 GetImageDataByID(String column, int row)
00080 {
00081 Array2dVec3UInt8* ar = 0;
00082 if (mWeekStats.count(row) != 0) {
00083 OGLIMAGE* oglIm = mRemoteRetriever->requestImage(mWeekStats[row]->mostPopularPhoto->imageUrl("s"));
00084 ar = (Array2dVec3UInt8*) oglIm->imageHandle;
00085 }
00086 return ar;
00087 }
00088
00089 private:
00090
00091 void Init()
00092 {
00093 AddStaticColumn("flickrWeek", TYPE_INT, 50);
00094 AddStaticColumn("most popular photo", TYPE_IMAGE, 50);
00095 AddColumn("usage", TYPE_INT, 50);
00096 AddColumn("views", TYPE_INT, 50);
00097 AddColumn("contribution", TYPE_NORMALIZEDVALUE, 50, 1);
00098 AddColumn("red", TYPE_NORMALIZEDVALUE, 50, 1);
00099 AddColumn("green", TYPE_NORMALIZEDVALUE, 50, 2);
00100 AddColumn("blue", TYPE_NORMALIZEDVALUE, 50, 3);
00101 }
00102
00103 Tag::weekStatsType mWeekStats;
00104 RemoteRetriever* mRemoteRetriever;
00105 int mTotalRows;
00106
00107 ILOG_VAR_DEC;
00108 };
00109
00110 ILOG_VAR_INIT(TableDataSourceWeekMap, Application.TagsLife);
00111
00112 }
00113 }
00114 }
00115
00116 #endif // TableDataSourceWeekMap_h