Git Product home page Git Product logo

makoonij / applied Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jurioli/applied

0.0 1.0 0.0 361 KB

.NET Extension methods for object-object or dictionary-object or datatable-object mapping, single item mapping use [ item.Apply(()=>new { .. }); ],multiple array items mapping use [ items.Apply(a=>new { .. }); ]. Extension methods for SQL Window Function in Linq, use [ items.GroupBy(a =>...).AsPartition(p=> p.OrderBy(a=>...)).Over(p=>...); ],can also be customize function.

C# 100.00%

applied's Introduction

Applied

.NET Extension methods for object-object or dictionary-object or datatable-object mapping, single item mapping use [ item.Apply(()=>new { .. }); ],multiple array items mapping use [ items.Apply(a=>new { .. }); ].
Extension methods for SQL Window Function in Linq, use [ items.GroupBy(a =>...).AsPartition(p=> p.OrderBy(a=>...)).Over(p=>...); ],can also be customize function.

    public enum UserEnum
    {
        None,
        User
    }
    [Serializable]
    public class User
    {
        public int UserID { get; set; }
        public string Name { get; set; }
        public DateTime? Time { get; set; }
        public UserEnum Enum { get; set; }
    }
    [Serializable]
    public class UserViewModel
    {
        public int UserID { get; set; }
        public string Name { get; set; }
        public DateTime? Time { get; set; }
        public UserEnum Enum { get; set; }
    }
    User[] users = new User[]
    {
        new User() { UserID = 1, Name = "Sam     " },
        new User() { UserID = 2, Name = "John    " }
    };

    users.Apply(a => new { Time = DateTime.Now, Enum = UserEnum.User });
    users.Trim();
    users.Apply(a => new { Time = DateTime.Now, Enum = UserEnum.User }).Trim();
    UserViewModel[] vm1 = users.ToDataEnumerable<User, UserViewModel>().ToArray();
    DataTable dt1 = users.ToDataTable();
    Dictionary<string, object>[] ds1 = users.ToDictionaries().ToArray();

    UserViewModel[] vm2 = dt1.ToDataEnumerable<UserViewModel>().ToArray();
    UserViewModel[] vm3 = ds1.ToDataEnumerable<UserViewModel>().ToArray();

    DataTable dt2 = vm1.ToDataTable();
    DataTable dt3 = ds1.ToDataTable();

    Dictionary<string, object>[] ds2 = vm1.ToDictionaries().ToArray();
    Dictionary<string, object>[] ds3 = dt1.ToDictionaries().ToArray();
    public class TestData
    {
        public int Year { get; set; }
        public string Name { get; set; }
        public decimal Value { get; set; }
        public decimal Sum { get; set; }
        public decimal Average { get; set; }
        public int RowNumber { get; set; }
        public int Ntile { get; set; }
        public int DenseRank { get; set; }
        public int Rank { get; set; }
        public decimal FirstValue { get; set; }
        public decimal LastValue { get; set; }
        public decimal NthValue { get; set; }
        public decimal Lead { get; set; }
        public decimal Lag { get; set; }
        public decimal CumeDist { get; set; }
        public decimal PercentRank { get; set; }
        public decimal PercentileDisc { get; set; }
        public decimal PercentileCont { get; set; }
        public decimal KeepDenseRankFirst { get; set; }
        public decimal KeepDenseRankLast { get; set; }
    }
    List data = new List();
    data.Add(new TestData() { Year = 2019, Name = "A", Value = 111.1m });
    data.Add(new TestData() { Year = 2019, Name = "B", Value = 333.3m });
    data.Add(new TestData() { Year = 2019, Name = "C", Value = 333.3m });
    data.Add(new TestData() { Year = 2019, Name = "A", Value = 222.2m });
    data.Add(new TestData() { Year = 2019, Name = "C", Value = 444.4m });
    data.Add(new TestData() { Year = 2019, Name = "A", Value = 222.2m });
    data.Add(new TestData() { Year = 2019, Name = "B", Value = 333.3m });
    data.Add(new TestData() { Year = 2019, Name = "C", Value = 555.5m });
    data.Add(new TestData() { Year = 2020, Name = "A", Value = 111.1m });
    data.Add(new TestData() { Year = 2020, Name = "B", Value = 333.3m });
    data.Add(new TestData() { Year = 2020, Name = "A", Value = 222.2m });
    data.Add(new TestData() { Year = 2020, Name = "C", Value = 333.3m });

    data = data.GroupBy(a => new { a.Year }).AsPartition(p => p.OrderBy(a => a.Value).ThenBy(a => a.Name))
    .Over(p => p.Sum(a => a.Value), (a, value) => a.Apply(() => new { Sum = value }))
    .Over(p => p.Average(a => a.Value), (a, value) => a.Apply(() => new { Average = value }))
    .Over(p => p.RowNumber(), (a, value) => a.Apply(() => new { RowNumber = value }))
    .Over(p => p.Ntile(2), (a, value) => a.Apply(() => new { Ntile = value }))
    .Over(p => p.DenseRank(), (a, value) => a.Apply(() => new { DenseRank = value }))
    .Over(p => p.Rank(), (a, value) => a.Apply(() => new { Rank = value }))
    .Over(p => p.FirstValue(a => a.Value), (a, value) => a.Apply(() => new { FirstValue = value }))
    .Over(p => p.LastValue(a => a.Value), (a, value) => a.Apply(() => new { LastValue = value }))
    .Over(p => p.NthValue(a => a.Value, 2), (a, value) => a.Apply(() => new { NthValue = value }))
    .Over(p => p.Lead(a => a.Value), (a, value) => a.Apply(() => new { Lead = value }))
    .Over(p => p.Lag(a => a.Value), (a, value) => a.Apply(() => new { Lag = value }))
    .Over(p => p.CumeDist(), (a, value) => a.Apply(() => new { CumeDist = value }))
    .Over(p => p.PercentRank(), (a, value) => a.Apply(() => new { PercentRank = value }))
    .Over(p => p.PercentileDisc(0.5m, a => a.Value), (a, value) => a.Apply(() => new { PercentileDisc = value }))
    .Over(p => p.PercentileCont(0.5m, a => a.Value), (a, value) => a.Apply(() => new { PercentileCont = value }))
    .Over(p => p.KeepDenseRankFirst(g => g.Sum(a => a.Value)), (a, value) => a.Apply(() => new { KeepDenseRankFirst = value }))
    .Over(p => p.KeepDenseRankLast(g => g.Sum(a => a.Value)), (a, value) => a.Apply(() => new { KeepDenseRankLast = value }))
    .ToList();

https://www.nuget.org/packages/Applied/

applied's People

Contributors

jurioli avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.