gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r6973 - gnunet-qt/src/plugins/fs


From: gnunet
Subject: [GNUnet-SVN] r6973 - gnunet-qt/src/plugins/fs
Date: Sun, 1 Jun 2008 13:22:47 -0600 (MDT)

Author: durner
Date: 2008-06-01 13:22:45 -0600 (Sun, 01 Jun 2008)
New Revision: 6973

Modified:
   gnunet-qt/src/plugins/fs/fs-search.cc
   gnunet-qt/src/plugins/fs/fs.cc
   gnunet-qt/src/plugins/fs/fshelper.h
   gnunet-qt/src/plugins/fs/searchController.cc
   gnunet-qt/src/plugins/fs/searchController.h
   gnunet-qt/src/plugins/fs/searchItemDelegate.cc
Log:
update ranking code

Modified: gnunet-qt/src/plugins/fs/fs-search.cc
===================================================================
--- gnunet-qt/src/plugins/fs/fs-search.cc       2008-06-01 19:22:31 UTC (rev 
6972)
+++ gnunet-qt/src/plugins/fs/fs-search.cc       2008-06-01 19:22:45 UTC (rev 
6973)
@@ -137,8 +137,7 @@
   }
   
   // add availability and relevance
-  addColumn(menu, tr("Availability"), SEARCH_AVAIL_COLUMN);
-  addColumn(menu, tr("Relevance"), SEARCH_RELEVANCE_COLUMN);
+  addColumn(menu, tr("Ranking"), SEARCH_RANK_COLUMN);
   
   item = menu->exec();
   if (item)
@@ -178,8 +177,7 @@
     
     m->setHeaderData(typeIdx, Qt::Horizontal, label, Qt::DisplayRole);
   }
-  m->setHeaderData(SEARCH_AVAIL_COLUMN, Qt::Horizontal, tr("Availability"), 
Qt::DisplayRole);
-  m->setHeaderData(SEARCH_RELEVANCE_COLUMN, Qt::Horizontal, tr("Relevance"), 
Qt::DisplayRole);  
+  m->setHeaderData(SEARCH_RANK_COLUMN, Qt::Horizontal, tr("Ranking"), 
Qt::DisplayRole);
     
   // get columns to be displayed
   // FIXME
@@ -187,13 +185,14 @@
   cols.append(EXTRACTOR_FILE_SIZE);
   cols.append(EXTRACTOR_MIMETYPE);
   cols.append(EXTRACTOR_THUMBNAIL_DATA);
-  cols.append(SEARCH_AVAIL_COLUMN);
-  cols.append(SEARCH_RELEVANCE_COLUMN);
+  cols.append(SEARCH_RANK_COLUMN);
   
   for (colIdx = 0; colIdx < m->columnCount(); colIdx++)
     setColHidden(MODEL_IDX(colIdx), !cols.contains(colIdx));
   treeResults->setColumnWidth(0, 200);
   treeResults->setColumnWidth(MODEL_IDX(EXTRACTOR_FILE_SIZE), 50);
+  treeResults->header()->moveSection(SEARCH_RANK_COLUMN, 2);
+  treeResults->setColumnWidth(SEARCH_RANK_COLUMN, 50);
 }
 
 void GFSSearch::setModel(QStandardItemModel *model)

Modified: gnunet-qt/src/plugins/fs/fs.cc
===================================================================
--- gnunet-qt/src/plugins/fs/fs.cc      2008-06-01 19:22:31 UTC (rev 6972)
+++ gnunet-qt/src/plugins/fs/fs.cc      2008-06-01 19:22:45 UTC (rev 6973)
@@ -46,6 +46,9 @@
 
 static void *fsuiEventProcessor(void *cls, const GNUNET_FSUI_Event *event)
 {
+  void *ret;
+  int i;
+  
   GFSSearchController *searchCntrl = ((GFSPlugin *) cls)->searchController();
   GFSUploadController *uploadCntrl = ((GFSPlugin *) cls)->uploadController();
   GFSDownloadController *downloadCntrl = ((GFSPlugin *) 
cls)->downloadController();
@@ -66,16 +69,26 @@
         event->type);
       break;
     case GNUNET_FSUI_search_resumed:
