Installing Aqueduct for a dart server - server

I'm trying to build a server using Dart/Aqueduct.
But when i try to set things up i get following error after i type "pub global activate aqueduct" in my command line:
../../runtime/vm/raw_object.cc: 283: error: unreachable code
Dumping native stack trace for thread 33
[0x000000000090efc3] dart::Profiler::DumpStackTrace()
[0x000000000090efc3] dart::Profiler::DumpStackTrace()
[0x000000000068d1a1] dart::DynamicAssertionHelper::Fail(char const*, ...)
[0x00000000009122a0] dart::RawObject::VisitPointers(dart::ObjectPointerVisitor*)
[0x0000000000951b18] dart::Scavenger::ProcessToSpace(dart::ScavengerVisitor*)
[0x000000000095212d] dart::Scavenger::Scavenge(bool)
[0x0000000000768609] dart::Heap::CollectNewSpaceGarbage(dart::Thread*, dart::Heap::ApiCallbacks, dart::Heap::GCReason)
[0x0000000000767692] dart::Heap::AllocateNew(long)
[0x00000000007e715e] dart::Object::Allocate(long, long, dart::Heap::Space)
[0x00000000007ea9e6] dart::Array::New(long, dart::Heap::Space)
[0x00000000009bd031] dart::DRT_AllocateArray(dart::NativeArguments)
[0x00007f77e26a061b] [Stub] CallToRuntime
[0x00007f77e26a16e2] [Stub] AllocateArray
I had to terminate the execution because it got stuck.
it also gets stuck using "pub global activate stagehand" so i guess the problem is with "pub global activate ... "
Hope someone has an idea and can help me.
Thanks in advance
after running "pub global activate -v aqueduct"
FINE: Pub 1.24.0-dev.6.4
MSG : Resolving dependencies...
SLVR: Solving dependencies:
| - aqueduct any from hosted (aqueduct)
IO : Get versions from https://pub.dartlang.org/api/packages/aqueduct.
FINE: HTTP GET https://pub.dartlang.org/api/packages/aqueduct
| Accept: application/vnd.pub.v2+json
| X-Pub-OS: linux
| X-Pub-Command: global activate
| X-Pub-Session-ID: 55613A99-D375-47A9-9088-AAB0A68A7438
| user-agent: Dart pub 1.24.0-dev.6.4
FINE: HTTP response 200 OK for GET https://pub.dartlang.org/api/packages/aqueduct
| took 0:00:00.644556
| date: Sat, 03 Jun 2017 19:20:30 GMT
| transfer-encoding: chunked
| via: 1.1 google
| content-type: application/json
| x-frame-options: SAMEORIGIN
| x-xss-protection: 1; mode=block
| x-content-type-options: nosniff
| server: nginx
SLVR: * start at root
IO : Get versions from https://pub.dartlang.org/api/packages/stack_trace.
FINE: HTTP GET https://pub.dartlang.org/api/packages/stack_trace
| Accept: application/vnd.pub.v2+json
| X-Pub-OS: linux
| X-Pub-Command: global activate
| X-Pub-Session-ID: 55613A99-D375-47A9-9088-AAB0A68A7438
| user-agent: Dart pub 1.24.0-dev.6.4
FINE: HTTP response 200 OK for GET https://pub.dartlang.org/api/packages/stack_trace
| took 0:00:00.267917
| date: Sat, 03 Jun 2017 19:20:30 GMT
| transfer-encoding: chunked
| via: 1.1 google
| content-type: application/json
| x-frame-options: SAMEORIGIN
| x-xss-protection: 1; mode=block
| x-content-type-options: nosniff
| server: nginx
SLVR: Could not get versions for stack_trace from hosted:
| Connection closed while receiving data
|
| package:pub/src/source/hosted.dart 337 BoundHostedSource._throwFriendlyError
| package:pub/src/source/hosted.dart 139 BoundHostedSource.doGetVersions
| package:pub/src/source.dart 165 BoundSource.getVersions
| package:pub/src/solver/version_solver.dart 230 SolverCache.getVersions.<fn>
| package:pub/src/http.dart 227 withDependencyType
| package:pub/src/solver/version_solver.dart 229 SolverCache.getVersions
| package:pub/src/solver/unselected_package_queue.dart 121 UnselectedPackageQueue._getNumVersions
| package:pub/src/solver/unselected_package_queue.dart 50 UnselectedPackageQueue.add
| package:pub/src/solver/version_selection.dart 68 VersionSelection.select.<fn>
| dart:async Future.forEach
| package:pub/src/solver/version_selection.dart 61 VersionSelection.select
| package:pub/src/solver/backtracking_solver.dart 308 BacktrackingSolver._solve.<fn>
| dart:async Future.doWhile
| package:pub/src/solver/backtracking_solver.dart 276 BacktrackingSolver._solve
| package:pub/src/solver/backtracking_solver.dart 176 BacktrackingSolver.solve
| package:pub/src/solver/version_solver.dart 41 resolveVersions.<fn>
| package:pub/src/log.dart 409 progress
| package:pub/src/solver/version_solver.dart 39 resolveVersions
| package:pub/src/global_packages.dart 166 GlobalPackages._installInCache
| package:pub/src/global_packages.dart 116 GlobalPackages.activateHosted
| package:pub/src/command/global_activate.dart 91 GlobalActivateCommand.run
| package:args/command_runner.dart 194 CommandRunner.runCommand
| package:pub/src/command_runner.dart 168 PubCommandRunner.runCommand.<fn>
| dart:async new Future.sync
| package:pub/src/utils.dart 99 captureErrors.<fn>
| package:stack_trace Chain.capture
| package:pub/src/utils.dart 114 captureErrors
| package:pub/src/command_runner.dart 168 PubCommandRunner.runCommand
| package:pub/src/command_runner.dart 117 PubCommandRunner.run
| /tmp/tmp5krbLf/dart-1.24.0-dev.6.4/dart/third_party/pkg/pub/bin/pub.dart 8 main
| ===== asynchronous gap ===========================
| dart:async _Completer.completeError
| package:pub/src/source/hosted.dart 152 BoundHostedSource.doGetVersions
| ===== asynchronous gap ===========================
| dart:async _asyncErrorWrapperHelper
| package:pub/src/source/hosted.dart 128 BoundHostedSource.doGetVersions
| package:pub/src/source.dart 165 BoundSource.getVersions
| package:pub/src/solver/version_solver.dart 230 SolverCache.getVersions.<fn>
| package:pub/src/http.dart 227 withDependencyType
| package:pub/src/solver/version_solver.dart 229 SolverCache.getVersions
| ===== asynchronous gap ===========================
| dart:async new Future.microtask
| package:pub/src/solver/version_solver.dart 203 SolverCache.getVersions
| package:pub/src/solver/unselected_package_queue.dart 121 UnselectedPackageQueue._getNumVersions
| ===== asynchronous gap ===========================
| dart:async new Future.microtask
| package:pub/src/solver/unselected_package_queue.dart 115 UnselectedPackageQueue._getNumVersions
| package:pub/src/solver/unselected_package_queue.dart 50 UnselectedPackageQueue.add
| ===== asynchronous gap ===========================
| dart:async new Future.microtask
| package:pub/src/solver/unselected_package_queue.dart 44 UnselectedPackageQueue.add
| package:pub/src/solver/version_selection.dart 68 VersionSelection.select.<fn>
| ===== asynchronous gap ===========================
| dart:async new Future.microtask
| package:pub/src/solver/version_selection.dart 61 VersionSelection.select.<fn>
| dart:async Future.forEach
| package:pub/src/solver/version_selection.dart 61 VersionSelection.select
| ===== asynchronous gap ===========================
| dart:async Future.forEach
| package:pub/src/solver/version_selection.dart 61 VersionSelection.select
| ===== asynchronous gap ===========================
| dart:async _asyncThenWrapperHelper
| package:pub/src/solver/version_selection.dart 53 VersionSelection.select
| package:pub/src/solver/backtracking_solver.dart 308 BacktrackingSolver._solve.<fn>
| ===== asynchronous gap ===========================
| dart:async _asyncThenWrapperHelper
| package:pub/src/solver/backtracking_solver.dart 276 BacktrackingSolver._solve.<fn>
| dart:async Future.doWhile
| package:pub/src/solver/backtracking_solver.dart 276 BacktrackingSolver._solve
| ===== asynchronous gap ===========================
| dart:async Future.doWhile
| package:pub/src/solver/backtracking_solver.dart 276 BacktrackingSolver._solve
| ===== asynchronous gap ===========================
| dart:async new Future.microtask
| package:pub/src/solver/backtracking_solver.dart 274 BacktrackingSolver._solve
| package:pub/src/solver/backtracking_solver.dart 176 BacktrackingSolver.solve
| ===== asynchronous gap ===========================
| dart:async _asyncThenWrapperHelper
| package:pub/src/solver/backtracking_solver.dart 157 BacktrackingSolver.solve
| package:pub/src/solver/version_solver.dart 41 resolveVersions.<fn>
| package:pub/src/log.dart 409 progress
| package:pub/src/solver/version_solver.dart 39 resolveVersions
| package:pub/src/global_packages.dart 166 GlobalPackages._installInCache
| ===== asynchronous gap ===========================
| dart:async new Future.microtask
| package:pub/src/global_packages.dart 160 GlobalPackages._installInCache
| package:pub/src/global_packages.dart 116 GlobalPackages.activateHosted
| ===== asynchronous gap ===========================
| dart:async new Future.microtask
| package:pub/src/global_packages.dart 114 GlobalPackages.activateHosted
| package:pub/src/command/global_activate.dart 91 GlobalActivateCommand.run
| package:args/command_runner.dart 194 CommandRunner.runCommand
| ===== asynchronous gap ===========================
| dart:async new Future.microtask
| package:args/command_runner.dart 142 CommandRunner.runCommand
| package:pub/src/command_runner.dart 168 PubCommandRunner.runCommand.<fn>
| dart:async new Future.sync
| package:pub/src/utils.dart 99 captureErrors.<fn>
| package:stack_trace Chain.capture
| package:pub/src/utils.dart 114 captureErrors
| package:pub/src/command_runner.dart 168 PubCommandRunner.runCommand
SLVR: Could not get versions for stack_trace from hosted:
| Connection closed while receiving data
|
| package:pub/src/source/hosted.dart 337 BoundHostedSource._throwFriendlyError
| package:pub/src/source/hosted.dart 139 BoundHostedSource.doGetVersions
| package:pub/src/source.dart 165 BoundSource.getVersions
| package:pub/src/solver/version_solver.dart 230 SolverCache.getVersions.<fn>
| package:pub/src/http.dart 227 withDependencyType
| package:pub/src/solver/version_solver.dart 229 SolverCache.getVersions
| package:pub/src/solver/unselected_package_queue.dart 121 UnselectedPackageQueue._getNumVersions
| package:pub/src/solver/unselected_package_queue.dart 50 UnselectedPackageQueue.add
| package:pub/src/solver/version_selection.dart 68 VersionSelection.select.<fn>
| dart:async Future.forEach
| package:pub/src/solver/version_selection.dart 61 VersionSelection.select
| package:pub/src/solver/backtracking_solver.dart 308 BacktrackingSolver._solve.<fn>
| dart:async Future.doWhile
| package:pub/src/solver/backtracking_solver.dart 276 BacktrackingSolver._solve
| package:pub/src/solver/backtracking_solver.dart 176 BacktrackingSolver.solve
| package:pub/src/solver/version_solver.dart 41 resolveVersions.<fn>
| package:pub/src/log.dart 409 progress
| package:pub/src/solver/version_solver.dart 39 resolveVersions
| package:pub/src/global_packages.dart 166 GlobalPackages._installInCache
| package:pub/src/global_packages.dart 116 GlobalPackages.activateHosted
| package:pub/src/command/global_activate.dart 91 GlobalActivateCommand.run
| package:args/command_runner.dart 194 CommandRunner.runCommand
| package:pub/src/command_runner.dart 168 PubCommandRunner.runCommand.<fn>
| dart:async new Future.sync
| package:pub/src/utils.dart 99 captureErrors.<fn>
| package:stack_trace Chain.capture
| package:pub/src/utils.dart 114 captureErrors
| package:pub/src/command_runner.dart 168 PubCommandRunner.runCommand
| package:pub/src/command_runner.dart 117 PubCommandRunner.run
| /tmp/tmp5krbLf/dart-1.24.0-dev.6.4/dart/third_party/pkg/pub/bin/pub.dart 8 main
| ===== asynchronous gap ===========================
| dart:async _Completer.completeError
| package:pub/src/source/hosted.dart 152 BoundHostedSource.doGetVersions
| ===== asynchronous gap ===========================
| dart:async _asyncErrorWrapperHelper
| package:pub/src/source/hosted.dart 128 BoundHostedSource.doGetVersions
| package:pub/src/source.dart 165 BoundSource.getVersions
| package:pub/src/solver/version_solver.dart 230 SolverCache.getVersions.<fn>
| package:pub/src/http.dart 227 withDependencyType
| package:pub/src/solver/version_solver.dart 229 SolverCache.getVersions
| ===== asynchronous gap ===========================
| dart:async new Future.microtask
| package:pub/src/solver/version_solver.dart 203 SolverCache.getVersions
| package:pub/src/solver/unselected_package_queue.dart 121 UnselectedPackageQueue._getNumVersions
| ===== asynchronous gap ===========================
| dart:async new Future.microtask
| package:pub/src/solver/unselected_package_queue.dart 115 UnselectedPackageQueue._getNumVersions
| package:pub/src/solver/unselected_package_queue.dart 50 UnselectedPackageQueue.add
| ===== asynchronous gap ===========================
| dart:async new Future.microtask
| package:pub/src/solver/unselected_package_queue.dart 44 UnselectedPackageQueue.add
| package:pub/src/solver/version_selection.dart 68 VersionSelection.select.<fn>
| ===== asynchronous gap ===========================
| dart:async new Future.microtask
| package:pub/src/solver/version_selection.dart 61 VersionSelection.select.<fn>
| dart:async Future.forEach
| package:pub/src/solver/version_selection.dart 61 VersionSelection.select
| ===== asynchronous gap ===========================
| dart:async Future.forEach
| package:pub/src/solver/version_selection.dart 61 VersionSelection.select
| ===== asynchronous gap ===========================
| dart:async _asyncThenWrapperHelper
| package:pub/src/solver/version_selection.dart 53 VersionSelection.select
| package:pub/src/solver/backtracking_solver.dart 308 BacktrackingSolver._solve.<fn>
| ===== asynchronous gap ===========================
| dart:async _asyncThenWrapperHelper
| package:pub/src/solver/backtracking_solver.dart 276 BacktrackingSolver._solve.<fn>
| dart:async Future.doWhile
| package:pub/src/solver/backtracking_solver.dart 276 BacktrackingSolver._solve
| ===== asynchronous gap ===========================
| dart:async Future.doWhile
| package:pub/src/solver/backtracking_solver.dart 276 BacktrackingSolver._solve
| ===== asynchronous gap ===========================
| dart:async new Future.microtask
| package:pub/src/solver/backtracking_solver.dart 274 BacktrackingSolver._solve
| package:pub/src/solver/backtracking_solver.dart 176 BacktrackingSolver.solve
| ===== asynchronous gap ===========================
| dart:async _asyncThenWrapperHelper
| package:pub/src/solver/backtracking_solver.dart 157 BacktrackingSolver.solve
| package:pub/src/solver/version_solver.dart 41 resolveVersions.<fn>
| package:pub/src/log.dart 409 progress
| package:pub/src/solver/version_solver.dart 39 resolveVersions
| package:pub/src/global_packages.dart 166 GlobalPackages._installInCache
| ===== asynchronous gap ===========================
| dart:async new Future.microtask
| package:pub/src/global_packages.dart 160 GlobalPackages._installInCache
| package:pub/src/global_packages.dart 116 GlobalPackages.activateHosted
| ===== asynchronous gap ===========================
| dart:async new Future.microtask
| package:pub/src/global_packages.dart 114 GlobalPackages.activateHosted
| package:pub/src/command/global_activate.dart 91 GlobalActivateCommand.run
| package:args/command_runner.dart 194 CommandRunner.runCommand
| ===== asynchronous gap ===========================
| dart:async new Future.microtask
| package:args/command_runner.dart 142 CommandRunner.runCommand
| package:pub/src/command_runner.dart 168 PubCommandRunner.runCommand.<fn>
| dart:async new Future.sync
| package:pub/src/utils.dart 99 captureErrors.<fn>
| package:stack_trace Chain.capture
| package:pub/src/utils.dart 114 captureErrors
| package:pub/src/command_runner.dart 168 PubCommandRunner.runCommand
IO : Get versions from https://pub.dartlang.org/api/packages/pub_semver.
FINE: HTTP GET https://pub.dartlang.org/api/packages/pub_semver
| Accept: application/vnd.pub.v2+json
| X-Pub-OS: linux
| X-Pub-Command: global activate
| X-Pub-Session-ID: 55613A99-D375-47A9-9088-AAB0A68A7438
| user-agent: Dart pub 1.24.0-dev.6.4
FINE: HTTP response 200 OK for GET https://pub.dartlang.org/api/packages/pub_semver
| took 0:00:00.280514
| date: Sat, 03 Jun 2017 19:24:31 GMT
| transfer-encoding: chunked
| via: 1.1 google
| content-type: application/json
| x-frame-options: SAMEORIGIN
| x-xss-protection: 1; mode=block
| x-content-type-options: nosniff
| server: nginx
IO : Get versions from https://pub.dartlang.org/api/packages/safe_config.
FINE: HTTP GET https://pub.dartlang.org/api/packages/safe_config
| Accept: application/vnd.pub.v2+json
| X-Pub-OS: linux
| X-Pub-Command: global activate
| X-Pub-Session-ID: 55613A99-D375-47A9-9088-AAB0A68A7438
| user-agent: Dart pub 1.24.0-dev.6.4
FINE: HTTP response 200 OK for GET https://pub.dartlang.org/api/packages/safe_config
| took 0:00:00.157651
| date: Sat, 03 Jun 2017 19:24:31 GMT
| transfer-encoding: chunked
| via: 1.1 google
| content-type: application/json
| x-frame-options: SAMEORIGIN
| x-xss-protection: 1; mode=block
| x-content-type-options: nosniff
| server: nginx
after that it got stuck.
Don't really know what to do with this information tbh.

