Exemplo n.º 1
0
        private static async void Post(ParticipantFeedItem item)
        {
            using (HttpClient client = new HttpClient())
            { 
                Uri baseAddress = new Uri(BaseUri);
                client.BaseAddress = baseAddress;

                HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, BaseUri + "Feed");

                //TODO login headers

                HttpContent content = new StringContent(JsonConvert.SerializeObject(item), System.Text.Encoding.UTF8,
                    "application/json");
                requestMessage.Content = content;

                HttpResponseMessage response = await client.SendAsync(requestMessage);
                string toReturn = await response.Content.ReadAsStringAsync();
            }

        }
Exemplo n.º 2
0
        protected void submitBtn_Click(object sender, EventArgs e)
        {
            if (!IsValid)
            {
                return;
            }

            Session["newStoryForm"] = "submitted";

            ParticipantFeedItem item = new ParticipantFeedItem
            {
                Title = newTitle.Text,
                Description = newDesc.Text,
                Dismissable = true,
                Importance = 1,
                Global = true
            };

            int typeVal = int.Parse(newType.SelectedValue);

            if (typeVal >= 1)
            {

                item.Image = newImage.Text;
            }

            if (typeVal >= 2)
            {
                item.Interaction = new ParticipantFeedItemInteraction
                {
                    Label = "Open story",
                    Type = ParticipantFeedItemInteraction.InteractionType.Url,
                    Value = newLink.Text
                };
            }

            Post(item);
        }
