当前位置: 首页>>代码示例>>C#>>正文


C# IManosContext.GetUserID方法代码示例

本文整理汇总了C#中IManosContext.GetUserID方法的典型用法代码示例。如果您正苦于以下问题:C# IManosContext.GetUserID方法的具体用法?C# IManosContext.GetUserID怎么用?C# IManosContext.GetUserID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IManosContext的用法示例。


在下文中一共展示了IManosContext.GetUserID方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetUserData

        public void GetUserData(IManosContext ctx)
        {
            var ratings = MyRecommender.Instance.Data;
            var user_mapping = MyRecommender.Instance.UserMapping;
            var item_mapping = MyRecommender.Instance.ItemMapping;

            int user_id = ctx.GetUserID("users");

            if (user_id < 0 || user_id > ratings.MaxUserID)
            {
                ctx.Response.StatusCode = 404; // TODO maybe different error code
                ctx.Response.End();
                return;
            }

            var match = new Regex(@"users/\d+/(\w+)").Match(ctx.Request.Path);
            string command = match.Success ? match.Groups[1].Value : string.Empty;

            switch(command)
            {
                case "statistics":
                    ctx.Response.WriteLine("uid={0} num_ratings={1}", user_mapping.ToOriginalID(user_id), ratings.ByUser[user_id].Count);
                    break;
                case "events":
                    var items_string = ctx.Request.QueryData.GetString("items");
                    if (items_string == null)
                    {
                        foreach (int index in ratings.ByUser[user_id])
                            ctx.Response.WriteLine("eid={0} iid={1} value={2}", index, item_mapping.ToOriginalID(ratings.Items[index]), ratings[index].ToString(CultureInfo.InvariantCulture));
                    }
                    else
                    {
                        var requested_items = new HashSet<int>(from i in items_string.Split(',') select item_mapping.ToInternalID(int.Parse(i)));
                        foreach (int index in ratings.ByUser[user_id])
                        {
                            int item_id = ratings.Items[index];
                            if (requested_items.Contains(item_id))
                                ctx.Response.WriteLine("eid={0} iid={1} value={2}", index, item_mapping.ToOriginalID(item_id), ratings[index].ToString(CultureInfo.InvariantCulture));
                        }
                    }
                    break;
                case "events/ratings": // TODO support timestamps
                    goto case "events";
                case "":
                    ctx.Response.WriteLine("no user metadata available");
                    break;
                default:
                    ctx.Response.StatusCode = 404; // TODO maybe different error
                    break;
            }

            ctx.Response.End();
        }
开发者ID:zenogantner,项目名称:MyMediaREST,代码行数:53,代码来源:UserDataModule.cs

示例2: Predict

        public void Predict(IManosContext ctx)
        {
            var recommender = MyRecommender.Instance.Predictor;
            var ratings = MyRecommender.Instance.Data;
            var item_mapping = MyRecommender.Instance.ItemMapping;

            int user_id = ctx.GetUserID("users", "predictions");

            if (user_id < 0 || user_id > recommender.MaxUserID)
            {
                ctx.Response.StatusCode = 404; // TODO maybe different error
                ctx.Response.End();
                return;
            }

            var query_data = ctx.Request.QueryData;

            // TODO do this in a more elegant way
            var items_string = query_data.GetString("items");
            var requested_items = items_string != null
                ? from i in items_string.Split(',') select item_mapping.ToInternalID(int.Parse(i))
                : Enumerable.Range(0, ratings.MaxItemID + 1);

            // TODO do this in a more elegant way
            var override_value = query_data.GetString("useStoredRatings");
            bool show_stored_ratings = override_value != null ? override_value.Equals("true", StringComparison.InvariantCultureIgnoreCase) : false;

            // TODO sort results

            if (show_stored_ratings)
            {
                var known_items = new HashSet<int>(
                    from index in ratings.ByUser[user_id]
                    select ratings.Items[index]);

                foreach (int item_id  in requested_items)
                    if (known_items.Contains(item_id))
                        ctx.Response.WriteLine("iid={0} value={1}", item_mapping.ToOriginalID(item_id), ratings[user_id, item_id]);
                    else
                        ctx.Response.WriteLine("iid={0} value={1}", item_mapping.ToOriginalID(item_id), recommender.Predict(user_id, item_id).ToString(CultureInfo.InvariantCulture));
            }
            else
                foreach (int item_id  in requested_items)
                    ctx.Response.WriteLine("iid={0} value={1}", item_mapping.ToOriginalID(item_id), recommender.Predict(user_id, item_id).ToString(CultureInfo.InvariantCulture));

            ctx.Response.End();
        }
开发者ID:zenogantner,项目名称:MyMediaREST,代码行数:47,代码来源:RatingPredictionModule.cs


注:本文中的IManosContext.GetUserID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。