Related

FormatException: Unexpected character (at character 7)

I'm getting this error. How to resolve this.
FormatException: Unexpected character (at character 7)
public static final int right_side = 0x7f050036;
flutter pub get
Running "flutter pub get" in shayari_card...
Failed to decode data using encoding 'utf-8', path = '.\pubspec.lock'
---- Log transcript ----
FINE: Pub 2.8.4
IO : Spawning "cmd /c ver" in C:\Users\Mahender\Desktop\FlutterApps\shayari_card\.
IO : Finished ver. Exit code 0.
| stdout:
| |
| | Microsoft Windows [Version 6.1.7601]
| Nothing output on stderr.
MSG : Resolving dependencies...
ERR : Failed to decode data using encoding 'utf-8', path = '.\pubspec.lock'
FINE: Exception type: FileSystemException
FINE: dart:io _File.readAsStringSync
| package:pub/src/io.dart 152:48 readTextFile
| package:pub/src/lock_file.dart 82:38 new LockFile.load
| package:pub/src/entrypoint.dart 96:28 Entrypoint.lockFile
| package:pub/src/entrypoint.dart 222:19 Entrypoint.acquireDependencies.<fn>
| package:pub/src/log.dart 394:18 progress
| package:pub/src/entrypoint.dart 216:24 Entrypoint.acquireDependencies
| package:pub/src/command/get.dart 46:23 GetCommand.run
| package:args/command_runner.dart 197:27 CommandRunner.runCommand
| package:pub/src/command_runner.dart 191:39 PubCommandRunner.runCommand.<fn>
| dart:async new Future.sync
| package:pub/src/utils.dart 113:12 captureErrors.wrappedCallback
| package:stack_trace Chain.capture
| package:pub/src/utils.dart 126:11 captureErrors
| package:pub/src/command_runner.dart 191:13 PubCommandRunner.runCommand
| ===== asynchronous gap ===========================
| dart:async Future.catchError
| package:pub/src/utils.dart 113:52 captureErrors.wrappedCallback
| package:stack_trace Chain.capture
| package:pub/src/utils.dart 126:11 captureErrors
| package:pub/src/command_runner.dart 191:13 PubCommandRunner.runCommand
| dart:async _completeOnAsyncReturn
| package:pub/src/command_runner.dart PubCommandRunner._validatePlatform
| dart:async _completeOnAsyncReturn
| package:pub/src/io.dart runProcess.<fn>
---- End log transcript ----
pub get failed (66; ---- End log transcript ----)
exit code 66

