更改对象键

时间:2016-07-07 21:22:52

标签: object key crossfilter

这是我目前的代码(使用crossfilter.js)......

function getCount(){
votersByDMA = voter_data.dimension(function(d) {if (d.dma === 'Burlington-Plattsburgh'){return 1} else {return 0}});
votersInDMA = votersByDMA.group().reduceCount();
voterCount = votersInDMA.all()[0].value;
console.log(votersInDMA.all());
console.log('value:' + voterCount);

}

它和console.logs这个

0: Object
key: 0
value: 2
__proto__
1: Object
key: 1
value: 10406

我想更改密钥,因此它需要数据的dma属性,所以它就像这样的console.logs

0: Object
key: Madison, WI
value: 2
__proto__
1: Object
key: Burlington, VT-Plattsburgh, NY
value: 10406

1 个答案:

答案 0 :(得分:0)

您是否只是更改维度访问者以返回字符串而不是数字?

# Set yesterday's date (since uploads will happen at 2am)
$YDate = (Get-Date).AddDays(-1).ToString('MM-dd-yyyy')

#Create Log File
$Logfile = "C:\powershell\$YDate.log"
Function LogWrite
{
    Param ([string]$logstring)

    Add-Content $Logfile -value $logstring
}


# Find Directory w/ Yesterday's Date in name
$YesterdayFolder = Get-ChildItem -Path "\\network\storage\location" | Where-Object {$_.FullName.contains($YDate)}


If ($YesterdayFolder) {

    #we specify the directory where all files that we want to upload are contained 
    $Dir= $YesterdayFolder
    #ftp server
    $ftp = "ftp://ftps.site.com"
    $user = "USERNAME"
    $pass = "PASSWORD"

    $webclient = New-Object System.Net.WebClient 
    $webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)


$FilesToUpload = Get-ChildItem -Path (Join-Path $YesterdayFolder.FullName "Report") | Where-Object {$_.Name.StartsWith("JONES","CurrentCultureIgnoreCase")}
foreach($item in ($FilesToUpload))
    { 
        LogWrite "Uploading file:  $YesterdayFolder\Report\$item"
        $uri = New-Object System.Uri($ftp+$item.Name) 
        $webclient.UploadFile($uri, $item.FullName)  
    }
    } Else {
        LogWrite "No files to upload"
    }

或者,如果您想保证两个存档,var votersByDMA = voter_data.dimension(function(d) { return d.dma; }); 'Burlington-Plattsburgh'

'Other'