i want to get the sound dB when I am talking. If the sound dB is high enough, the record function will run, so how can i get the sound dB? many thanks
If you are using AVAudioPlayer, then, I think you can use the below to return the following values in dB's:
double peakPower =[audioPlayer peakPowerForChannel:0];
double avgPower = [audioPlayer averagePowerForChannel:0];
Related
Lets assume that I have an input DataStream and want to implement some functionality that requires "memory" so I need ProcessFunction that gives me access to state. Is it possible to do it straight to the DataStream or the only way is to keyBy the initial stream and work in keyed-context?
I'm thinking that one solution would be to keyBy the stream with a hardcoded unique key so the whole input stream ends up in the same group. Then technically I have a KeyedStream and I can normally use keyed state, like I'm showing below with keyBy(x->1). But is this a good solution?
DataStream<Integer> inputStream = env.fromSource(...)
DataStream<Integer> outputStream = inputStream
.keyBy(x -> 1)
.process(...) //I've got acess to state heree
As I understand that's not a common usecase because the main purpose of flink is to partition the stream, process them seperately and then merge the results. In my scenario thats exactly what I'm doing, but the problem is that the merge step requires state to produce the final "global" result. What I actually want to do is something like this:
DataStream<Integer> inputStream = env.fromElements(1,2,3,4,5,6,7,8,9)
//two groups: group1=[1,2,3,4] & group2=[5,6,7,8,9]
DataStream<Integer> partialResult = inputStream
.keyBy(val -> val/5)
.process(<..stateful processing..>)
//Can't do statefull processing here because partialResult is not a KeyedStream
DataStream<Integer> outputStream = partialResult
.process(<..statefull processing..>)
outputStream.print();
But Flink doesnt seem to allow me do the final "merge partial results operation" because I can't get access to state in process function as partialResult is not a KeyedStream.
I'm beginner to flink so I hope what I'm writing makes sense.
In general I can say that I haven't found a good way to do the "merging" step, especially when it comes to complex logic.
Hope someone can give me some info, tips or correct me if I'm missing something
Thank you for your time
Is "keyBy the stream with a hardcoded unique key" a good idea? Well, normally no, since it forces all data to flow through a single sub-task, so you get no benefit from the full parallelism in your Flink cluster.
If you want to get a global result (e.g. the "best" 3 results, from any results generated in the preceding step) then yes, you'll have to run all records through a single sub-task. So you could have a fixed key value, and use a global window. But note (as the docs state) you need to come up with some kind of "trigger condition", otherwise with a streaming workflow you never know when you really have the best N results, and thus you'd never emit any final result.
I am doing some tests on the FIX engine sample of FXCM. The complete code is available here.
There is a function void FixApplication::SubscribeMarketData() that allow to continuously receive update of a particular symbol of the Market. Here is what it look like :
// Subscribes to the EUR/USD trading security
void FixApplication::SubscribeMarketData()
{
// Subscribe to market data for EUR/USD
string request_ID = "EUR_USD_Request_";
FIX44::MarketDataRequest request;
request.setField(MDReqID(request_ID));
request.setField(SubscriptionRequestType(
SubscriptionRequestType_SNAPSHOT_PLUS_UPDATES));
request.setField(MarketDepth(0));
request.setField(NoRelatedSym(1));
// Add the NoRelatedSym group to the request with Symbol
// field set to EUR/USD
FIX44::MarketDataRequest::NoRelatedSym symbols_group;
symbols_group.setField(Symbol("EUR/USD"));
request.addGroup(symbols_group);
// Add the NoMDEntryTypes group to the request for each MDEntryType
// that we are subscribing to. This includes Bid, Offer, High, and Low
FIX44::MarketDataRequest::NoMDEntryTypes entry_types;
entry_types.setField(MDEntryType(MDEntryType_BID));
request.addGroup(entry_types);
entry_types.setField(MDEntryType(MDEntryType_OFFER));
request.addGroup(entry_types);
entry_types.setField(MDEntryType(MDEntryType_TRADING_SESSION_HIGH_PRICE));
request.addGroup(entry_types);
entry_types.setField(MDEntryType(MDEntryType_TRADING_SESSION_LOW_PRICE));
request.addGroup(entry_types);
Session::sendToTarget(request, sessionID(true));
}
Is there a way to tell the FIX server that I only want to receive updates every 5min ?
Or should I implement a function that catch the continuous flow of data and output a data every 5 min?
I already tried to search for a parameter in the FIX engine that I could modify to return a T periodic flow of data but I didn't find anything. If it exist I prefer to use it rather than create a function to handle the ticks flow.
The feature you are suggesting would be have to be a counterparty-specific feature implemented with probably custom fields. I don't believe the standard FIX dictionary provides fields that would support this.
So, yes, your hypothetical client-side solution would be the way to go.
(I'm new here so please excuse the probably not perfectly formulated question)
I've got a problem when running the run_model() method from the ModelChain class. I want to have the option to choose between hourly data resolution and 15-minute weather data resolution. Using hourly data, the calculation works fine and delivers reasonable results. When using 15-minute resolution, an AttributeError: 'numpy.float64' object has no attribute 'exp'' comes up in the 'sapm_celltemp' function. Everything else is kept unchanged tho.
I use the CEC module and inverter database
These are the PVSystem and ModelChain parameters that I chose for the calculation:
**PVSystem:**
surface_tilt=15
surface_azimuth=183
albedo=None
surface_type='sea'
module=''
module_parameters=
cec_modules
['CSUN_Eurasia_Energy_Systems_Industry_and_Trade_CSUN325_72P']
modules_per_string=18
strings_per_inverter=4
inverter=''
inverter_parameters=
cec_inverters['Fronius_USA__Fronius_Symo_20_0_3_480_480V__CEC_2015_']
racking_model='open_rack_cell_glassback'
losses_parameters=None
**ModelChain**
system=PVSystem
location=Location
orientation_strategy=None
clearsky_model='ineichen'
transposition_model='haydavies'
solar_position_model='nrel_numpy'
airmass_model='kastenyoung1989'
dc_model='cec'
ac_model=None
aoi_model='physical'
spectral_model='no_loss'
temp_model='sapm'
losses_model='no_loss'
Does anyone have a similar problem or knows what could cause the error?
Thanks in advance
Cheers, Felix
I'm trying to get CPU usage data with WMI. For this purpose I'm using the Win32_PerfRawData_PerfProc_Process class. When I run below code, I do not get any result.
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2","SELECT * FROM Win32_PerfRawData_PerfProc_Process");
var data = searcher.Get();
Until here there is no any error, if I try to use data object, app waiting until I close it.
I made some research, but found nothing useful.
NOTE: Other WMI class queries work fine. And I need to use WMI (not performance counters).
Please take a look at registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\PerfProc\Performance and here the value of "Disable Performance Counters". It should be set to "0" for this Class to work.
I am trying to think through how to implement a countdown on a stamina level. For example, maximum 100% and over time it decreases. I don't need to know how to display it but the technology behind it to get it working and where to look.
This countdown would keep on going down when the application is closed.
I was looking at NSUserDefaults as a means to do this. Is this correct?
Similar to the top bar as shown below:
You can save latest refueled stamina value in NSUserDefaults or in iCloud and calculate current value using something like this:
timePassedInSeconds = currentTime - latestMaxValueSaveTime;
newStamina = latestMaxValue - (timePassedInSeconds * decreasePerSecond);
This way each time the player refuels stamina (e.g. buys some food for animal) you reset stamina to 100% (or add some percentage depending on food type) and save this value into latestMaxValue and save the time it was refueled into latestMaxValueSaveTime (you can store both in NSUserDefaults)
And you calculate newStamina in update: of the scene or in onEnter: method of the scene if it needs to be calculated once.
This way it will decrease even when the app is closed.
However, if you want to avoid players resetting stamina by changing device time you should get time from the server (preferably in UTC, to avoid issues with timezones and daylight saving).