Exemplo n.º 3
0
        //http://localhost:52215/api/Feedback?id=null
        public async Task<HttpResponseMessage> Get(int? id)
        {
            using (CrowdContext db = new CrowdContext())
            {
                User user = await AuthenticateUser(GetAuthentication(), db);
                if (user == null)
                {
                    return new HttpResponseMessage(HttpStatusCode.Unauthorized);
                }

                try
                {
                    int submissionId = id ?? -1;
                    int jobId = -1;
                    if (submissionId >= 0)
                    {
                        ParticipantResult res = await db.ParticipantResults.FindAsync(id);
                        if (res != null)
                        {
                            if (res.User != user)
                            {
                                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.Forbidden));
                            }
                            jobId = res.CrowdJobId;
                        }
                        else
                        {
                            throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
                        }
                    }

                    List<ParticipantFeedItem> feedback = new List<ParticipantFeedItem>();

                    float? accentRating = await AverageRating("rlstaccent", user, db, jobId);
                    if (accentRating != null)
                    {
                        var accentFeedback = new ParticipantFeedItem
                        {
                            Rating = (float)accentRating,
                            Title = "Accent Influence",
                            Description =
                                "This rating shows how much your accent affected listeners' understanding of your speech.",
                            Date = DateTime.Now,
                            Dismissable = false,
                            Importance = 10
                        };
                        feedback.Add(accentFeedback);
                    }

                    float? transRating = await AverageRating("rlsttrans", user, db, submissionId);
                    if (transRating != null)
                    {
                        var transFeedback = new ParticipantFeedItem
                        {
                            Rating = (float)transRating,
                            Title = "Difficulty of Understanding",
                            Description = "This rating shows how difficult listeners find understanding what you say.",
                            Date = DateTime.Now,
                            Dismissable = false,
                            Importance = 10
                        };
                        feedback.Add(transFeedback);
                    }


                    ParticipantFeedItem graphFeedback = new ParticipantFeedItem
                    {
                        Title = "Understanding Progress",
                        Description = "How understandable people have found you over time.",
                        Date = DateTime.Now,
                        Dismissable = false,
                        Importance = 8,
                        DataPoints = await GetGraphPoints("rlsttrans", user, db)
                    };
                    feedback.Add(graphFeedback);

                    return new HttpResponseMessage
                    {
                        Content = new JsonContent(JsonConvert.SerializeObject(feedback))
                    };
                }
                catch (Exception)
                {
                    throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
                }
            }
            
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns the user's subscription feed
        /// </summary>
        /// <returns></returns>
        public async Task<HttpResponseMessage> Get()
        {
            using (CrowdContext db = new CrowdContext())
            {
                User user = await AuthenticateUser(GetAuthentication(), db);
                if (user == null)
                {
                    return new HttpResponseMessage(HttpStatusCode.Unauthorized);
                }

                // Get a list of all feed items which are either
                // 1- Globally visible and have not been dismissed by the user
                // 2- On this user's list of personal feed items
                List<ParticipantFeedItem> items = await (from feedItem in db.ParticipantFeedItems
                                                         where (int)feedItem.App == (int)Crowd.Model.Data.User.AppType.None || (int)feedItem.App == (int)user.App
                                                         from thisUser in db.Users
                                                         where thisUser.Email == user.Email
                                                         where (feedItem.Global && !thisUser.DismissedPublicFeedItems.Contains(feedItem)) || thisUser.FeedItems.Contains(feedItem)
                                                         select feedItem).ToListAsync();

                TimeGraphPoint[] points = await GetGraphPoints("rlsttrans", user, db);
                if (points != null && points.Length >= 2)
                {
                    foreach (TimeGraphPoint point in points)
                    {
                        point.YVal = 5 - point.YVal;
                    }

                    ParticipantFeedItem graphFeedback = new ParticipantFeedItem
                    {
                        Title = "Understanding Progress",
                        Description = "How understandable people have found you over time.",
                        Date = DateTime.Now,
                        Dismissable = false,
                        Importance = 9,
                        DataPoints = points
                    };
                    items.Add(graphFeedback);
                }

                float? transRating = await AverageRating("rlsttrans", user, db);
                if (transRating != null)
                {
                    transRating = 5 - transRating;

                    var transFeedback = new ParticipantFeedItem
                    {
                        Rating = (float)transRating,
                        Title = "Ease of Listening",
                        Description = "This rating shows how easy people found understanding what you said.",
                        Date = DateTime.Now,
                        Dismissable = false,
                        Importance = 9
                    };
                    items.Add(transFeedback);
                }

                //float? accentRating = await AverageRating("rlstaccent", user, db);
                //if (accentRating != null)
                //{
                //    accentRating = 5 - accentRating;

                //    var accentFeedback = new ParticipantFeedItem
                //    {
                //        Rating = (float)accentRating,
                //        Title = "Accent Clarity",
                //        Description =
                //            "This total average rating shows how easy to understand people find your accent.",
                //        Date = DateTime.Now,
                //        Dismissable = false,
                //        Importance = 8
                //    };
                //    items.Add(accentFeedback);
                //}

                await GetMostRecentJobId(db, user);

                float? volumeRating = await AverageRating("rlstvolume", user, db);
                if (volumeRating != null)
                {
                    string scoreDesc = "\nYou should be aiming for a score between 50 and 80.";

                    if (volumeRating > 80) scoreDesc += " You might be talking a little too loudly!";
                    else if (volumeRating < 50) scoreDesc += " Try talking a little bit louder.";

                    var volumeFeedback = new ParticipantFeedItem
                    {
                        Percentage = (float)volumeRating,
                        Title = "Speech Volume",
                        Description =
                            "This average rating shows how loud people think you speak." + scoreDesc,
                        Date = DateTime.Now,
                        Dismissable = false,
                        Importance = 8
                    };
                    items.Add(volumeFeedback);
                }

                float? paceRating = await AverageRating("rlstpace", user, db);
                if (paceRating != null)
                {
                    string scoreDesc = "\nYou should be aiming for a score between 40 and 60.";

                    if (paceRating > 60) scoreDesc += " You might be talking a little too quickly!";
                    else if (paceRating < 40) scoreDesc += " Try talking a little bit faster.";

                    var pacingFeedback = new ParticipantFeedItem
                    {
                        Percentage = (float)paceRating,
                        Title = "Rate of Speech",
                        Description =
                            "This average rating shows how fast people think you speak." + scoreDesc,
                        Date = DateTime.Now,
                        Dismissable = false,
                        Importance = 8
                    };
                    items.Add(pacingFeedback);
                }

                float? pitchRating = await AverageRating("rlstpitch", user, db);
                if (pitchRating != null)
                {
                    string scoreDesc = "\nYou should be aiming for a score between 50 and 80.";

                    if (pitchRating > 80) scoreDesc += " You might be talking a little too animatedly!";
                    else if (pitchRating < 40) scoreDesc += " You might be speaking in a dull or monotonous tone.";

                    var pitchFeedback = new ParticipantFeedItem
                    {
                        Percentage = (float)pitchRating,
                        Title = "Pitch Change",
                        Description =
                            "This average rating shows how much people think your pitch changes over the course of a sentence." + scoreDesc,
                        Date = DateTime.Now,
                        Dismissable = false,
                        Importance = 8
                    };
                    items.Add(pitchFeedback);
                }

                float? minPairsRating = await MinimalPairsScore(user, db);
                if (minPairsRating != null)
                {
                    var mpFeedback = new ParticipantFeedItem
                    {
                        Percentage = minPairsRating,
                        Title = "QuickFire Success",
                        Description = "This is the success rating of people identifying the words spoken in your QuickFire tests!",
                        Date = DateTime.Now,
                        Dismissable = false,
                        Importance = 8
                    };
                    items.Add(mpFeedback);
                }

                if (items.Count == 0)
                {
                    items.Add(new ParticipantFeedItem
                    {
                        Title = "No stories available",
                        Description = "Your news feed is looking a bit empty! Complete assessments and activities to fill it up with results and feedback. Be sure to check back regularly!",
                        Date = DateTime.Now,
                        Dismissable = false,
                        Importance = 5,
                    });
                }

                if (user.App == Crowd.Model.Data.User.AppType.Speeching)
                {
                    ParticipantActivity assessment = await GetAssessmentIfNeeded(db, user);
                    if (assessment != null)
                    {
                        items.Add(new ParticipantFeedItem
                        {
                            Title = "A new assessment is available!",
                            Description =
                                "There's a new assessment available for you to complete!\n" + assessment.Description,
                            Date = DateTime.Now,
                            Dismissable = false,
                            Importance = 10,
                            Interaction = new ParticipantFeedItemInteraction
                            {
                                Type = ParticipantFeedItemInteraction.InteractionType.Assessment,
                                Value = assessment.Id.ToString(),
                                Label = "Start Assessment!"
                            }
                        });
                    }
                    else
                    {
                        items.Add(new ParticipantFeedItem
                        {
                            Title = "No Assessment Available",
                            Description = "You submitted an assessment recently - please wait at least a day before doing another.",
                            Date = DateTime.Now,
                            Dismissable = false,
                            Importance = 5,
                            App = Crowd.Model.Data.User.AppType.None
                        });
                    }
                }
                else if(user.App == Crowd.Model.Data.User.AppType.Fluent)
                {
                    ParticipantActivity scenario = await GetRandomScenario(db, user);
                    if (scenario != null)
                    {
                        items.Add(new ParticipantFeedItem
                        {
                            Title = "Try this scenario!",
                            Description =
                                "There's a scenario available for you to complete!\n" + scenario.Description,
                            Date = DateTime.Now,
                            Dismissable = false,
                            Importance = 10,
                            Interaction = new ParticipantFeedItemInteraction
                            {
                                Type = ParticipantFeedItemInteraction.InteractionType.Activity,
                                Value = scenario.Id.ToString(),
                                Label = "Start Scenario!"
                            }
                        });
                    }
                }

                return new HttpResponseMessage()
                {
                    Content = new JsonContent(items)
                };
            }
        }