<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZYWC.ZW.Core.Analysis.Data;
using ZYWC.ZW.Core.Analysis.Model;

namespace ZYWC.ZW.Core.Analysis.BusinessLogic
{
    public class LiuNianAnalyzer
    {
        private DAL dal;

        public LiuNianAnalyzer(DAL dal)
        {
            this.dal = dal;
        }

        public IList<LiuNianInfo> GetLiuNianInfo(string[] stars, GongIndex index)
        {
            var list = new List<LiuNianInfo>();
            if (stars == null || stars.Length == 0)
                return list;

            int id = 0;
            switch (index)
            {
                case GongIndex.命宫: id = 0; break;
                case GongIndex.夫妻宫: id = 1; break;
                case GongIndex.事业宫: id = 2; break;
                case GongIndex.财帛宫: id = 3; break;
                case GongIndex.迁移宫: id = 4; break;
                case GongIndex.田宅宫: id = 5; break;
                case GongIndex.疾厄宫: id = 6; break;
                case GongIndex.仆役宫: id = 7; break;
                case GongIndex.父母宫: id = 8; break;
                case GongIndex.子女宫: id = 9; break;
                default: return list;
            }

            var container = dal.s43.Find(d => d.id == id);
            string xingid = null;
            if (stars.Length == 1)
            {
                xingid = dal.Dic_ZhuXing[stars[0]].id.ToString();
            }
            else if (stars.Length == 2)
            {
                xingid = string.Format("{0}#{1}", dal.Dic_ZhuXing[stars[0]].id, dal.Dic_ZhuXing[stars[1]].id);
            }
            else
            {
                return list;
            }

            var raw = container.starDatas.Where(d => d.id == xingid);
            foreach(var item in raw)
            {
                var info = new LiuNianInfo()
                {
                    id = item.id,
                    name = item.name,
                    title = item.title,
                    text = item.text
                };
                list.Add(info);
            }

            return list;
        }


        #region 流年财运

        /// <summary>
        /// 获取流年财运指数
        /// </summary>
        /// <param name="pan"></param>
        /// <returns></returns>
        public float GetLiuNianCaiboScore(PaiPan pan)
        {
            var caiboMing = pan.Gongs.First(g => g.Name == GongIndex.财帛宫.ToString());
            var caiboXian = pan.Gongs.First(g => g.XianName == GongIndex.财帛宫.ToString());
            var caiboLiu = pan.Gongs.First(g => g.LiuName == GongIndex.财帛宫.ToString());
            var scoreMing = CaiboScore(pan, caiboMing);
            var scoreXian = CaiboScore(pan, caiboXian);
            var scoreLiu = CaiboScore(pan, caiboLiu);
            return scoreMing * ming_weight + scoreXian * xian_weight + scoreLiu * liu_weight;
        }

        private BasicGong SanFangSiZheng(PaiPan pan, string name)
        {
            //三方四正
            var model = new BasicGong();
            model.SelfGong = pan.Gongs.First(g => g.Name == name);

            int dui = (model.SelfGong.Zhi + 6) % 12;
            if (dui == 0)
            {
                dui = 12;
            }
            else if (dui < 0)
            {
                dui += 12;
            }

            int hui1 = (model.SelfGong.Zhi + 4) % 12;
            if (hui1 == 0)
            {
                hui1 = 12;
            }
            else if (hui1 < 0)
            {
                hui1 += 12;
            }


            int hui2 = (model.SelfGong.Zhi - 4) % 12;
            if (hui2 == 0)
            {
                hui2 = 12;
            }
            else if (hui2 < 0)
            {
                hui2 += 12;
            }

            model.DuiZhaoGong = pan.Gongs[dui - 1];
            model.HuiGongs.Add(pan.Gongs[hui1 - 1]);
            model.HuiGongs.Add(pan.Gongs[hui2 - 1]);

            return model;
        }