Get previous days' value in column in postgres

I have a question.
I have a sql command that is getting the moving average for each day using window functions.
BEGIN;
DROP TABLE IF EXISTS vol_stats;
SELECT pk as fk,
avg(CAST(volume as FLOAT)) over (partition by account_id order by "endts") as average,
INTO vol_stats
from volume_temp
order by account_id, "endts";
COMMIT;
I would like to get one more value and that is the previous days' value.
The data structure looks like this.
acccount_id | value | timestamp
-------------------------------
a12 | 122 | jan 1
a13 | 133 | jan 1
a14 | 443 | jan 1
a12 | 251 | jan 2
a13 | 122 | jan 2
a14 | 331 | jan 2
a12 | 412 | jan 3
a13 | 323 | jan 3
a14 | 432 | jan 3
and we are computing this
acccount_id | value | timestamp | Average
-----------------------------------------
a12 | 122 | jan 1 | 122
a13 | 133 | jan 1 | 133
a14 | 443 | jan 1 | 443
a12 | 251 | jan 2 | 188.5
a13 | 122 | jan 2 | 222.5
a14 | 331 | jan 2 | 387
a12 | 412 | jan 3 | 261.6
a13 | 323 | jan 3 | 192.6
a14 | 432 | jan 3 | 402
What would be helpful would be to grab the previous days' value as well. Like this.
acccount_id | value | timestamp | Average | previous
-----------------------------------------
a12 | 122 | jan 1 | 122 | null
a13 | 133 | jan 1 | 133 | null
a14 | 443 | jan 1 | 443 | null
a12 | 251 | jan 2 | 188.5 | 122
a13 | 122 | jan 2 | 222.5 | 133
a14 | 331 | jan 2 | 387 | 443
a12 | 412 | jan 3 | 261.6 | 251
a13 | 323 | jan 3 | 192.6 | 122
a14 | 432 | jan 3 | 402 | 331
Just add another column to the SELECT list:
lag(volume) OVER (PARTITION BY account_id ORDER BY endts)

