コード例 #1
0
ファイル: Model.cs プロジェクト: e6opoteh/E621-Browser
 void StartAddWeights(postsPost post, int weight)
 {
     var worker = InitializeAddWeightsWorker(post, weight);
     worker.RunWorkerAsync();
 }
コード例 #2
0
ファイル: Model.cs プロジェクト: e6opoteh/E621-Browser
 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
ファイル: Model.cs プロジェクト: e6opoteh/E621-Browser
        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
ファイル: Model.cs プロジェクト: e6opoteh/E621-Browser
        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
ファイル: Model.cs プロジェクト: e6opoteh/E621-Browser
        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
ファイル: Model.cs プロジェクト: e6opoteh/E621-Browser
        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;
                }
            }
        }