예제 #1
0
        /// <summary>
        /// Gives back a map with the number of metntions
        /// mapped to a specific day or week
        ///
        /// NOTE
        /// This method is not the same as getNumberInfo
        /// This method will be used for widgets.
        /// </summary>
        public WidgetData GetNumberOfMentionsForItem(int itemId, int widgetId, string dateFormat, DateTime?startDate = null)
        {
            //Create widgetdata
            WidgetData widgetData = new WidgetData()
            {
                KeyValue    = "Number of mentions",
                GraphValues = new List <GraphValue>()
            };

            //Get Widget
            Widget widget = new WidgetManager(uowManager).GetWidget(widgetId);

            if (widget == null)
            {
                return(widgetData);
            }

            //Map informations to datetime and add them to the list
            IEnumerable <Information> informations = GetInformationsWithAllInfoForItem(itemId);

            if (informations == null || informations.Count() == 0)
            {
                return(widgetData);
            }

            //Determine startdata
            DateTime timestamp = widget.Timestamp.Value;

            if (startDate == null)
            {
                startDate = DateTime.Now;
            }
            else if (startDate < timestamp)
            {
                return(widgetData);
            }

            //Extract information
            while (timestamp <= startDate)
            {
                //Each grapvalue represents a total number of mentions mapped
                //To a specific data
                int couny = informations.Count(i => i.CreationDate.Value.Day == startDate.Value.Day);
                widgetData.GraphValues.Add(new GraphValue()
                {
                    Value         = startDate.Value.ToString(dateFormat),
                    NumberOfTimes = informations.Count(i => i.CreationDate.Value.Day == startDate.Value.Day)
                });
                startDate = startDate.Value.AddDays(-1);
            }

            return(widgetData);
        }
예제 #2
0
        /// <summary>
        /// Gives back a widgetdata with all the propertievalues of a specific propertie
        /// works dynamicly.
        ///
        /// WARNING
        /// This method will only work if the widget has a propertytag
        /// </summary>
        public WidgetData GetPropvaluesForWidget(int itemid, int widgetId, string proptag, DateTime?startDate = null)
        {
            //Create widgetdata
            WidgetData widgetData = new WidgetData()
            {
                KeyValue    = proptag,
                GraphValues = new List <GraphValue>()
            };

            //Get propertytag and timestamp
            Widget widget = new WidgetManager(uowManager).GetWidget(widgetId);

            if (widget == null)
            {
                return(widgetData);
            }
            DateTime?timestamp = widget.Timestamp.Value;

            if (timestamp == null)
            {
                return(widgetData);
            }

            //Determine startdata
            if (startDate == null)
            {
                startDate = DateTime.Now;
            }
            else if (startDate < timestamp)
            {
                return(widgetData);
            }

            //Get informations for item
            IEnumerable <Information> infosQueried = GetInformationsWithAllInfoForItem(itemid).Where(info => info.CreationDate <= startDate)
                                                     .Where(info => info.CreationDate > timestamp)
                                                     .AsEnumerable();

            if (infosQueried == null || infosQueried.Count() == 0)
            {
                return(widgetData);
            }

            //Map timestap to number of propertyValues
            foreach (Information information in infosQueried)
            {
                foreach (PropertyValue propval in information.PropertieValues)
                {
                    //If the name of the property is the same as the propertytag,
                    //Then the propertyvalue shall be added to the widgetdata
                    if (propval.Property.Name.ToLower().Equals(proptag.ToLower()))
                    {
                        GraphValue grapValue = widgetData.GraphValues.Where(value => value.Value.ToLower().Equals(propval.Value.ToLower())).SingleOrDefault();
                        //If A grapvalue yet exists for a specific widgetData object
                        if (grapValue != null)
                        {
                            grapValue.NumberOfTimes++;
                        }
                        //If a grapvalue does not yet exists for a specific widgetData object
                        else
                        {
                            grapValue = new GraphValue()
                            {
                                Value         = propval.Value,
                                NumberOfTimes = 1
                            };
                            widgetData.GraphValues.Add(grapValue);
                        }
                    }
                }
            }

            return(widgetData);
        }
        /// <summary>
        /// Generates dafault widgets based on the itemid
        /// </summary>
        public void GenerateDefaultItemWidgets(string name, int itemId)
        {
            uowManager = new UnitOfWorkManager();
            InitRepo();

            WidgetManager      widgetManager = new WidgetManager(uowManager);
            List <Widget>      itemWidgets   = new List <Widget>();
            List <int>         widgetIds     = new List <int>();
            List <PropertyTag> proptags;

            //Get item
            Item item = GetItemWithAllWidgets(itemId);

            //1st widget
            proptags = new List <PropertyTag>();
            proptags.Add(new PropertyTag()
            {
                Name = "Mentions"
            });
            ItemWidget widget1 = (ItemWidget)widgetManager.AddWidget(WidgetType.GraphType, name + " popularity", 1, 1, proptags: proptags, graphType: GraphType.LineChart, rowspan: 12, colspan: 6);

            itemWidgets.Add(widget1);
            widgetIds.Add(widget1.WidgetId);

            //If item is from type theme or person then
            //more items shall be added
            if (item is Theme || item is Person)
            {
                //2nd widget
                proptags = new List <PropertyTag>();
                proptags.Add(new PropertyTag()
                {
                    Name = "Gender"
                });
                ItemWidget widget2 = (ItemWidget)widgetManager.AddWidget(WidgetType.GraphType, name + " gender comparison ", 1, 1, proptags: proptags, graphType: GraphType.PieChart, rowspan: 6, colspan: 6);
                itemWidgets.Add(widget2);
                widgetIds.Add(widget2.WidgetId);

                //3rd widget
                proptags = new List <PropertyTag>();
                proptags.Add(new PropertyTag()
                {
                    Name = "Age"
                });
                ItemWidget widget3 = (ItemWidget)widgetManager.AddWidget(WidgetType.GraphType, name + " age comparison", 1, 1, proptags: proptags, graphType: GraphType.DonutChart, rowspan: 6, colspan: 6);
                itemWidgets.Add(widget3);
                widgetIds.Add(widget3.WidgetId);

                //4th widget
                proptags = new List <PropertyTag>();
                proptags.Add(new PropertyTag()
                {
                    Name = "Education"
                });
                ItemWidget widget4 = (ItemWidget)widgetManager.AddWidget(WidgetType.GraphType, name + " education comparison", 1, 1, proptags: proptags, graphType: GraphType.DonutChart, rowspan: 6, colspan: 6);
                itemWidgets.Add(widget4);
                widgetIds.Add(widget4.WidgetId);

                //5th widget
                proptags = new List <PropertyTag>();
                proptags.Add(new PropertyTag()
                {
                    Name = "Personality"
                });
                ItemWidget widget5 = (ItemWidget)widgetManager.AddWidget(WidgetType.GraphType, name + " personality comparison", 1, 1, proptags: proptags, graphType: GraphType.PieChart, rowspan: 6, colspan: 6);
                itemWidgets.Add(widget5);
                widgetIds.Add(widget5.WidgetId);
            }

            //Link widgets to item & save changes to database
            item.ItemWidgets = itemWidgets;
            itemRepo.UpdateItem(item);
            uowManager.Save();
            uowManager = null;
        }