Getting an average of each column from CSV

I am trying to get the average of all the columns in CSV with respect to timestamp. The object type is system.array. Whenever I try to convert the integer it is showing an error.
timestamp streams TRP A B C D
6/4/2019 6775 305 56 229 132 764
6/4/2019 6910 316 28 356 118 134
6/4/2019 6749 316 54 218 206 144
6/5/2019 5186 267 84 280 452 258
6/5/2019 5187 240 33 436 455 245
6/5/2019 5224 291 21 245 192 654
6/6/2019 5254 343 42 636 403 789
6/6/2019 5180 252 23 169 328 888
6/6/2019 5181 290 32 788 129 745
6/6/2019 5244 328 44 540 403 989
I got help from Lee_Dailey on the below code, I was trying to produce the average of each column based on timestamp. I get an error
Cannot convert value " " to type "System.Int32".
Error: "Index was outside the bounds of the array."
+ ... l = [Math]::Round(($GIS_Item.Group.$TPL_Item.ForEach({[int]$_}) | Mea ...
+ ~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvalidCastFromStringToInteger
$InStuff = Import-Csv 'M:\MyDoc\script\logfiles\Output_18Mar\streams_E1WAF2_OUTPUT.csv'
$TargetPropertyList = $InStuff[0].PSObject.Properties.Name.Where({$_ - ne 'TimeStamp'})
$GroupedInStuff = $InStuff | Group-Object -Property TimeStamp
$Results = foreach ($GIS_Item in $GroupedInStuff) {
$HighestValues = [ordered]#{
TimeStamp = $GIS_Item.Name
}
foreach ($TPL_Item in $TargetPropertyList) {
$TempHiVal = [Math]::Round(($GIS_Item.Group.$TPL_Item.ForEach({[int]$_}) | Measure-Object -Average).Average)
$HighestValues.Add($TPL_Item, $TempHiVal)
}
[PSCustomObject]$HighestValues
}
$Results = $Results | Sort-Object -Property {[DateTime]$_.TimeStamp}
here's a way to deal with the somewhat damaged CSV file you presented in the new data set. [grin] it reads the file in as plain text, removes the spaces, and trims the final |.
i was wondering if having only one date in a grouping was a problem, so i added a final line to the data set that has a different date.
# fake reading in a defective CSV file as plain text
# in real life, use Get-Content
$InStuff = #'
timestamp|abc | A | B | C | D | E | F | G |
6/4/2019 |6775 | 3059 | 4 | 2292 | 1328 | 764 | 0 | 0 |
6/4/2019 |6910 | 3167 | 28 | 3568 | 1180 | 1348 | 0 | 0 |
6/4/2019 |6749 | 3161 | 0 | 2180 | 2060 | 1440 | 0 | 28 |
6/5/2019 |6738 | 3118 | 4 | 2736 | 1396 | 984 | 0 | 0 |
6/5/2019 |6718 | 3130 | 12 | 3076 | 1008 | 452 | 0 | 4 |
6/5/2019 |6894 | 3046 | 4 | 2284 | 1556 | 624 | 0 | 0 |
1/1/2021 |1111 | 2222 | 3 | 4444 | 5555 | 666 | 7 | 8 |
'# -split [System.Environment]::NewLine
$CleanedInStuff = $InStuff.ForEach({$_.Replace(' ', '').Trim('|')}) |
ConvertFrom-Csv -Delimiter '|'
$TargetPropertyList = $CleanedInStuff[0].PSObject.Properties.Name.
Where({
$_ -ne 'TimeStamp'
})
$GroupedCIS = $CleanedInStuff |
Group-Object -Property TimeStamp
$Results = foreach ($GCIS_Item in $GroupedCIS) {
$TempObject = [ordered]#{
TimeStamp = $GCIS_Item.Name
}
foreach ($TPL_Item in $TargetPropertyList) {
$TempAveValue = [Math]::Round(($GCIS_Item.Group.$TPL_Item.
ForEach({[int]$_}) |
Measure-Object -Average).Average, 2)
$TempObject.Add($TPL_Item, $TempAveValue)
}
[PSCustomObject]$TempObject
}
$Results = $Results |
Sort-Object -Property {
[DateTime]$_.TimeStamp
}
$Results
output ...
TimeStamp : 6/4/2019
abc : 6811.33
A : 3129
B : 10.67
C : 2680
D : 1522.67
E : 1184
F : 0
G : 9.33
TimeStamp : 6/5/2019
abc : 6783.33
A : 3098
B : 6.67
C : 2698.67
D : 1320
E : 686.67
F : 0
G : 1.33
TimeStamp : 1/1/2021
abc : 1111
A : 2222
B : 3
C : 4444
D : 5555
E : 666
F : 7
G : 8
There is probably a nicer way to do this that Lee will surely advise, but this is how I would complete the task. This will group the objects by the Timestamp property and then you can average them there. I recommend playing around with $csv | Group-Object timestamp and see what you can do with it.
$csv = import-csv C:\temp\test.csv
$Averages = New-Object System.Collections.ArrayList
Foreach($object in ($csv | Group-Object timestamp)) {
$Averages.Add([pscustomobject]#{
timestamp = $object.Name
abc = ($object.group | Select-Object -ExpandProperty abc | Measure-Object -Average).Average
a = ($object.group | Select-Object -ExpandProperty a | Measure-Object -Average).Average
b = ($object.group | Select-Object -ExpandProperty b | Measure-Object -Average).Average
c = ($object.group | Select-Object -ExpandProperty c | Measure-Object -Average).Average
d = ($object.group | Select-Object -ExpandProperty d | Measure-Object -Average).Average
e = ($object.group | Select-Object -ExpandProperty e | Measure-Object -Average).Average
f = ($object.group | Select-Object -ExpandProperty f | Measure-Object -Average).Average
g = ($object.group | Select-Object -ExpandProperty g | Measure-Object -Average).Average
})
}
Output:
PS H:\> $Averages
timestamp : 6/4/2019
abc : 6811.33333333333
a : 3129
b : 10.6666666666667
c : 2680
d : 1522.66666666667
e : 1184
f : 0
g : 9.33333333333333
timestamp : 6/5/2019
abc : 6783.33333333333
a : 3098
b : 6.66666666666667
c : 2698.66666666667
d : 1320
e : 686.666666666667
f : 0
g : 1.33333333333333
The ConvertFrom-SourceTable cmdlet I created is actually supposed to read fixed width column tables but there isn't any reason why it shouldn't be able to also read delimited (or distorted) tables. So this question has encouraged me to create an update which no longer produces errors when this happens.
Converting the table in the question
$Table = '
timestamp streams TRP A B C D
6/4/2019 6775 305 56 229 132 764
6/4/2019 6910 316 28 356 118 134
6/4/2019 6749 316 54 218 206 144
6/5/2019 5186 267 84 280 452 258
6/5/2019 5187 240 33 436 455 245
6/5/2019 5224 291 21 245 192 654
6/6/2019 5254 343 42 636 403 789
6/6/2019 5180 252 23 169 328 888
6/6/2019 5181 290 32 788 129 745
6/6/2019 5244 328 44 540 403 989
'
# Raw Table
ConvertFrom-SourceTable $Table | Format-Table
timestamp streams TRP A B C D
--------- ------- --- - - - -
6/4/2019 6775 305 56 229 132 764
6/4/2019 6910 316 28 356 118 134
6/4/2019 6749 316 54 218 206 144
6/5/2019 5186 267 84 280 452 258
6/5/2019 5187 240 33 436 455 245
6/5/2019 5224 291 21 245 192 654
6/6/2019 5254 343 42 636 403 789
6/6/2019 5180 252 23 169 328 888
6/6/2019 5181 290 32 788 129 745
6/6/2019 5244 328 44 540 403 989
#Streamed rows from pipeline:
$Table -split [System.Environment]::NewLine | ConvertFrom-SourceTable | Format-Table
timestamp streams TRP A B C D
--------- ------- --- - - - -
6/4/2019 6775 305 56 229 132 764
6/4/2019 6910 316 28 356 118 134
6/4/2019 6749 316 54 218 206 144
6/5/2019 5186 267 84 280 452 258
6/5/2019 5187 240 33 436 455 245
6/5/2019 5224 291 21 245 192 654
6/6/2019 5254 343 42 636 403 789
6/6/2019 5180 252 23 169 328 888
6/6/2019 5181 290 32 788 129 745
6/6/2019 5244 328 44 540 403 989
Fixed width column table with vertical rulers
$Table = '
| date | abc | A | B | C | D | E | F | G |
| 6/4/2019 | 6775 | 3059 | 4 | 2292 | 1328 | 764 | 0 | 0 |
| 6/4/2019 | 6910 | 3167 | 28 | 3568 | 1180 | 1348 | 0 | 0 |
| 6/4/2019 | 6749 | 3161 | 0 | 2180 | 2060 | 1440 | 0 | 28 |
| 6/5/2019 | 6738 | 3118 | 4 | 2736 | 1396 | 984 | 0 | 0 |
| 6/5/2019 | 6718 | 3130 | 12 | 3076 | 1008 | 452 | 0 | 4 |
| 6/5/2019 | 6894 | 3046 | 4 | 2284 | 1556 | 624 | 0 | 0 |
| 1/1/2021 | 1111 | 2222 | 3 | 4444 | 5555 | 666 | 7 | 8 |
'
# Raw Table
ConvertFrom-SourceTable $Table | Format-Table
date abc A B C D E F G
---- --- - - - - - - -
6/4/2019 6775 3059 4 2292 1328 764 0 0
6/4/2019 6910 3167 28 3568 1180 1348 0 0
6/4/2019 6749 3161 0 2180 2060 1440 0 28
6/5/2019 6738 3118 4 2736 1396 984 0 0
6/5/2019 6718 3130 12 3076 1008 452 0 4
6/5/2019 6894 3046 4 2284 1556 624 0 0
1/1/2021 1111 2222 3 4444 5555 666 7 8
#Streamed rows from pipeline:
$Table -split [System.Environment]::NewLine | ConvertFrom-SourceTable | Format-Table
date abc A B C D E F G
---- --- - - - - - - -
6/4/2019 6775 3059 4 2292 1328 764 0 0
6/4/2019 6910 3167 28 3568 1180 1348 0 0
6/4/2019 6749 3161 0 2180 2060 1440 0 28
6/5/2019 6738 3118 4 2736 1396 984 0 0
6/5/2019 6718 3130 12 3076 1008 452 0 4
6/5/2019 6894 3046 4 2284 1556 624 0 0
1/1/2021 1111 2222 3 4444 5555 666 7 8
Note the type casting (table alignment) in the results, meaning that the result is symmetrical:
$Result = $Table | ConvertFrom-SourceTable | Format-Table
$Result | Format-Table <=> $Result | ConvertFrom-SourceTable | Format-Table
Distorted table
$Table = '
timestamp|abc | A | B | C | D | E | F | G |
6/4/2019 |6775 | 3059 | 4 | 2292 | 1328 | 764 | 0 | 0 |
6/4/2019 |6910 | 3167 | 28 | 3568 | 1180 | 1348 | 0 | 0 |
6/4/2019 |6749 | 3161 | 0 | 2180 | 2060 | 1440 | 0 | 28 |
6/5/2019 |6738 | 3118 | 4 | 2736 | 1396 | 984 | 0 | 0 |
6/5/2019 |6718 | 3130 | 12 | 3076 | 1008 | 452 | 0 | 4 |
6/5/2019 |6894 | 3046 | 4 | 2284 | 1556 | 624 | 0 | 0 |
1/1/2021 |1111 | 2222 | 3 | 4444 | 5555 | 666 | 7 | 8 |
'
# Raw Table
ConvertFrom-SourceTable $Table | Format-Table
timestamp abc A B C D E F G
--------- --- - - - - - - -
6/4/2019 6775 3059 4 2292 1328 764 0 0
6/4/2019 6910 3167 28 3568 1180 1348 0 0
6/4/2019 6749 3161 0 2180 2060 1440 0 28
6/5/2019 6738 3118 4 2736 1396 984 0 0
6/5/2019 6718 3130 12 3076 1008 452 0 4
6/5/2019 6894 3046 4 2284 1556 624 0 0
1/1/2021 1111 2222 3 4444 5555 666 7 8
#Streamed rows from pipeline:
$Table -split [System.Environment]::NewLine | ConvertFrom-SourceTable | Format-Table
timestamp abc A B C D E F G
--------- --- - - - - - - -
6/4/2019 6775 3059 4 2292 1328 764 0 0
6/4/2019 6910 3167 28 3568 1180 1348 0 0
6/4/2019 6749 3161 0 2180 2060 1440 0 28
6/5/2019 6738 3118 4 2736 1396 984 0 0
6/5/2019 6718 3130 12 3076 1008 452 0 4
6/5/2019 6894 3046 4 2284 1556 624 0 0
1/1/2021 1111 2222 3 4444 5555 666 7 8
Note that distorted rows will always result in a literal (string) conversion (no type casting)