        private float CaiboScore(PaiPan pan, Gong caibo)
        {
            var sfsz = SanFangSiZheng(pan, caibo.Name);
            // 主星
            List<Star> zhuxing = caibo.Stars.Where(s => s.Type == Star.StarType.主星).ToList();
            if (zhuxing == null || zhuxing.Count == 0)
            {
                zhuxing = new List<Star>();
                var duiStars = sfsz.DuiZhaoGong.Stars.Where(s => s.Type == Star.StarType.主星);
                foreach (var star in duiStars)<commit_msg>public<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZYWC.ZW.Core.Analysis.Data;
using ZYWC.ZW.Core.Analysis.Model;

namespace ZYWC.ZW.Core.Analysis.BusinessLogic
{
    public class LiuNianAnalyzer
    {
        private DAL dal;

        public LiuNianAnalyzer(DAL dal)
        {
            this.dal = dal;
        }

        public IList<LiuNianInfo> GetLiuNianInfo(string[] stars, GongIndex index)
        {
            var list = new List<LiuNianInfo>();
            if (stars == null || stars.Length == 0)
                return list;

            int id = 0;
            switch (index)
            {
                case GongIndex.命宫: id = 0; break;
                case GongIndex.夫妻宫: id = 1; break;
                case GongIndex.事业宫: id = 2; break;
                case GongIndex.财帛宫: id = 3; break;
                case GongIndex.迁移宫: id = 4; break;
                case GongIndex.田宅宫: id = 5; break;
                case GongIndex.疾厄宫: id = 6; break;
                case GongIndex.仆役宫: id = 7; break;
                case GongIndex.父母宫: id = 8; break;
                case GongIndex.子女宫: id = 9; break;
                default: return list;
            }

            var container = dal.s43.Find(d => d.id == id);
            string xingid = null;
            if (stars.Length == 1)
            {
                xingid = dal.Dic_ZhuXing[stars[0]].id.ToString();
            }
            else if (stars.Length == 2)
            {
                xingid = string.Format("{0}#{1}", dal.Dic_ZhuXing[stars[0]].id, dal.Dic_ZhuXing[stars[1]].id);
            }
            else
            {
                return list;
            }

            var raw = container.starDatas.Where(d => d.id == xingid);
            foreach(var item in raw)
            {
                var info = new LiuNianInfo()
                {
                    id = item.id,
                    name = item.name,
                    title = item.title,
                    text = item.text
                };
                list.Add(info);
            }

            return list;
        }


        #region 流年财运

        /// <summary>
        /// 获取流年财运指数
        /// </summary>
        /// <param name="pan"></param>
        /// <returns></returns>
        public float GetLiuNianCaiboScore(PaiPan pan)
        {
            var caiboMing = pan.Gongs.First(g => g.Name == GongIndex.财帛宫.ToString());
            var caiboXian = pan.Gongs.First(g => g.XianName == GongIndex.财帛宫.ToString());
            var caiboLiu = pan.Gongs.First(g => g.LiuName == GongIndex.财帛宫.ToString());
            var scoreMing = CaiboScore(pan, caiboMing);
            var scoreXian = CaiboScore(pan, caiboXian);
            var scoreLiu = CaiboScore(pan, caiboLiu);
            return scoreMing * ming_weight + scoreXian * xian_weight + scoreLiu * liu_weight;
        }

        private BasicGong SanFangSiZheng(PaiPan pan, string name)
        {
            //三方四正
            var model = new BasicGong();
            model.SelfGong = pan.Gongs.First(g => g.Name == name);

            int dui = (model.SelfGong.Zhi + 6) % 12;
            if (dui == 0)
            {
                dui = 12;
            }
            else if (dui < 0)
            {
                dui += 12;
            }

            int hui1 = (model.SelfGong.Zhi + 4) % 12;
            if (hui1 == 0)
            {
                hui1 = 12;
            }
            else if (hui1 < 0)
            {
                hui1 += 12;
            }


            int hui2 = (model.SelfGong.Zhi - 4) % 12;
            if (hui2 == 0)
            {
                hui2 = 12;
            }
            else if (hui2 < 0)
            {
                hui2 += 12;
            }

            model.DuiZhaoGong = pan.Gongs[dui - 1];
            model.HuiGongs.Add(pan.Gongs[hui1 - 1]);
            model.HuiGongs.Add(pan.Gongs[hui2 - 1]);

            return model;
        }

        public float CaiboScore(PaiPan pan, Gong caibo)
        {
            var sfsz = SanFangSiZheng(pan, caibo.Name);
            // 主星
            List<Star> zhuxing = caibo.Stars.Where(s => s.Type == Star.StarType.主星).ToList();
            if (zhuxing == null || zhuxing.Count == 0)
            {
                zhuxing = new List<Star>();
                var duiStars = sfsz.DuiZhaoGong.Stars.Where(s => s.Type == Star.StarType.主星);
                foreach (var star in duiStars)
{'fraction_non_alphanumeric': 0.11433028749721418, 'fraction_numerical': 0.014263427679964342, 'mean_word_length': 1.2057016465962154, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5010941', 'n_tokens_mistral': 3109, 'n_tokens_neox': 2889, 'n_words': 603}