using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FLY.Simulation.Blowing
{
    class OrgData
    {
        static int[] data = new int[]{
3518	,
3484	,
3634	,
3620	,
3579	,
3625	,
3635	,
3638	,
3635	,
3606	,
3611	,
3603	,
3590	,
3631	,
3646	,
3647	,
3710	,
3705	,
3607	,
3720	,
3680	,
3637	,
3659	,
3703	,
3860	,
3720	,
3615	,
3810	,
3772	,
3666	,
3614	,
3627	,
3618	,
3502	,
3575	,
3583	,
3615	,
3680	,
3730	,
3840	,
3927	,
3946	,
3923	,
3841	,
3797	,
3865	,
3810	,
3711	,
3754	,
3705	,
3723	,
3699	,
3723	,
3801	,
3786	,
3798	,
3907	,
3945	,
3828	,
3860	,
3846	,
3903	,
3871	,
3844	,
3759	,
3816	,
3886	,
3815	,
3789	,
3876	,
3942	,
3854	,
3842	,
3921	,
3846	,
3835	,
3886	,
3881	,
3820	,
3787	,
3730	,
3617	,
3650	,
3610	,
3536	,
3545	,
3564	,
3584	,
3580	,
3572	,
3571	,
3579	,
3620	,
3634	,
3484	,
3518	
        };

        public static int[] GetData(int cnt)
        {
            int idx;
            int dat;
            int last_idx;
            int last_dat;
            //数据扩展
            int[] list = new int[cnt];
            int list_idx = 0;
            idx = 0;
            dat = data[0];
            list[list_idx] = dat;
            list_idx++;

            last_idx = idx;
            last_dat = dat;

            for (int i = 0; i < data.Length; i++)
            {
                idx = i * cnt / data.Length;
                dat = data[i];

                for (int j = last_idx + 1; j <= idx; j++)
                {
                    int d = (j - last_idx) * (dat - last_dat) / (idx - last_idx) + last_dat;
                    list[list_idx] = d;
                    list_idx++;
                }
                last_idx = idx;
                last_dat = dat;
            }
            idx = cnt;
            dat = data[0];

            for (int j = last_idx + 1; j < cnt; j++)
            {
                int d = (j - last_idx) * (dat - last_dat) / (idx - last_idx) + last_dat;
                list[list_idx] = d;
                list_idx++;

            }

            //对数据滤波
            int[] data2 = new int[cnt];
            int w = (cnt/data.Length);
            for (int i = 0; i < cnt; i++)
            {
                int sum = 0;
                for (int j = (i - w / 2); j < (i - w / 2 + w); j++) 
                {
                    int index = j;
                    if (index < 0)
                        index += cnt;
                    else if (index >= cnt)
                        index -= cnt;
                    sum += list[index];
                }
                data2[i] = sum / w;
            }
            return data2;
        }
    }
}