Difference between periods in crosstabs, Jaspersoft Studio

I'm working with Jaspersoft Studio.
I've a crosstab similar to this one:
+---------+------+------+
| FRUIT | 2014 | 2015 |
+---------+------+------+
| apples | 12 | 85 |
+---------+------+------+
| peaches | 74 | 36 |
+---------+------+------+
| bananas | 54 | 82 |
+---------+------+------+
and I would like to obtain something like this:
+---------+------+------+---------------------+
| FRUIT | 2014 | 2015 | Difference |
| | | | between 2015/2014 |
| | | | (delta) |
+---------+------+------+---------------------+
| apples | 12 | 85 | 73 |
+---------+------+------+---------------------+
| peaches | 74 | 36 | -38 |
+---------+------+------+---------------------+
| bananas | 54 | 82 | 28 |
+---------+------+------+---------------------+
Is it possible?
I mean, it's there a way to intercetpt the value of a field in the single period (e.g. 2014) and use it for a custom calculation?

Divison with more than one result from postgresql query

I am using postgresql and I have a table called accidents (state, total accidents) and another table called population. I want to get the top 3 state names with high total accidents and then get the population of those 3 states divided by total accidents in postgresql? How to write the query in the following way?
Explanation:
Population Table
rank| state | population
---+-----------------------------+------------
1 | Uttar Pradesh | 199581477
2 | Maharashtra | 112372972
3 | Bihar | 103804630
4 | West Bengal | 91347736
5 | Madhya Pradesh | 72597565
6 | Tamil Nadu | 72138958
7 | Rajasthan | 68621012
8 | Karnataka | 61130704
9 | Gujarat | 60383628
10 | Andhra Pradesh | 49665533
11 | Odisha | 41947358
12 | Telangana | 35193978
13 | Kerala | 33387677
14 | Jharkhand | 32966238
15 | Assam | 31169272
16 | Punjab | 27704236
17 | Haryana | 25753081
18 | Chhattisgarh | 25540196
19 | Jammu and Kashmir | 12548926
20 | Uttarakhand | 10116752
21 | Himachal Pradesh | 6856509
22 | Tripura | 3671032
23 | Meghalaya | 2964007
24 | Manipur*β* | 2721756
25 | Nagaland | 1980602
26 | Goa | 1457723
27 | Arunachal Pradesh | 1382611
28 | Mizoram | 1091014
29 | Sikkim | 607688
30 | Delhi | 16753235
31 | Puducherry | 1244464
32 | Chandigarh | 1054686
33 | Andaman and Nicobar Islands | 379944
34 | Dadra and Nagar Haveli | 342853
35 | Daman and Diu | 242911
36 | Lakshadweep | 64429
accident table:
state | eqto8 | eqto10 | mrthn10 | ntknwn | total
-----------------------------+-------+--------+---------+--------+--------
Andhra Pradesh | 6425 | 8657 | 8144 | 19298 | 42524
Arunachal Pradesh | 88 | 76 | 87 | 0 | 251
Assam | 0 | 0 | 0 | 6535 | 6535
Bihar | 2660 | 3938 | 3722 | 0 | 10320
Chhattisgarh | 2888 | 7052 | 3571 | 0 | 13511
Goa | 616 | 1512 | 2184 | 0 | 4312
Gujarat | 4864 | 7864 | 7132 | 8089 | 27949
Haryana | 3365 | 2588 | 4112 | 0 | 10065
Himachal Pradesh | 276 | 626 | 977 | 1020 | 2899
Jammu and Kashmir | 1557 | 618 | 434 | 4100 | 6709
Jharkhand | 1128 | 701 | 1037 | 2845 | 5711
Karnataka | 11167 | 14715 | 18566 | 0 | 44448
Kerala | 5580 | 13271 | 17323 | 0 | 36174
Madhya Pradesh | 15630 | 16226 | 19354 | 0 | 51210
Maharashtra | 4117 | 5350 | 10538 | 46311 | 66316
Manipur | 147 | 453 | 171 | 0 | 771
Meghalaya | 210 | 154 | 119 | 0 | 483
Mizoram | 27 | 58 | 25 | 0 | 110
Nagaland | 11 | 13 | 18 | 0 | 42
Odisha | 1881 | 3120 | 4284 | 0 | 9285
Punjab | 1378 | 2231 | 1825 | 907 | 6341
Rajasthan | 5534 | 5895 | 5475 | 6065 | 22969
Sikkim | 6 | 144 | 8 | 0 | 158
Tamil Nadu | 8424 | 18826 | 29871 | 10636 | 67757
Tripura | 290 | 376 | 222 | 0 | 888
Uttarakhand | 318 | 305 | 456 | 393 | 1472
Uttar Pradesh | 8520 | 10457 | 10995 | 0 | 29972
West Bengal | 1494 | 1311 | 974 | 8511 | 12290
Andaman and Nicobar Islands | 18 | 104 | 114 | 0 | 236
Chandigarh | 112 | 39 | 210 | 58 | 419
Dadra and Nagar Haveli | 40 | 20 | 17 | 8 | 85
Daman and Diu | 11 | 6 | 8 | 25 | 50
Delhi | 0 | 0 | 0 | 6937 | 6937
Lakshadweep | 0 | 0 | 0 | 3 | 3
Puducherry | 154 | 668 | 359 | 0 | 1181
All India | 88936 | 127374 | 152332 | 121741 | 490383
So that result should be
21.57
81.03
107.44
explanation:
Highest accidents states Tamilnadu, Maharashtra, Madhyapradesh.
Tamilnadu population/accidents = 21213/983 = 21.57 (Assumed values)
Maharasthra population/accidents = 10000/123 = 81.03
Madhyapradesh population/accidents = 34812/324 = 107.44
My query is:
SELECT POPULATION/
(SELECT TOTAL
FROM accidents
WHERE STATE NOT LIKE 'All %'
ORDER BY TOTAL DESC
LIMIT 3)
aVG FROM population
WHERE STATE IN
(SELECT STATE
FROM accidents
WHERE STATE NOT LIKE 'All %'
ORDER BY TOTAL DESC
LIMIT 3);
throwing ERROR: more than one row returned by a subquery used as an expression.
How to modify the query to get the required result or any other way to get the result in postgresql?
This ought to do it.
SELECT a.state, population.population/a.total FROM
(SELECT total, state FROM accidents WHERE state <> 'All India' ORDER BY total DESC LIMIT 3 ) AS a
INNER JOIN population on a.state = population.state