Posts

Showing posts with the label function

Is using function in transformation causing Not Serializable exceptions?

Is using function in transformation causing Not Serializable exceptions? I have a Breeze DenseMatrix , i find mean per row and mean of squares per row and put them in another DenseMatrix , one per column. But i get Task Not Serializable exception. I know that sc is not Serializable but i think that the exception is because i call functions in a transformation in Safe Zones. Breeze DenseMatrix mean mean DenseMatrix Task Not Serializable sc Serializable Am i right? And how could be a possible way to be done without any functions? Any help would be great! Code: object MotitorDetection { case class MonDetect() extends Serializable { var sc: SparkContext = _ var machines: Int=0 var counters: Int=0 var GlobalVec= BDM.zeros[Double](counters, 2) def findMean(a: BDM[Double]): BDV[Double] = { var c = mean(a(*, ::)) c} def toMatrix(x: BDV[Double], y: BDV[Double], C: Int): BDM[Double]={ val m = BDM.zeros[Double](C,2) m(::, 0) := x m(::, 1) := y m} def SafeZones(stream: DStream[(In...

MySql function returns null everytime

MySql function returns null everytime I have the following function: (The SQL query works perfectly) CREATE FUNCTION get_participantes (pid INT) RETURNS varchar(255) DETERMINISTIC BEGIN DECLARE par varchar(255); SET par = (SELECT GROUP_CONCAT(mail SEPARATOR ',') FROM users WHERE id IN ( SELECT user_id FROM meeting_participants WHERE meeting_id = pid)); RETURN par; END And I'm trying to get the return of that function in the following procedure: CREATE PROCEDURE google_calendar (p1 varchar(50), p2 INT, p3 varchar(50), p4 varchar(50), p5 varchar(50), p6 varchar(50), p7 varchar(50), p8 varchar(50)) BEGIN DECLARE parti VARCHAR(255); SET @parti = get_participantes(p2); SELECT COALESCE(@parti,"nullpart") INTO @par2; SET @cmd = CONCAT('curl "http://*****:80**/meetings/api/" --data-urlencode "id=',p1,'" --data-urlencode "participants=',@par2,'" --data-urlencode "age...

How to combine functions in a plot in R

How to combine functions in a plot in R This is my code so far: Basically, I want x^2[0;10] & 6[11, infinity] random <- function(x){ if (any(x <= 10 )) { return (x**2)} else if (any(x > 10 )){ return(6) } } Unfortunately, R uses only the first part of the function when I try to plot or integrate it. Thanks for your help! 1 Answer 1 Your error is because of the use of the "any" function. any(x <= 10) will always be true as long as a single value in x is less than ten, e.g. it'll be true for [1, 2, 10, 15, 30]. Because of this, this function never reaches the second if statement. What you actually want to do is map this function. First, remove the "any" calls in your function. Then pass in your function (labelled here as "random") into a map function. A map function is a dynamic function, one that takes in a function and a list of obj...

Function to behave differently on class vs on instance

Function to behave differently on class vs on instance I'd like a particular function to be callable as a classmethod, and to behave differently when it's called on an instance. For example, if I have a class Thing , I want Thing.get_other_thing() to work, but also thing = Thing(); thing.get_other_thing() to behave differently. class Thing Thing.get_other_thing() thing = Thing(); thing.get_other_thing() I think overwriting the get_other_thing method on initialization should work (see below), but that seems a bit hacky. Is there a better way? get_other_thing class Thing: def __init__(self): self.get_other_thing = self._get_other_thing_inst() @classmethod def get_other_thing(cls): # do something... def _get_other_thing_inst(self): # do something else Isn't this what we use inheritance for. Define a separate class with your new method - which inherits from parent class, then by scope, instance will return ...

Extrapolating value from function to a for loop and passing it back to the function

Extrapolating value from function to a for loop and passing it back to the function function Test() a = 2; b = 1; c = 0.5; q = 0.001; r = 10; function F = Useful(x) %calculates existing values for x with size 11 eq1 = (1*(0.903*x(2))^(-1))-(0.903*x(1)); eq2 = (1*(0.665*x(3))*(0.903*x(2))^(-1))-0.903*x(4); eq3 = (1*(0.399*x(5))*(0.903*x(2)))-0.665*x(6); eq4 = (1*(0.399*x(5))*(0.903*x(2))^2)-0.903*x(7); eq5 = (1*(0.399*x(5))*(0.903*x(2))^3)-1*x(8); eq6 = (1*(0.665*x(3))*(0.399*x(5))*(0.903*x(2)))-1*x(9); eq7 = (1*(0.665*x(3))*(0.399*x(5))*(0.903*x(2))^2)-0.903*x(10); eq8 = (1*(0.665*x(3))*(0.399*x(5)))-0.903*x(11); eq9 = x(3)+x(4)+x(9)+x(10)+x(11)-a; eq10 = x(5)+x(6)+x(7)+x(8)+x(9)+x(10)+x(11)-b; eq11 = x(2)+x(6)+2*x(7)+3*x(8)+x(9)+2*x(10)-x(1)-x(4)-c; F = [eq1;eq2;eq3;eq4;eq5;eq6;eq7;eq8; eq9; eq10; eq11]; end Value(1,1) = 0; for d = 2:100 x = fsolve(@Useful,x0,options); %Produces the x(1) to x(11) values Value(1,d) = (x(3)+x(5))*d+Value(1,d-1); %Gives a new value after eac...

Time function that checks for certain days

Time function that checks for certain days I have the following time function that I use to output if the business is open or closed. The way I have it coded works fine for normal business weeks. What I am wanting to do is program it for holidays, such as Christmas, 4th of July, etc that are always on the same day, so the output shows we are closed. How would I program in the fixed holidays? function timeNow() { //Get time var d = new Date(), h = ('0' + d.getHours()).slice(-2), m = ('0' + d.getMinutes()).slice(-2); //Get Day new Date().getDay(); var day = new Date().getDay(); console.log(day); var operateDay = ''; if (day >= 1 && day <= 5) { operateDay = true; } else if (day < 1 || day > 5) { operateDay = false; } // Checking time range var operatingTime = ((h >= 8 && h < 17) || (h === 8 && m == 0)); var closedTime = (h >= 17 || h <= 8); ...

name : function(){} or function name (){} | ReactJS

name : function(){} or function name (){} | ReactJS I am new to ReactJS and as I am learning I noticed that there's a few ways to declare functions such as, MyFunc : function(){ /// } or function MyFunc(){ /// } I was wondering which one shall i use and why? Those two are not interchangeable the way you posted them. In context where first works the second won't, and vice versa. – dfsq Jun 29 at 11:08 The first one is a syntax error, the second isn't ?! – Jonas W. Jun 29 at 11:08 It's not a react specific – The Reason Jun 29 at 11:08 ...

Pyrhon 3 file sharing variable

Pyrhon 3 file sharing variable I want to import a var from another python file. This first file runs on the side of file2 on a second window. File1.py def onlinecheckext(): global onlinecheckvarr while 1: try: onlinecheckscc = pyautogui.locateOnScreen(imPath("start_detect.png")) if onlinecheckscc is None: logging.debug("I am Online") onlinecheckvarr = True time.sleep(2) else: logging.debug("I am not online") onlinecheckvarr = False time.sleep(2) except: logging.debug("Online check fail") return False File2.py from file1 import onlinecheckvarr while onlinecheckvarr is True: print("TEST") else: print("Test2") Error : NameError: name 'onlinecheckvarr' is not defined. I have try almost everything and still didn't get it, it's a global var and i imported it right i think but it still throws...

React Native setState not a function

React Native setState not a function Can someone explain me why this.setState is not a function ? I do not see why my code has an error import React from 'react'; import axios from 'axios' import { StyleSheet, Text, View , Image} from 'react-native'; export default class App extends React.Component { constructor(){ super(); this.state = {res: } } componentDidMount() { axios.get('https://api.github.com/repos/torvalds/linux/commits') .then(function (response) { this.setState({res: response}); }).catch(function (error) { console.log(error); }); } } Thank you use arrow function to wrap this.setState({res: response}); that bring this inside arrow function – Pramendra Gupta Jun 29 at 9:51 this.setState({...

How can i pass an array to a function so that the original array's value does not change if i change the array's values in that function?

How can i pass an array to a function so that the original array's value does not change if i change the array's values in that function? using namespace std; #include<iostream> int passarr(int b,int s) { //Some Modification in the array b b[0]=0; b[s-1]=0; //Printing the array b for(int i=0;i<s;i++) { cout<<b[i]<<" "; } cout<<endl; } int main() { int arr[100]; int n; cin>>n; for(int i=0;i<n;i++) { cin>>arr[i]; } //Function call and passing array a to the function` passarr(arr,n); //Printing the array arr for(int i=0;i<n;i++) { cout<<arr[i]<<" "; } } In this code, I have passed array arr to function passarr() which performs some modifications. The problem is that modifications reflect on the original array too. Is there any way to pass the array to a function so that the original array does not get ...

angular - call function from different typescript file

angular - call function from different typescript file I am facing issue whiling calling a function/method from another typescript file. I have read through many articles and found using service it can be done easily so here I am with my code but it is not working. It is not throwing any error but not giving any results too. trigger.html <button (click) = "openToast();" type="button" class="btn btn-primary btn-block"> Open Toast </button> trigger.ts import { Component, OnInit } from '@angular/core'; import { MessageService } from '../message.service'; @Component({ selector: 'app-trigger', templateUrl: './trigger.component.html', styleUrls: ['./trigger.component.scss'], providers: [MessageService] }) export class TriggerComponent implements OnInit { constructor(private _messageService: MessageService) { } ngOnInit() { } openToast(){ this._messageService.callToastr(); } } message.ser...