

Public Class DataService
    Private rnd As New Random()
    Shared _default As DataService


    Private Sub New()
    End Sub

    Public Shared ReadOnly Property Instance() As DataService
        Get
            If _default Is Nothing Then
                _default = New DataService()
            End If

            Return _default
        End Get
    End Property

    Public Function GetSunburstData() As List(Of DataItem)
        Dim list = New List(Of DataItem)()
        Dim years As New List(Of String)()
        Dim times As New List(Of List(Of String))() From {
            New List(Of String)() From {
                "Jan",
                "Feb",
                "Mar"
            },
            New List(Of String)() From {
                "Apr",
                "May",
                "June"
            },
            New List(Of String)() From {
                "Jul",
                "Aug",
                "Sep"
            },
            New List(Of String)() From {
                "Oct",
                "Nov",
                "Dec"
            }
        }

        Dim yearLen = Math.Max(CInt(Math.Round(Math.Abs(5 - Instance.rnd.NextDouble() * 10))), 3)
        Dim currentYear As Integer = DateTime.Now.Year
        For i As Integer = yearLen To 1 Step -1
            years.Add((currentYear - i).ToString())
        Next
        Dim quarterAdded = False

        years.ForEach(Function(y)
                          Dim i = years.IndexOf(y)
                          Dim addQuarter = Instance.rnd.NextDouble() > 0.5
                          If Not quarterAdded AndAlso i = years.Count - 1 Then
                              addQuarter = True
                          End If
                          Dim year = New DataItem() With {
                              .Year = y
                          }
                          If addQuarter Then
                              quarterAdded = True
                              times.ForEach(Function(q)
                                                Dim addMonth = Instance.rnd.NextDouble() > 0.5
                                                Dim idx As Integer = times.IndexOf(q)
                                                Dim quar = "Q" & (idx + 1)
                                                Dim quarters = New DataItem() With {
                                                    .Year = y,
                                                    .Quarter = quar
                                                }
                                                If addMonth Then
                                                    q.ForEach(Function(m)
                                                                  quarters.Items.Add(New DataItem() With {
                                                                      .Year = y,
                                                                      .Quarter = quar,
                                                                      .Month = m,
                                                                      .Value = rnd.[Next](20, 30)
                                                                  })

                                                              End Function)
                                                Else
                                                    quarters.Value = rnd.[Next](80, 100)
                                                End If
                                                year.Items.Add(quarters)

                                            End Function)
                          Else
                              year.Value = rnd.[Next](80, 100)
                          End If
                          list.Add(year)

                      End Function)

        Return list
    End Function

    Public Function GetData(count As Integer) As List(Of Item)
        Dim data As New List(Of Item)()
        Dim countries = "US,Germany,UK,Japan,Italy,Greece".Split(","c)
        Dim years = New Integer() {2010, 2011, 2012, 2013, 2014}
        Dim countriesLen = countries.Length
        Dim citiesByCountry = New Dictionary(Of String, String())()
        citiesByCountry.Add("US", New String() {"New York", "Los Angeles", "Chicago", "Phoenix", "Dallas"})
        citiesByCountry.Add("Germany", New String() {"Berlin", "Hamburg", "Munich", "Cologne", "Frankfurt"})
        citiesByCountry.Add("UK", New String() {"London", "Birmingham", "Leeds", "Glasgow", "Sheffield"})
        citiesByCountry.Add("Japan", New String() {"Tokyo", "Kanagawa", "Osaka", "Aichi", "Hokkaido"})
        citiesByCountry.Add("Italy", New String() {"Rome", "Milan", "Naples", "Turin", "Palermo"})
        citiesByCountry.Add("Greece", New String() {"Athens", "Thessaloniki", "Patras", "Heraklion", "Larissa"})
        For i As Integer = 0 To count - 1
            Dim yearIndex = rnd.[Next](0, 5)
            Dim cityIndex = rnd.[Next](0, 5)
            Dim countryIndex As Integer = i Mod countriesLen
            Dim country = countries(countryIndex)
            data.Add(New Item() With {
                .ID = i,
                .Country = country,
                .City = citiesByCountry(country)(cityIndex),
                .Year = years(yearIndex).ToString(),
                .Month = (i Mod 12 + 1).ToString(),
                .Day = (i Mod 27 + 1).ToString(),
                .Amount = Math.Floor(rnd.NextDouble() * 10000)
            })
        Next

        Return data
    End Function
End Class