Пример #1
0
 void StartAddWeights(postsPost post, int weight)
 {
     var worker = InitializeAddWeightsWorker(post, weight);
     worker.RunWorkerAsync();
 }
Пример #2
0
 BackgroundWorker InitializeAddWeightsWorker(postsPost post, int weight)
 {
     ButtonsAvailable = false;
     BackgroundWorker worker = new BackgroundWorker();
     worker.DoWork += (sender, e) => { AddWeights(post, weight); };
     worker.RunWorkerCompleted += (sender, e) => { AddWeightsCompleted(post.id); };
     return worker;
 }
Пример #3
0
        public void LoadTags(postsPost post)
        {
            StatusString = "Loading tag info for post " + post.id + "...";

            string sURL;
            sURL = " https://e621.net/post/tags.xml?id=" + post.id;
            WebRequest wrGETURL;
            wrGETURL = WebRequest.Create(sURL);
            wrGETURL.Proxy = myProxy;

            Stream objStream;
            objStream = wrGETURL.GetResponse().GetResponseStream();

            StreamReader objReader = new StreamReader(objStream);

            TagsForDisplay.Clear();

            try
            {
                var serializer = new XmlSerializer(typeof(tags));
                tags result = (tags)serializer.Deserialize(objReader);

                foreach (var tag in result.tag)
                {
                    Tag currentTag;
                    if (tagList.Tags.Any(t => t.Name == tag.name))
                    {
                        currentTag = tagList.Tags.First(t => t.Name == tag.name);
                        currentTag.Count = Int32.Parse(tag.count);
                    }
                    else
                    {
                        currentTag = new Tag { Name = tag.name, Count = Int32.Parse(tag.count) };
                        tagList.Tags.Add(currentTag);
                    }
                    TagsForDisplay.Add(currentTag);
                }
                TagsForDisplay = new ObservableCollection<Tag>(TagsForDisplay.OrderByDescending(t => t.Weight));
            }
            catch
            {
                StatusString = "Failed to read tags for post " + post.id;
            }
        }
Пример #4
0
        public void LoadImage(postsPost post)
        {
            string path = "temp\\" + post.id + "." + post.file_ext;
            using (var client = new WebClient())
            {
                client.Proxy = myProxy;
                //Console.WriteLine("Downloading " + post.file_url + "...");
                StatusString = "Downloading " + post.file_url + "..." + " ("
                    + Math.Round((Double.Parse(post.file_size) / (double)1024), 0) + " KB)";

                client.DownloadFile(post.file_url, path);

                StatusString = "File " + post.file_url + " was successfully downloaded.";
            }
        }
Пример #5
0
        public void BeforeAnswer()
        {
            i++;

            var orderedPosts = posts.Where(p => !viewedPosts.Contains(p.id)).OrderByDescending(p => CalculateWeigth(p.tags.Split(' ')));
            post = orderedPosts.First();

            LoadTags(post);
            PostTagWeight = CalculateWeigth(post.tags.Split(' '));
            PostTagCount = post.tags.Split(' ').Count();

            var worker = InitializeLoadImageWorker();
            worker.RunWorkerAsync();
        }
Пример #6
0
        public void AddWeights(postsPost post, int weight)
        {
            foreach (var currentTag in TagsForDisplay)
            {
                if (weight != 0)
                {
                    double relativeWeight = weight;

                    //weight addition depends on how rare the tag is
                    var sqrt = Math.Pow((double)currentTag.Count / (double)postCount, 1.0 / 3.0);
                    relativeWeight = weight / sqrt;

                    //weight addition depends on how much negative/positive weight is already accumulated
                    if (currentTag.Weight != 0)
                    {
                        var i = 1 - Math.Abs((double)relativeWeight / (double)currentTag.Weight);
                        if (i > 0)
                        {
                            if ((relativeWeight < 0) == (currentTag.Weight < 0))
                            {
                                relativeWeight = relativeWeight + relativeWeight * (Math.Pow(i, 3) * (1 / sqrt));
                            }
                            //else
                            //{
                            //    relativeWeight = relativeWeight - relativeWeight * (Math.Pow(i, 3) * (1 / sqrt));
                            //}
                        }
                    }
                    currentTag.Weight += relativeWeight;
                }
            }
        }