Monday, October 28, 2013

Downloads per country

Hi. I should like to know if there is a way to have a download report or graphic by countries. For example, a graphic of countries sorted by downloads amount. This could be useful to know where my app and OS are better accepted. Thanks.


Buenas. Me guataría saber si hay alguna manera de hacer un informe de descargas por paises. Por ejemplo, un gráfico con los paises ordenados por numero de descargas. Esto sería bueno para ver en que sitios la aplicación y el sistema operativo tienen mas aceptación. Gracias.


Downloads per country

Hi Fisiovictor,


Based on the current scenario, it seems that you want to create a report that display the countries and the corresponding downloads amount, and the countries should be sorted by downloads amount. In Reporting Services, we can create a report project, set up connection information, define a query, add a Table data region, and sort the table sorted by downloads amount.


For more detail, please refer to the following links:

http://technet.microsoft.com/en-us/library/ms167305.aspx

http://technet.microsoft.com/en-us/library/dd220417.aspx#Sorting


If there are any misunderstanding, please elaborate the issue for further investigation.


Thanks,

Katherine Xiong




We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time.

Thanks for helping make community forums a great place.


Combination Algorithm

I am trying to write a small code to find the possible combinations from a list of integer values which when added is equal to the input value or somewhat nearing.


List<int> comb = new List<comb>() { 618, 350, 308, 300, 250, 232, 200, 128 };


The above list contains the integer values from which the proper combination has to be generated


The combination should have least number of values i.e., greatest number has to used most


Example:


If Input from User [Value = 2386]


Combination 1 = 618 + 350 + 308 + 300 + 250 + 232 + 200 + 128


Combination 2 = 618 + 618 + 618 + 300 + 232


I have used the below code, but have missed some logic.



public static void Main(string[] args)
{
//subtotal list
List<int> totals = new List<int>(new int[] { 618, 350, 308, 300, 250, 232, 200, 128 });

// get matches
List<int[]> results = KnapSack.MatchTotal(2682, totals);

// print results
foreach (var result in results)
{
Console.WriteLine(string.Join(",", result));
}

Console.WriteLine("Done.");
}

internal static List<int[]> MatchTotal(int theTotal, List<int> subTotals)
{
List<int[]> results = new List<int[]>();
while (subTotals.Contains(theTotal))
{
results.Add(new int[1] { theTotal });
subTotals.Remove(theTotal);
}

if (subTotals.Count == 0)
return results;

subTotals.Sort();

double mostNegativeNumber = subTotals[0];
if (mostNegativeNumber > 0)
mostNegativeNumber = 0;

if (mostNegativeNumber == 0)
subTotals.RemoveAll(d => d > theTotal);

for (int choose = 0; choose <= subTotals.Count; choose++)
{
IEnumerable<IEnumerable<int>> combos = Combination.Combinations(subTotals.AsEnumerable(), choose);

results.AddRange(from combo in combos where combo.Sum() == theTotal select combo.ToArray());
}
return results;
}


public static class Combination
{
public static IEnumerable<IEnumerable<T>> Combinations<T>(this IEnumerable<T> elements, int choose)
{
return choose == 0 ?
new[] { new T[0] } :
elements.SelectMany((element, i) =>
elements.Skip(i + 1).Combinations(choose - 1).Select(combo => (new[] { element }).Concat(combo)));
}
}

Is there any other way other than the above to get combinations


Combination Algorithm

Hello Joel,


As mentioned in the previous comment, it gives me distinct values.


Now as input you have given 2386.


The output will be 618,350,308,300,250,232,200,128


However the output can also be 618,618,618,300,232.


That's my point. I am facing the same problem with the code i am using. I am also getting distinct values.


I do not need unique values in the output, the output can can contain as many number of same values.


How to avoid that ?


Combination Algorithm

the program takes a very long time to run because of all the combinations and the added check to filter out duplicates.



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
const int TOTAL = 2386;
static List<int> totals = new List<int>(new int[] { 618, 350, 308, 300, 250, 232, 200, 128 });
static List<List<int>> matches = new List<List<int>>();
static void Main(string[] args)
{
List<int> numbersUsed = new List<int>();
int total = 0;
RecursiveCount(numbersUsed, total);
Console.ReadLine();
}
static void RecursiveCount(List<int> numbersUsed, int total)
{
if (numbersUsed.Count > 0)
{
//check total
if (total == 2386)
{
numbersUsed.Sort();
Boolean found = false;
foreach(List<int> match in matches)
{
if (numbersUsed.Count == match.Count)
{
Boolean rowMatch = true;
for (int i = 0; i < numbersUsed.Count; i++)
{
if (numbersUsed[i] != match[i])
{
rowMatch = false;
break;
}
}
if (rowMatch == true)
{
found = true;
break;
}
}
}
if (!found)
{
matches.Add(numbersUsed);
string[] strNumbers = numbersUsed.Select(x => x.ToString()).ToArray();
string numbers = string.Join(",", strNumbers);
Console.WriteLine(" the total of 2386 can be made from the following numbers {0}", numbers);
}
}
}
if (total < TOTAL)
{
for (int index = 0; index < totals.Count; index++)
{
int newtotal = total + totals[index];
List<int> newnumbersUsed = new List<int>(numbersUsed);
newnumbersUsed.Add(totals[index]);
RecursiveCount(newnumbersUsed, newtotal);
}
}
}
}
}





jdweng


Combination Algorithm

