Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - using Microsoft.SqlServer.Server;
 - using System;
 - using System.Collections.Generic;
 - [Serializable]
 - [SqlUserDefinedAggregate(Format.UserDefined,
 - IsInvariantToDuplicates = false,
 - IsInvariantToOrder = false,
 - MaxByteSize = -1, Name = "OdchylenieStandardowe")]
 - public struct OdchStd : IBinarySerialize
 - {
 - public List<double> posr;
 - private int licznik; // zmienna zliczająca liczbę wierszy nie mających wartości NULL
 - private double suma; // zmienna przechowująca sumę pól
 - private double temp; // zmienna pomocnicza
 - public void Init()
 - {
 - posr = new List<double>();
 - licznik = 0;
 - suma = 0;
 - }
 - public void Accumulate(double? value)
 - {
 - if (value != null) // wyznaczanie sumy dla pól nie mających wartości NULL
 - {
 - licznik++;
 - temp = (double)value;
 - suma = suma + temp;
 - posr.Add(temp);
 - }
 - }
 - public void Merge(OdchStd Group)
 - {
 - this.suma += Group.suma;
 - this.licznik += Group.licznik;
 - this.temp += Group.temp;
 - // kiedy obliczenia równoległe suma staje się sumą z wszystkich procesów
 - }
 - public double? Terminate() //SqString
 - {
 - if (licznik <= 1)
 - {
 - return null;
 - }
 - else
 - {
 - return (double?)(this.temp); //zwrócenie ostatecznej wartości obliczeń
 - }
 - }
 - public void Write(System.IO.BinaryWriter w)
 - {
 - temp = 0;
 - double sr = suma / licznik;
 - foreach (double d in posr)
 - {
 - temp = temp + Math.Pow((d - sr), 2);
 - }
 - temp = temp / (licznik - 1);
 - temp = Math.Pow(temp, 0.5);
 - w.Write(temp);
 - //w.Write(suma);
 - w.Write(licznik);
 - }
 - public void Read(System.IO.BinaryReader r)
 - {
 - temp = r.ReadDouble();
 - //suma = r.ReadDouble();
 - licznik = r.ReadInt32();
 - }
 - }
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment