QML test fails in Qt 5.9.1 - c++

While compiling in Qt 5.9.1 version it is not working.. Any one help me to compile this TestCase in qml..
import QtQuick 2.0
import QtTest 1.1
TestCase{
function test_math() {
compare(2 + 2, 4, "2 + 2 = 4")
}
function test_fail() {
compare(2 + 2, 5, "2 + 2 = 5")
}
}
Getting error like this:
Type TestCase unavailable and module Qt.test.qtestroot is not installed

Related

How can the rxjs 6 webSocket function be mocked for unit tests?

I am trying to unit test some code that uses the webSocket function from rxjs6. I have tried to spy on the webSocket function by doing the following (as recommended here): -
import * as rxJsWebSocket from 'rxjs/webSocket';
subject = new Subject();
webSocketSpy = spyOn(rxJsWebSocket, 'webSocket').and.returnValue(<any>subject);
but I got the error: -
Error: <spyOn> : webSocket is not declared writable or has no setter
Is there any other way to achieve this or is there a workaround for the error?
I've also tried ts-mock-imports with no success.
It works for me using "rxjs": "^6.6.3". E.g.
index.ts:
import { webSocket } from 'rxjs/webSocket';
export function main() {
return webSocket('ws://localhost:8081');
}
index.test.ts:
import { main } from './';
import * as rxJsWebSocket from 'rxjs/webSocket';
import { Subject } from 'rxjs/internal/Subject';
describe('55415481', () => {
it('should pass', () => {
const subject = new Subject();
const webSocketSpy = spyOn(rxJsWebSocket, 'webSocket').and.returnValue(<any>subject);
const actual = main();
expect(actual).toBe(<any>subject);
expect(webSocketSpy).toHaveBeenCalledWith('ws://localhost:8081');
});
});
unit test result:
Executing 1 defined specs...
Running in random order... (seed: 21376)
Test Suites & Specs:
(node:74151) ExperimentalWarning: The fs.promises API is experimental
1. 55415481
✔ should pass (8ms)
>> Done!
Summary:
👊 Passed
Suites: 1 of 1
Specs: 1 of 1
Expects: 2 (0 failures)
Finished in 0.02 seconds
source code: https://github.com/mrdulin/jasmine-examples/tree/master/src/stackoverflow/55415481

How to display the time and date of the RTC library DS1302 in a tkinter window using a Raspberry Pi

I'm new I have a doubt. I use the library RTC_DS1302 to obtain the PC time and store it in the RTC DS1302 using a Raspberry Pi. My question is how to show the time and date in a tkinter window and to update it every time the time and date change, I have not been able to do this. I leave the code with which I get the time and date. In this link you can find the library.
https://github.com/ksaye/IoTDemonstrations/blob/master/RTC_DS1302/RTC_DS1302.py
This is the code
import RTC_DS1302
import os
import time
ThisRTC = RTC_DS1302.RTC_DS1302()
Data = ThisRTC.ReadRAM()
print("Message: " + Data)
DateTime = { "Year":0, "Month":0, "Day":0, "DayOfWeek":0, "Hour":0, "Minute":0, "Second":0 }
Data = ThisRTC.ReadDateTime(DateTime)
print("Date/Time: " + Data)
print("Year: " + format(DateTime["Year"] + 2000, "04d"))
print("Month: " + format(DateTime["Month"], "02d"))
print("Day: " + format(DateTime["Day"], "02d"))
print("DayOfWeek: " + ThisRTC.DOW[DateTime["DayOfWeek"]])
print("Hour: " + format(DateTime["Hour"], "02d"))
print("Minute: " + format(DateTime["Minute"], "02d"))
print("Second: " + format(DateTime["Second"], "02d"))
ThisRTC.CloseGPIO()
tkinter has function after(time_in_ms, function_name) which let you run function with delay. In this function you can update text in Labels and execute after(time_in_ms, function_name)so it will run the same function after some time.
Example which use after() to display current time
import tkinter as tk # Python 3.x
from datetime import datetime
def update_time():
# update displayed time
current_time = datetime.now()
current_time_str = current_time.strftime('%Y.%m.%d %H:%M:%S')
label['text'] = current_time_str
# run update_time again after 1000ms (1s)
root.after(1000, update_time)
# --- main ---
root = tk.Tk()
label = tk.Label(root)
label.pack()
update_time()
root.mainloop()
More of my examples with after()

Build problems with CodenameOneCameraKit.cn1lib

I am trying to run the demo program for the CodenameOne CameraKit:
https://github.com/codenameone/CameraKitDemo/ after reading
https://www.codenameone.com/blog/camerakit-low-level-camera-api.html
It compiles and runs in the simulator, but when I send it to the server to build, it gives me a build error.
Am I missing something?
I am using the IntelliJ IDE:
IntelliJ IDEA 2018.1.1 (Community Edition)
Build #IC-181.4445.78, built on April 9, 2018
JRE: 1.8.0_152-release-1136-b27 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.13.3
Latest Codename One plugin
Here follows the code, and the errors from the build server.
enter code here
package com.test;
import static com.codename1.ui.CN.*;
import com.codename1.camerakit.CameraEvent;
import com.codename1.camerakit.CameraKit;
import com.codename1.camerakit.CameraListener;
import com.codename1.components.FloatingActionButton;
import com.codename1.components.SpanLabel;
import com.codename1.components.ToastBar;
import com.codename1.ui.*;
import com.codename1.ui.layouts.BorderLayout;
import com.codename1.ui.layouts.LayeredLayout;
import com.codename1.ui.plaf.UIManager;
import com.codename1.ui.util.Resources;
import com.codename1.io.Log;
import java.io.IOException;
import com.codename1.ui.layouts.BoxLayout;
import com.codename1.io.NetworkEvent;
/**
* This file was generated by Codename One for the purpose
* of building native mobile applications using Java.
*/
public class CameraDemo3 {
private Form current;
private Resources theme;
private CameraKit ck;
public void init(Object context) {
ck = CameraKit.create();
// use two network threads instead of one
updateNetworkThreadCount(2);
theme = UIManager.initFirstTheme("/theme");
// Enable Toolbar on all Forms by default
Toolbar.setGlobalToolbar(true);
// Pro only feature
Log.bindCrashProtection(true);
addNetworkErrorListener(err -> {
// prevent the event from propagating
err.consume();
if(err.getError() != null) {
Log.e(err.getError());
}
Log.sendLogAsync();
Dialog.show("Connection Error", "There was a networking error in the connection to " + err.getConnectionRequest().getUrl(), "OK", null);
});
}
public void start() {
if(ck != null && !ck.isStarted()) {
ck.start();
}
if(current != null){
current.show();
return;
}
Form hi = new Form("Native Camera", new LayeredLayout());
hi.setScrollableY(false);
if(ck != null) {
ck.addCameraListener(new CameraListener() {
#Override
public void onError(CameraEvent ev) {
// We currently get some errors on Android
Log.p(ev.getMessage() + " : " + ev.getExceptionMessage());
}
#Override
public void onImage(CameraEvent ev) {
ToastBar.showInfoMessage("Captured image bytes");
}
#Override
public void onVideo(CameraEvent ev) {
ToastBar.showInfoMessage("Captured video: " + ev.getFile());
}
});
hi.add(ck.getView());
Button video = new Button();
FontImage.setMaterialIcon(video, FontImage.MATERIAL_VIDEOCAM);
video.addActionListener(e -> {
Boolean b = (Boolean)video.getClientProperty("capturing");
if(b == null) {
video.putClientProperty("capturing", Boolean.TRUE);
ck.captureVideo();
FontImage.setMaterialIcon(video, FontImage.MATERIAL_VIDEOCAM_OFF);
} else {
video.putClientProperty("capturing", null);
ck.stopVideo();
FontImage.setMaterialIcon(video, FontImage.MATERIAL_VIDEOCAM);
}
});
FloatingActionButton fab = FloatingActionButton.createFAB(FontImage.MATERIAL_CAMERA);
fab.bindFabToContainer(hi, CENTER, BOTTOM);
fab.addActionListener(e -> ck.captureImage());
Button toggleCamera = new Button();
FontImage.setMaterialIcon(toggleCamera, FontImage.MATERIAL_CAMERA_FRONT);
Button toggleFlash = new Button();
FontImage.setMaterialIcon(toggleFlash, FontImage.MATERIAL_FLASH_ON);
toggleCamera.addActionListener(e -> ck.toggleFacing());
toggleFlash.addActionListener(e -> ck.toggleFlash());
Container buttons = BoxLayout.encloseY(video, toggleCamera, toggleFlash);
buttons.setScrollableY(true);
hi.add(BorderLayout.east(buttons));
} else {
hi.add(BorderLayout.north(new SpanLabel("Loading native camera view")));
}
hi.show();
}
public void stop() {
current = getCurrentForm();
if(current instanceof Dialog) {
((Dialog)current).dispose();
current = getCurrentForm();
}
}
public void destroy() {
}
}
Build Server output:
User-level: 1000
Request Args:
-----------------
java.version=8
ios.NSCameraUsageDescription=We need camera access to grab pictures and videos
ios.newStorageLocation=true
-------------------
Executing: /home/ec2-user/android-sdk/tools/android create project --target android-23 --name CameraDemo3 --path /tmp/build9109673224646903413xxx/CameraDemo3 --activity CameraDemo3Stub --package com.test --gradle --gradle-version 2.0.0 Created directory /tmp/build9109673224646903413xxx/CameraDemo3/src/main/java
Created directory /tmp/build9109673224646903413xxx/CameraDemo3/src/main/java/com/test
...... cut to reduce length .....
Compiling with JDK Java compiler API.
/tmp/build9109673224646903413xxx/CameraDemo3/src/main/java/com/codename1/camerakit/impl/CameraNativeAccessImpl.java:3: error: package com.wonderkiln.camerakit does not exist
import com.wonderkiln.camerakit.*;
^
/tmp/build9109673224646903413xxx/CameraDemo3/src/main/java/com/codename1/camerakit/impl/CameraNativeAccessImpl.java:9: error: cannot find symbol
private CameraView view;
^
symbol: class CameraView
location: class CameraNativeAccessImpl
/tmp/build9109673224646903413xxx/CameraDemo3/src/main/java/com/codename1/camerakit/impl/CameraNativeAccessImpl.java:10: error: cannot find symbol
private CameraKitEventListener listener = new CameraKitEventListener() {
^
symbol: class CameraKitEventListener
location: class CameraNativeAccessImpl
/tmp/build9109673224646903413xxx/CameraDemo3/src/main/java/com/codename1/camerakit/impl/CameraNativeAccessImpl.java:10: error: cannot find symbol
private CameraKitEventListener listener = new CameraKitEventListener() {
^
symbol: class CameraKitEventListener
location: class CameraNativeAccessImpl
/tmp/build9109673224646903413xxx/CameraDemo3/src/main/java/com/codename1/camerakit/impl/CameraNativeAccessImpl.java:35: error: cannot find symbol
view = new CameraView(AndroidNativeUtil.getContext());
^
symbol: class CameraView
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
5 errors
:compileDebugJavaWithJavac FAILED
:compileDebugJavaWithJavac (Thread[Daemon worker,5,main]) completed. Took 7.792 secs.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --debug option to get more log output.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':compileDebugJavaWithJavac'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:203)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:185)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:66)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:50)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:25)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:110)
at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23)
at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43)
at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30)
at org.gradle.initialization.DefaultGradleLauncher$4.run(DefaultGradleLauncher.java:154)
at org.gradle.internal.Factories$1.create(Factories.java:22)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:52)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:151)
at org.gradle.initialization.DefaultGradleLauncher.access$200(DefaultGradleLauncher.java:32)
at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:99)
at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:93)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:62)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:93)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:82)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:94)
at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:43)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:28)
at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:75)
at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:45)
at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:52)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:37)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
at org.gradle.util.Swapper.swap(Swapper.java:38)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.health.DaemonHealthTracker.execute(DaemonHealthTracker.java:40)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:66)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:72)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.health.HintGCAfterBuild.execute(HintGCAfterBuild.java:41)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:246)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
Caused by: org.gradle.api.internal.tasks.compile.CompilationFailedException: Compilation failed; see the compiler error output for details.
at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:47)
at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:33)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:103)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:52)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:38)
at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:34)
at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:25)
at org.gradle.api.internal.tasks.compile.incremental.IncrementalCompilationFinalizer.execute(IncrementalCompilationFinalizer.java:38)
at org.gradle.api.internal.tasks.compile.incremental.IncrementalCompilationFinalizer.execute(IncrementalCompilationFinalizer.java:24)
at org.gradle.api.tasks.compile.JavaCompile.performCompilation(JavaCompile.java:157)
at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:127)
at com.android.build.gradle.tasks.factory.AndroidJavaCompile.compile(AndroidJavaCompile.java:49)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.doExecute(AnnotationProcessingTaskFactory.java:244)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:220)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.execute(AnnotationProcessingTaskFactory.java:231)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:209)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
... 68 more
BUILD FAILED
Total time: 18.103 secs
Stopped 0 compiler daemon(s).
Received result Failure[value=org.gradle.initialization.ReportedException: org.gradle.internal.exceptions.LocationAwareException: Execution failed for task ':compileDebugJavaWithJavac'.] from daemon DaemonInfo{pid=11167, address=[46019278-8ed8-4606-8f74-3c03030b4a25 port:44179, addresses:[/0:0:0:0:0:0:0:1%lo, /127.0.0.1]], idle=false, context=DefaultDaemonContext[uid=1240b5d8-39f4-4710-ac85-f3cf1a99af7f,javaHome=/home/ec2-user/jdk1.8.0_45,daemonRegistryDir=/home/ec2-user/.gradle/daemon,pid=11167,idleTimeout=120000,daemonOpts=-XX:MaxPermSize=512m,-XX:+HeapDumpOnOutOfMemoryError,-Xmx2048m,-Dfile.encoding=UTF-8,-Duser.country=US,-Duser.language=en,-Duser.variant]} (build should be done).
Process return code is 1
It looks like you took the cn1lib and tried to use the code instead of installing the cn1lib using the extension manager available in Codename One Settings.
I would suggest installing the extension.
If you would still want to use the code notice you also need to replicate the changes to build hints which are missing. These are within the properties files that are a part of the cn1lib.

"Ambiguous use of prefix" compiler error with Swift 3

I just migrated my project from Swift 2.2 to Swift 3.0 with Xcode 8 beta.
I have something similar to the following code (you can paste this into a playground):
import Foundation
let datesWithCount: [(Date, Int)] = [(Date(), 1), (Date(), 2), (Date(), 3)]
let dates: [Date] = datesWithCount.sorted {
$0.0 < $1.0
}.prefix(1).map {
return $0.0
}
In Swift 2.2 this compiled fine. However, with Swift 3.0 I get the error
Ambiguous use of 'prefix'
The only way to get this to compile in Swift 3.0 is to split out the map into a separate line:
let sortedDatesWithCount = datesWithCount.sorted {
$0.0 < $1.0
}.prefix(1)
let mappedDates = sortedDatesWithCount.map {
return $0.0
}
BTW, in the actual code I'm returning NSNotification objects from the map not Dates but the error is the same. I just used Date here for making the example simple.
Is there any way to get this to compile as a one liner?
UPDATE: Created a JIRA for the Swift project.
It works if you make the ArraySlice into an Array before passing it to map:
let dates: [Date] = Array(datesWithCount.sorted {
$0.0 < $1.0
}.prefix(1)).map { return $0.0 }
This looks like a type inference bug in the compiler.