-      return searchCntrl->started(event->data.SearchResumed.sc.pos,
+      ret = searchCntrl->started(event->data.SearchResumed.sc.pos,
         event->data.SearchResumed.searchURI,
         event->data.SearchResumed.fisSize,
         event->data.SearchResumed.fis);
+      for (i=0; i < event->data.SearchResumed.fisSize; i++)
+        searchCntrl->update((GFSSearchInfo *) ret,
+                         &event->data.SearchResumed.fis[i],
+                         event->data.SearchResumed.searchURI,
+                         event->data.SearchResumed.availability_rank[i],
+                         event->data.SearchResumed.availability_certainty[i],
+                         event->data.SearchResumed.applicability_rank[i]);
+      return ret;
     case GNUNET_FSUI_search_stopped:
       searchCntrl->stopped((GFSSearchInfo *) 
event->data.SearchStopped.sc.cctx);
       break;
     case GNUNET_FSUI_search_update:
       searchCntrl->update((GFSSearchInfo *) event->data.SearchUpdate.sc.cctx,
-          &event->data.SearchUpdate.fi, 
event->data.SearchUpdate.availability_rank,
+          &event->data.SearchUpdate.fi, event->data.SearchUpdate.searchURI,
+          event->data.SearchUpdate.availability_rank,
+          event->data.SearchUpdate.availability_certainty,
           event->data.SearchUpdate.applicability_rank);
       break;
     case GNUNET_FSUI_upload_started:
@@ -147,6 +160,7 @@
   qRegisterMetaType<QModelIndex>("QModelIndex");
   qRegisterMetaType<Qt::Orientation>("Qt::Orientation");
   qRegisterMetaType<QModelIndexList>("QModelIndexList");
+  qRegisterMetaType<GRanking>("GRanking");
 
   cfg = config;
   ectx = errorContext;

Modified: gnunet-qt/src/plugins/fs/fshelper.h
===================================================================
--- gnunet-qt/src/plugins/fs/fshelper.h 2008-06-01 19:22:31 UTC (rev 6972)
+++ gnunet-qt/src/plugins/fs/fshelper.h 2008-06-01 19:22:45 UTC (rev 6973)
@@ -33,9 +33,8 @@
 
 #define SEARCH_URI_COLUMN ((int) EXTRACTOR_getHighestKeywordTypeNumber() + 1)
 #define SEARCH_META_COLUMN ((int) EXTRACTOR_getHighestKeywordTypeNumber() + 2)
-#define SEARCH_AVAIL_COLUMN ((int) EXTRACTOR_getHighestKeywordTypeNumber() + 3)
-#define SEARCH_RELEVANCE_COLUMN ((int) EXTRACTOR_getHighestKeywordTypeNumber() 
+ 4)
-#define SEARCH_MAX_COLUMN SEARCH_RELEVANCE_COLUMN
+#define SEARCH_RANK_COLUMN ((int) EXTRACTOR_getHighestKeywordTypeNumber() + 3)
+#define SEARCH_MAX_COLUMN SEARCH_RANK_COLUMN
 
 /* Maps view index 0 ("Filename") to model index 1 (EXTRACTOR_FILENAME).
  * We can't use unified indexes because row decorations (branches, +/-)
@@ -50,6 +49,17 @@
   EXTRACTOR_THUMBNAIL_DATA : (i == EXTRACTOR_THUMBNAIL_DATA) ? \
   EXTRACTOR_FILE_SIZE : (EXTRACTOR_KeywordType) i)
 
+typedef struct
+{
+  int availability_rank;
+  unsigned int availability_certainty;
+  unsigned int applicability_rank;
+  long long rank_sort;
+  unsigned int keywords;
+} GRanking;
+
+Q_DECLARE_METATYPE(GRanking)
+
 /**
  * @brief Get the name of a given keyword/metadata type
  * @param type the keyword/metadata type

Modified: gnunet-qt/src/plugins/fs/searchController.cc
===================================================================
--- gnunet-qt/src/plugins/fs/searchController.cc        2008-06-01 19:22:31 UTC 
(rev 6972)
+++ gnunet-qt/src/plugins/fs/searchController.cc        2008-06-01 19:22:45 UTC 
(rev 6973)
@@ -230,12 +230,16 @@
 }
 
 void GFSSearchController::update(GFSSearchInfo *info, const 
GNUNET_ECRS_FileInfo *finfo,
-    int avail, unsigned int relevance)
+    const struct GNUNET_ECRS_URI *searchURI, int avail, unsigned int cert,
+    unsigned int relevance)
 {
   QStandardItemModel *model;
   GFSEcrsUri ecrsUri;
   QModelIndexList lst;
-  int row;
+  int row, availmax, availmin;
+  GRanking rank;
+  QVariant var;
+  QModelIndex idx;
   
   model = info->model;
   ecrsUri = finfo->uri;
@@ -245,16 +249,26 @@
 
   row = lst.at(0).row();
   
-  avail *= 10;
-  if (avail > 100)
-    avail = 100;
-  else if (avail < 0)
-    avail = 0;
+  rank.availability_rank = avail;
+  rank.availability_certainty = cert;
+  rank.applicability_rank = relevance;
+  rank.rank_sort = (int) avail + (int) (avail * (int) cert * 65536);
+  rank.keywords = GNUNET_ECRS_uri_get_keyword_count_from_ksk(searchURI);
   
-  model->setData(model->index(row, SEARCH_AVAIL_COLUMN),
-      QString::number(avail) + "%");
-  model->setData(model->index(row, SEARCH_RELEVANCE_COLUMN),
-      QString::number(relevance));
+  var.setValue(rank);
+  idx = model->index(row, SEARCH_RANK_COLUMN);
+  model->setData(idx, var);
+  
+  availmax = (((double) avail + (GNUNET_FSUI_MAX_PROBES - cert)) / 
GNUNET_FSUI_MAX_PROBES) * 100;
+  availmin = (double) avail / GNUNET_FSUI_MAX_PROBES * 100;
+  if (availmin < 0)
+    availmin = 0;
+  
+  model->setData(idx, tr("Relevance:") + " " +
+      QString::number((double) relevance / rank.keywords * 100.0, 'f', 2) + 
+      "%\n" + tr("Availability:") + " " + QString::number(availmin) + "% " +
+        ((availmax > 0 && availmax != availmin) ? " - " +
+        QString::number(availmax) + "%" : ""), Qt::ToolTipRole);
 }
 
 void GFSSearchController::closed(GFSEcrsUri &uri)

Modified: gnunet-qt/src/plugins/fs/searchController.h
===================================================================
--- gnunet-qt/src/plugins/fs/searchController.h 2008-06-01 19:22:31 UTC (rev 
6972)
+++ gnunet-qt/src/plugins/fs/searchController.h 2008-06-01 19:22:45 UTC (rev 
6973)
@@ -60,7 +60,8 @@
   void downloadCompleted(QPersistentModelIndex &idx, GString file);
   void state(GFSSearchInfo *info, GNUNET_FSUI_EventType event);
   void update(GFSSearchInfo *info, const GNUNET_ECRS_FileInfo *finfo,
-      int avail, unsigned int relevance);
+      const struct GNUNET_ECRS_URI *searchURI, int avail, unsigned int cert,
+      unsigned int relevance);
 
   static void addSearchResult(QStandardItemModel *model, QModelIndex parent,
     const GNUNET_ECRS_FileInfo *info);

Modified: gnunet-qt/src/plugins/fs/searchItemDelegate.cc
===================================================================
--- gnunet-qt/src/plugins/fs/searchItemDelegate.cc      2008-06-01 19:22:31 UTC 
(rev 6972)
+++ gnunet-qt/src/plugins/fs/searchItemDelegate.cc      2008-06-01 19:22:45 UTC 
(rev 6973)
@@ -26,7 +26,10 @@
 
 #include <QApplication>
 #include <QPainter>
+#include <QBrush>
+#include <QColor>
 #include <extractor.h>
+#include <GNUnet/gnunet_fsui_lib.h>
 #include "searchItemDelegate.h"
 #include "fshelper.h"
 
@@ -72,6 +75,54 @@
     
     painter->drawImage(QPoint(left, option.rect.top()), img);
   }
+  else if (index.column() == SEARCH_RANK_COLUMN)
+  {
+    GRanking rank;
+    QString str;
+    QRect rect;
+    int colwidth, colheight, w, x1, x2, ydelta, hue;
+        
+    rank = var.value<GRanking>();
+    drawBackground(painter, option, index);
+
+    colwidth = option.rect.width() - 3;
+    colheight = option.rect.height() - 2;
+    if (colheight > 16)
+      colheight = 16;
+    ydelta = (option.rect.height() - colheight) / 2;
+    
+    rect.setRect(option.rect.x() + 1, option.rect.y() + ydelta, colwidth *
+        (rank.applicability_rank / (double) rank.keywords), colheight / 2);
+    if (!var.isNull())
+      painter->fillRect(rect, QBrush(QColor(0, 0, 255)));
+    
+    rect.setWidth(colwidth);
+    painter->drawRect(rect);
+    
+    w = (int) ((colwidth / 2.0) / GNUNET_FSUI_MAX_PROBES * 
rank.availability_rank);
+    x1 = rect.x() + colwidth / 2;
+    x2 = x1 + w;
+    
+    if (w < 0)
+    {
+      w *= -1;
+      hue = 0;
+    }
+    else
+      hue = 170;
+    
+    rect.setRect((x1 < x2 ? x1 : x2), option.rect.y() + ydelta + (colheight / 
2), w + 1, colheight / 2);
+    if (!var.isNull())
+      painter->fillRect(rect, QBrush(QColor::fromHsv(hue, 255, 128 + 
+          (GNUNET_FSUI_MAX_PROBES - rank.availability_certainty) * ((240.0 - 
128) / GNUNET_FSUI_MAX_PROBES))));
+
+    rect.setX(option.rect.x() + 1);
+    rect.setWidth(colwidth);
+    rect.setHeight(colheight / 2 - 1);
+    painter->drawRect(rect);
+    painter->drawLine(rect.x() + colwidth / 2, rect.y(),
+        rect.x() + colwidth / 2, rect.y() + colheight / 2 - 1);
+  }
   else if (index.model()->data(index, Qt::UserRole) == 1)
   {
     // expanded directory





reply via email to

[Prev in Thread] Current Thread [Next in Thread]