I haven't checked your code, so I can't say what is wrong with it but for an input of 2386 the following code gives these answers (runtime is 127mS on my computer


618,618,618,300,232

618,618,350,350,250,200

618,618,350,300,300,200

618,618,350,300,250,250

618,618,350,200,200,200,200

618,618,308,250,232,232,128

618,618,300,300,300,250

618,618,300,250,200,200,200

618,618,250,250,250,200,200

618,350,350,308,232,200,200,128

618,350,350,300,128,128,128,128,128,128

618,350,308,300,250,232,200,128

618,350,308,250,250,250,232,128

618,350,250,200,200,128,128,128,128,128,128

618,308,308,232,232,232,200,128,128

618,308,308,128,128,128,128,128,128,128,128,128

618,308,300,300,300,232,200,128

618,308,300,300,250,250,232,128

618,308,300,232,232,232,232,232

618,308,300,232,200,200,200,200,128

618,308,250,250,232,200,200,200,128

618,300,300,200,200,128,128,128,128,128,128

618,300,250,250,200,128,128,128,128,128,128

618,250,250,250,250,128,128,128,128,128,128

618,232,232,232,232,200,128,128,128,128,128

618,232,128,128,128,128,128,128,128,128,128,128,128,128

618,200,200,200,200,200,128,128,128,128,128,128

350,350,350,350,350,308,200,128

350,350,350,350,308,300,250,128

350,350,350,308,308,232,232,128,128

350,350,350,308,300,300,300,128

350,350,350,308,300,200,200,200,128

350,350,350,308,250,250,200,200,128

350,350,350,232,232,232,128,128,128,128,128

350,350,308,308,308,250,128,128,128,128

350,350,308,300,300,250,200,200,128

350,350,308,300,250,250,250,200,128

350,350,308,250,250,250,250,250,128

350,350,308,250,232,232,232,232,200

350,350,308,250,232,128,128,128,128,128,128,128

350,350,308,250,200,200,200,200,200,128

350,308,308,308,300,300,128,128,128,128

350,308,308,308,200,200,200,128,128,128,128

350,308,308,300,232,232,200,200,128,128

350,308,308,250,250,232,232,200,128,128

350,308,300,300,300,300,200,200,128

350,308,300,300,300,250,250,200,128

350,308,300,300,250,250,250,250,128

350,308,300,300,232,232,232,232,200

350,308,300,300,232,128,128,128,128,128,128,128

350,308,300,300,200,200,200,200,200,128

350,308,300,250,250,232,232,232,232

350,308,300,250,250,200,200,200,200,128

350,308,250,250,250,250,200,200,200,128

350,308,232,232,232,232,200,200,200,200

350,308,232,200,200,200,128,128,128,128,128,128,128

350,308,200,200,200,200,200,200,200,200,128

350,300,232,232,232,200,200,128,128,128,128,128

350,300,200,128,128,128,128,128,128,128,128,128,128,128,128

350,250,250,232,232,232,200,128,128,128,128,128

350,250,250,128,128,128,128,128,128,128,128,128,128,128,128

308,308,308,300,250,200,200,128,128,128,128

308,308,308,250,250,250,200,128,128,128,128

308,308,300,300,250,232,232,200,128,128

308,308,300,250,250,250,232,232,128,128

308,308,250,232,232,232,232,232,232,128

308,308,250,232,232,200,200,200,200,128,128

308,300,300,300,300,300,250,200,128

308,300,300,300,300,250,250,250,128

308,300,300,300,250,232,232,232,232

308,300,300,300,250,200,200,200,200,128

308,300,300,250,250,250,200,200,200,128

308,300,250,250,250,250,250,200,200,128

308,300,250,232,232,232,232,200,200,200

308,300,250,232,200,200,128,128,128,128,128,128,128

308,300,250,200,200,200,200,200,200,200,128

308,250,250,250,250,250,250,250,200,128

308,250,250,250,232,232,232,232,200,200

308,250,250,250,232,200,128,128,128,128,128,128,128

308,250,250,250,200,200,200,200,200,200,128

300,300,250,232,232,232,200,128,128,128,128,128

300,300,250,128,128,128,128,128,128,128,128,128,128,128,128

300,250,250,250,232,232,232,128,128,128,128,128

250,232,232,232,232,232,232,232,128,128,128,128

250,232,232,232,200,200,200,200,128,128,128,128,128

250,200,200,200,128,128,128,128,128,128,128,128,128,128,128,128



void Main()
{
int target = 2386;
var available = new List<int>{618,350,308,300,250,232,200,128};

foreach (var result in findCombinations(target, 0,new List<int>(), available))
{
stringList(result).Dump();
}
}

IEnumerable<IEnumerable<int>> findCombinations(int target, int soFar, IList<int> used, IEnumerable<int> available)
{
if (available.Count () == 0) yield break;
var first = available.First ();
var usedNow = new List<int>(used);

// Adding the first available number gets the result we want
if (soFar + first == target) {
// add the first number and return the list
usedNow.Add(first);
yield return usedNow;
} else
// Adding the first number leaves us short, so append the number to the usedNow list, increment soFar and try
// again with the same set of available numbers
if (soFar + first < target) {
usedNow.Add(first);
foreach (var element in findCombinations(target, soFar+first, usedNow, available))
{
yield return element;
}
}
// Otherwise adding the first number takes us over the total, just skip that combination

// Whatever happened, try again with the same inputs but skip the first available number
foreach (var element in findCombinations(target, soFar, used, available.Skip(1)))
{
yield return element;
}
}

string stringList(IEnumerable<int> nums)
{
if (!nums.Any ( )) return string.Empty;
return nums.Select (r => r.ToString()).Aggregate ((t,r) =>t+","+r );
}


Is that what you want?

(The call to Dump() is a Linqpad.net provided method - you could replace it with Console.WriteLine())


Paul Linton


Combination Algorithm

Hello Paul,


Yes i wanted the output to show all the possible combination, and your previous code will suffice.


I will modify it as per my needs.


R&D is always good.


Thank You