Octave library - 'MeanPeakHeight' invalid parameter

I would like to do a peak detection of a .wav file signal in Python with Octave library on a Raspberry pi 3 with Raspbian but there is a problem with the octave.findpeaks function. I had this error:findpeaks : argument 'MeanPeakHeight' did not match any valid parameter of the parser
I have installed all the packages concerning Octave so this is why i don't understand.
This is a part of my program :
import matplotlib.pyplot as plt
import numpy as np
from scipy.io import wavfile as wav
from scipy.signal import find_peaks_cwt, butter, lfilter
from pylab import *
import os
from operator import truediv
from easygui import *
from oct2py import octave
"High and Low Frequency for the filter"
low = 100
high = 50
list_file = []
octave.eval("pkg load signal")
def display_wav(wav_file):
samplerate, beat = wav.read('/home/pi/heartbeat_project/heartbeat_songs/%s' %wav_file)
beat_resize = np.fromfile(open('/home/pi/heartbeat_project/heartbeat_songs/%s' %wav_file),np.int16)[4*samplerate:float(beat.shape[0])-4*samplerate]
beat_resize = beat_resize / (2.**15)
timeArray = arange(0,float(beat_resize.shape[0]),1)
timeArray = timeArray / samplerate
ylow = butter_lowpass_filter(samplerate, 5, low, beat_resize)
y = butter_highpass_filter(samplerate, 5, high, ylow)
peaks, indexes = octave.findpeaks(np.array(y),'DoubleSided','MeanPeakHeight',np.std(y))
findpeaks is part of the octave-forge signal package:source file
This function doesn't have a 'MeanPeakHeight' parameter. Is guess this is a typo and you want 'MinPeakHeight'