Exemplo n.º 1
0
        //Predict match for paraticipate of each user
        public Hashtable Predict(int userID, SportEvent sevent)
        {
            Hashtable answersTable = new Hashtable();

            //Building vector from data
            double[][] test = new double[][]
            {
                new double[] { sevent.CategoryID, sevent.PlaceID }
            };
            foreach (DictionaryEntry s in usersTraining)
            {
                //foreach user except the creator of the user
                if (!s.Key.Equals(userID))
                {
                    //Checking for a match
                    Accord.MachineLearning.KNearestNeighbors model = s.Value as Accord.MachineLearning.KNearestNeighbors;
                    int[] answers    = model.Decide(test);
                    bool  answerBool = answers[0] != 0;
                    answersTable.Add(s.Key, answerBool);
                    Debug.WriteLine("User" + s.Key + ". This event is suitable for him: " + answers[0]);
                }
            }
            return(answersTable);
        }
Exemplo n.º 2
0
 private void detach_SportEvents(SportEvent entity)
 {
     this.SendPropertyChanging();
     entity.Place = null;
 }
Exemplo n.º 3
0
 private void attach_SportEvents(SportEvent entity)
 {
     this.SendPropertyChanging();
     entity.Place = this;
 }
Exemplo n.º 4
0
 private void detach_SportEvents(SportEvent entity)
 {
     this.SendPropertyChanging();
     entity.UserAccount = null;
 }
Exemplo n.º 5
0
 partial void DeleteSportEvent(SportEvent instance);
Exemplo n.º 6
0
 partial void UpdateSportEvent(SportEvent instance);
Exemplo n.º 7
0
 partial void InsertSportEvent(SportEvent instance);
Exemplo n.º 8
0
        public static void createEvent(FormCollection sportEventModel)
        {
            var dataContext = new SqlConnectionDataContext();
            int placeID     = getPlaceIDByName(dataContext, sportEventModel["location"]); //validate exist location

            if (placeID == 0)
            {
                return;
            }

            int catID = getCategoryID(dataContext, sportEventModel["category"]); //validate exist category

            if (catID == 0)
            {
                return;
            }


            SportEvent sportEvent = new SportEvent();
            int        userID     = ManageCookie.user.UserID;

            sportEvent.OwnerID = userID;

            sportEvent.CategoryID = catID;
            sportEvent.Date       = DateTime.Parse(sportEventModel["datetime"]);
            string duration = sportEventModel["duration"];

            if (String.IsNullOrWhiteSpace(duration))
            {
                sportEvent.Duration = 120;
            }
            else
            {
                if (!ValidationModel.ValidDuration(duration)) //validate duration
                {
                    return;
                }
                sportEvent.Duration = int.Parse(duration);
            }

            string max_attendies = sportEventModel["attendies"];

            if (String.IsNullOrWhiteSpace(max_attendies))
            {
                sportEvent.MaxAttendies = 12;
            }
            else
            {
                if (!ValidationModel.ValidAttendies(max_attendies)) // validate attendies
                {
                    return;
                }
                sportEvent.MaxAttendies = int.Parse(max_attendies);
            }
            string title = sportEventModel["title"];

            sportEvent.PlaceID = placeID;
            if (!ValidationModel.LengthAndNotSpecialValidationMaxOnly(title))
            {
                return;
            }
            sportEvent.title = title;

            string notes = sportEventModel["notes"];

            if (!ValidationModel.LengthAndNotSpecialValidationMaxOnly(notes))
            {
                return;
            }
            sportEvent.notes = notes;


            dataContext.SportEvents.InsertOnSubmit(sportEvent);
            try
            {
                dataContext.SubmitChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            //insert to user_event table

            Users_Event uevent = new Users_Event();

            uevent.EventID = sportEvent.EventID;
            uevent.UserID  = sportEvent.OwnerID;

            dataContext.Users_Events.InsertOnSubmit(uevent);
            try
            {
                dataContext.SubmitChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            //Retrieve ML instance
            MLModel mlModel = MLModel.GetInstance();

            //Predict classification for each user - ML
            Hashtable usersPredict = mlModel.Predict(uevent.UserID, sportEvent);

            //posting to facebook asyncly
            new Task(() => { FacebookModel.PostFacebook(sportEvent.EventID, sportEvent.title, usersPredict); }).Start();
        }