Laravel Http client - laravel

Could someone help me regarding Laravel Http client. I have this endpoint
http://projects.knmi.nl/klimatologie/uurgegevens/getdata_uur.cgi?stns=240&vars=RH&start=2020071500&end=2020072200 which store in $result variable. my problem is when I tried to dump ($result->body()) I don't know how to get the data excluding all the labels starting with '#'. Thanks
sample return data:
# BRON: KONINKLIJK NEDERLANDS METEOROLOGISCH INSTITUUT (KNMI)
# Opmerking: door stationsverplaatsingen en veranderingen in waarneemmethodieken zijn deze tijdreeksen van uurwaarden mogelijk inhomogeen! Dat betekent dat deze reeks van gemeten waarden niet geschikt is voor trendanalyse. Voor studies naar klimaatverandering verwijzen we naar de gehomogeniseerde reeks maandtemperaturen van De Bilt <http://www.knmi.nl/klimatologie/onderzoeksgegevens/homogeen_260/index.html> of de Centraal Nederland Temperatuur <http://www.knmi.nl/klimatologie/onderzoeksgegevens/CNT/>.
#
#
# STN LON(east) LAT(north) ALT(m) NAME
# 240: 4.790 52.318 -3.30 SCHIPHOL
#
# YYYYMMDD = datum (YYYY=jaar,MM=maand,DD=dag);
# HH = tijd (HH=uur, UT.12 UT=13 MET, 14 MEZT. Uurvak 05 loopt van 04.00 UT tot 5.00 UT;
# RH = Uursom van de neerslag (in 0.1 mm) (-1 voor <0.05 mm);
#
# STN,YYYYMMDD, HH, RH
#
240,20200715, 24, 0
240,20200716, 24, 0
240,20200717, 24, 0
240,20200718, 24, 0
240,20200719, 24, 0
240,20200720, 24, 0
240,20200721, 24, 0
Codes
$result = Http::get('http://projects.knmi.nl/klimatologie/uurgegevens/getdata_uur.cgi?stns=240&vars=RH&start=2020071500&end=2020072200');
dd($result->body());

Related

How to convert image to text in codeignter

Hii ijust want to ask that how can i convert a image to text using OCR ?
if(isset($_FILES['image'])){
$file_name = $_FILES['image']['name'];
$file_tmp =$_FILES['image']['tmp_name'];
move_uploaded_file($file_tmp,"image/".$file_name);
echo "<h3>Image Upload Success</h3>";
echo '<img src="'.$file_name.'" style="width:70%">';
shell_exec('"C:\\Program Files\\Tesseract-OCR\\tesseract" "D:\\xampp\\htdocs\\ci3\\image\\'.$file_name.'" out');
echo "<br><h3>OCR after reading</h3><br><pre>";
$myfile = fopen("out.txt", "r") or die("Unable to open file!");
echo fread($myfile,4045);
fclose($myfile);
echo "</pre>";
}
I just write this code but it is like not convert the image text properly so is their any solution so please let me know !!
I Expecting that its work i vertical image to read the text but in my output it read like.........
The Registration Directorate at the Ministry of Industry, Commerce and Tourism
certifies that the merchant's below details have been registered in accordance with
Decree law No. (27) for the year 2015 of the Commercial Registration.
22/04/2023 GliaiuY! ~,6 Registration 22/04/2007
Date
eroup HORIZON TELECOM SERVICES COMPANY WLL
Name
Commercial
Name
Registration
Type
CR
Status
HORIZON TELECOM SERVICES COMPANY WLL
With Limited Liability Company
ACTIVE
Area 4élaicl!
ABU SAYBA/ a2 5!
P.O.BOX #.ye Road & »b
7325
Block asx
473
Commercial
Address
Activities
Sale and installation of telecommunications equipment and parts
ere! Bylo!
Registration Directorate
QF. 409 Issue 0
* This CR does not permit its holder to practice investment activities on behalf of others.
igiwltzads
(alka,
KINGDOM OF BAHRAIN pues.
Ministry of Industry, ©
Commerce and Tourism R
Solenitl J) 15 bol gd
Commercial Registration Certificate
ell ad oi hath dala yb yleill s Ae licall 8 51} 52 apsaill 6 pla) agts
GSM Dasa GLE; 2015 Aid (27) aby cy silds p pes pall Cady alld g oLisi atltly Aba uell
Judll 6 Registration == 4908 - 1
aad CYL) Glesal 6 5 jl st 4S 8 Ac gore! pul
aed VLA) Las) Oy jolt ASS ole usd
Ba gdare Aud gious IS AS ph andl ¢ 93
dads aud Le
Flat/Shop No. J=«/4a4
11
Building +
608 Gola ol gual
Woke abby SYLSIYI Glace af jlo
wsdl Ul gal pletion! LU 49) jo: 4ualial jin Y all lhe *
Issued Date: 20/04/2022 Page 1 of 1
}
Z/
Please post this certificate at a visible place.
Tel: +973 80001700 - www. sijilat.bh - www.moic.gov.bh
boat! S12 Sol GIS Bolg S! che 5 oe
but i need a seprate column to read a proper text formate

how get only specific fields from elsticsearch

i have elasticsearch indice i have filed name "titile":Rolex i want to write DSL to save
ratemax,ratemin fields as variable
can this be done here is my sample json
"vente": [
"62402c696a271a7d0ceeef2f"
],
"status": [
0
]
},
"ignored_field_values": {
"description.keyword": [
"ROLEX \nPRINCE BRANCARD \"EATON QUARTER CENTURY CLUB\" \nVERS 1930 \nMontre bracelet en or jaune 14K sur cuir. \nBOITIER : rectangulaire curvex cintré en or jaune 14K (belle oxydation de l'or). Fond gravé d'une dédicace: \"Presented to Fred Peartree to mark a quarter century of continuous service with the T. Eaton, 1916-1941.\" \nCADRAN : duodial, argenté deux tons, personnalisé Eaton, inscrit \"1/4 Century Club\" à la place des index. Aiguilles en acier bleui. \nMOUVEMENT: mécanique, certifié chronometre, Ultra-Prima. \nBRACELET : cuir avec boucle ardillon en or Rolex. \nBoîtier et mouvement signés Rolex. \nNumérotée 53207. \nDIM. 42 x 24 mm. \n \nCette montre fait partie d'une série personnalisée par un industriel canadien nommé Eaton. Cet entrepreneur avait l'habitude d'en faire cadeau à ses employés pour les remercier de leur fidélité. \nA 14K gold manual winding wristwatch by Rolex from the 30's."
]
}
}

Removing categories with patsy and statsmodels

I am using statsmodels and patsy for building a logistic regression model. I'll use pseudocode here. Let's assume I have a dataframe containing a categorical variable, say Country, with 200 levels. I have reasons to believe some of them would be predictive, so I build a model as in
formula = 'outcome ~ C(Country)'
patsy splits Country into its levels and the model is build using all countries. I then see that the coefficient in GB is high so I want to remove only GB. Can I do something like this in patsy:
formula = 'outcome ~ C(country) - C(country)[GB]'
I tried and it did not change anything.
I don't know if there is a way to subset a Category with patsy formula, but you can do it in the DataFrame.
For example
import numpy as np
import pandas as pd
import statsmodels.api as sm
# sample data
size = 100
np.random.seed(1)
countries = ['IT', 'UK', 'US', 'FR', 'ES']
df = pd.DataFrame({
'outcome': np.random.random(size),
'Country': np.random.choice(countries, size)
})
df['Country'] = df.Country.astype('category')
print(df.Country)
0 ES
1 IT
2 UK
3 US
4 UK
..
95 FR
96 UK
97 ES
98 UK
99 US
Name: Country, Length: 100, dtype: category
Categories (5, object): ['ES', 'FR', 'IT', 'UK', 'US']
Let us suppose we want to remove Category "US"
# create a deep copy excluding 'US'
_df = df[df.Country!='US'].copy(deep=True)
print(_df.Country)
0 ES
1 IT
2 UK
4 UK
5 ES
..
94 UK
95 FR
96 UK
97 ES
98 UK
Name: Country, Length: 83, dtype: category
Categories (5, object): ['ES', 'FR', 'IT', 'UK', 'US']
Even if there are no more elements with category "US" in the DataFrame, the category is still there. If we use this DataFrame in a statsmodels model, we'd get a singular matrix error, so we need to remove unused categories
# remove unused category 'US'
_df['Country'] = _df.Country.cat.remove_unused_categories()
print(_df.Country)
0 ES
1 IT
2 UK
4 UK
5 ES
..
94 UK
95 FR
96 UK
97 ES
98 UK
Name: Country, Length: 83, dtype: category
Categories (4, object): ['ES', 'FR', 'IT', 'UK']
and now we can fit a model
mod = sm.Logit.from_formula('outcome ~ Country', data=_df)
fit = mod.fit()
print(fit.summary())
Optimization terminated successfully.
Current function value: 0.684054
Iterations 4
Logit Regression Results
==============================================================================
Dep. Variable: outcome No. Observations: 83
Model: Logit Df Residuals: 79
Method: MLE Df Model: 3
Date: Sun, 16 May 2021 Pseudo R-squ.: 0.01179
Time: 22:43:37 Log-Likelihood: -56.776
converged: True LL-Null: -57.454
Covariance Type: nonrobust LLR p-value: 0.7160
=================================================================================
coef std err z P>|z| [0.025 0.975]
---------------------------------------------------------------------------------
Intercept -0.1493 0.438 -0.341 0.733 -1.007 0.708
Country[T.FR] 0.4129 0.614 0.673 0.501 -0.790 1.616
Country[T.IT] -0.1223 0.607 -0.201 0.840 -1.312 1.068
Country[T.UK] 0.1027 0.653 0.157 0.875 -1.178 1.383
=================================================================================

Getting a number of context switches for a process / thread

Out of curiosity I want to know how many times my program was context switched by the OS. Like all the registers were saved and the control was passed to another process or thread, and then after some time everything was restored and we continue as it never happened.
Does the system maintain such a number somewhere or is there a sort of hack or whatever?
I am on Linux in particular but I am interested about other systems as well.
Well, let's examine the case. Linux type O/S keeps these details systematically and one may use a comfort of Python, for both inspecting the state and also for easy design of a monitoring system, that can report any excessive circumstances ( the former quite matching a just out of curiosity cases, the latter quite handy for any re-work / re-use for systematic work ) :
A "Monitor" example for both { voluntary | involuntary }-Ctx Switching :
Python here serves for both the educational role and for the ease and comfort of further extending the scope of functionalities:
Having assigned signal.signal( signal.SIGALRM, SIG_ALRM_handler_A ) and the timing, the system gets ready to report both voluntary and involuntary ( enforced ) Context-Switches, for which a "FAT"-blocking piece of computing was used, that resorts, due to historical reasons to non-GIL Numpy/C/FORTRAN code and thus gets disturbed by just involuntary-CtxSwitched cases, as was shown below:
len(str([np.math.factorial(2**f) for f in range(20)][-1]))
but by using a principally any other PID-number, this trivial monitoring mechanics can serve for whatever other purposes:
########################################################################
### SIGALRM_handler_
###
import psutil, resource, os, time
SIG_ALRM_last_ctx_switch_VOLUNTARY = -1
SIG_ALRM_last_ctx_switch_FORCED = -1
def SIG_ALRM_handler_A( aSigNUM, aFrame ): # SIG_ALRM fired evenly even during [ np.math.factorial( 2**f ) for f in range( 20 ) ] C-based processing =======================================
# onEntry_ROTATE_SigHandlers() -- MAY set another sub-sampled SIG_ALRM_handler_B() ... { last: 0, 0: handler_A, 1: handler_B, 2: handler_C }
#
# onEntry_SEQ of calls of regular, hierarchically timed MONITORS ( just the SNAPSHOT-DATA ACQUISITION Code-SPRINTs, handle later due to possible TimeDOMAIN overlaps )
#
#
# print( time.ctime() )
# print( formatExtMemoryUsed( getExtMemoryUsed() ) )
# print( 60 * "=", psutil.Process( os.getpid() ).num_ctx_switches(), "~~~", aProcess.cpu_percent( interval = 0 ) )
# ??? # WHY CPU 0.0%
aProcess = psutil.Process( os.getpid() )
aProcessCpuPCT = aProcess.cpu_percent( interval = 0 ) # EVENLY-TIME-STEPPED
aCtxSwitchNUMs = aProcess.num_ctx_switches() # THIS PROCESS ( may inspect other per-incident later ... on anomaly )
aVolCtxSwitchCNT = aCtxSwitchNUMs.voluntary
aForcedSwitchCNT = aCtxSwitchNUMs.involuntary
global SIG_ALRM_last_ctx_switch_VOLUNTARY
global SIG_ALRM_last_ctx_switch_FORCED
if ( SIG_ALRM_last_ctx_switch_VOLUNTARY != -1 ): # .INIT VALUE STILL UNCHANGED
#----------
# .ON_TICK: must process delta(s)
if ( SIG_ALRM_last_ctx_switch_VOLUNTARY == aVolCtxSwitchCNT ):
#
# AN INDIRECT INDICATION OF A LONG-RUNNING WORKLOAD OUTSIDE GIL-STEPPING ( regex / C-lib / FORTRAN / numpy-block et al )
# ||||| vvv
# SIG_: Wed Oct 19 12:24:32 2016 ------------------------------ pctxsw(voluntary=48714, involuntary=315) ~~~ 0.0
# SIG_: Wed Oct 19 12:24:37 2016 ------------------------------ pctxsw(voluntary=48714, involuntary=323) ~~~ 0.0
# SIG_: Wed Oct 19 12:24:42 2016 ------------------------------ pctxsw(voluntary=48714, involuntary=331) ~~~ 0.0
# SIG_: Wed Oct 19 12:24:47 2016 ------------------------------ pctxsw(voluntary=48714, involuntary=338) ~~~ 0.0
# SIG_: Wed Oct 19 12:24:52 2016 ------------------------------ pctxsw(voluntary=48714, involuntary=346) ~~~ 0.0
# SIG_: Wed Oct 19 12:24:57 2016 ------------------------------ pctxsw(voluntary=48714, involuntary=353) ~~~ 0.0
# ... ||||| ^^^
# 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000]
# >>> ||||| |||
# vvvvv |||
# SIG_: Wed Oct 19 12:26:17 2016 ------------------------------ pctxsw(voluntary=49983, involuntary=502) ~~~ 0.0
# SIG_: Wed Oct 19 12:26:22 2016 ------------------------------ pctxsw(voluntary=49984, involuntary=502) ~~~ 0.0
# SIG_: Wed Oct 19 12:26:27 2016 ------------------------------ pctxsw(voluntary=49985, involuntary=502) ~~~ 0.0
# SIG_: Wed Oct 19 12:26:32 2016 ------------------------------ pctxsw(voluntary=49986, involuntary=502) ~~~ 0.0
# SIG_: Wed Oct 19 12:26:37 2016 ------------------------------ pctxsw(voluntary=49987, involuntary=502) ~~~ 0.0
# SIG_: Wed Oct 19 12:26:42 2016 ------------------------------ pctxsw(voluntary=49988, involuntary=502) ~~~ 0.0
#rint( "SIG_ALRM_handler_A(): A SUSPECT CPU-LOAD:: ", time.ctime(), 10 * "-", aProcess.num_ctx_switches(), "{0: > 8.2f} CPU_CORE_LOAD [%]".format( aProcessCpuPCT ), " INSPECT processes ... ev. add a Stateful-self-Introspection" )
print( "SIG_ALRM_handler_A(): A SUSPECT CPU-LOAD:: ", time.ctime(), 10 * "-", aProcess.num_ctx_switches(), "{0:_>60s}".format( str( aProcess.threads() ) ), " INSPECT processes ... ev. add a Stateful-self-Introspection" )
#rint( "SIG_ALRM_handler_A(): A SUSPECT CPU-LOAD:: ", str( resource.getrusage( resource.RUSAGE_SELF ) )[22:] )
else:
#----------
# .ON_INIT: may report .INIT()
#rint( "SIG_ALRM_handler_A(): A SUSPECT CPU-LOAD:: ", time.ctime(), ...
print( "SIG_ALRM_handler_A(): activated ", time.ctime(), 30 * "-", aProcess.num_ctx_switches() )
##########
# FINALLY:
SIG_ALRM_last_ctx_switch_VOLUNTARY = aVolCtxSwitchCNT # .STO ACTUALs
SIG_ALRM_last_ctx_switch_FORCED = aForcedSwitchCNT # .STO ACTUALs
#rint( "SIG_: ", time.ctime(), 30 * "-", aProcess.num_ctx_switches(), " ~~~ ", aProcess.cpu_percent( interval = 0 ), " % -?- ", aProcess.threads() )
#____________________________________________________________________
# SIG_ALRM_handler_A( aSigNUM, aFrame ): DEFINED
#####################################################################
##########
# FINALLY:
#
# > signal.signal( signal.SIGALRM, SIG_ALRM_handler_A ) # .ASSOC { SIGALRM: thisHandler }
# > signal.setitimer( signal.ITIMER_REAL, 10, 5 ) # .SET #5 [sec] interval, after first run, starting after 10[sec] initial-delay
# > signal.setitimer( signal.ITIMER_REAL, 0, 5 ) # .UNSET
# > SIG_ALRM_last_ctx_switch_VOLUNTARY = -1 # .RESET .INIT() the global { signalling | state }-variable
# > len(str([np.math.factorial(2**f) for f in range(20)][-1])) # .RUN A "FAT"-BLOCKING CHUNK OF A regex/numpy/C/FORTRAN-calculus
Also the Thread-level CtxSwitch details
While this was not elaborated to a similar depth, the same as above applies to:
>>> psutil.Process( 18263 ).cpu_percent() 0.0
>>> psutil.Process( 18263 ).ppid() 18054
>>> psutil.Process( 18054 ).cpu_percent() 0.0
=== ( 18054 ).threads(): [ 17679, 17680, 17681, 18054, 18265, 18266, 18267, ]
==4 -------------vvv-------------------=4--------------vvvv-------------------=4--------------vvv
>>> [ psutil.Process( p ).num_ctx_switches() for p in ( 18259, 18260, 18261 ) ] [pctxsw(voluntary=4, involuntary=267), pctxsw(voluntary=4, involuntary=1909), pctxsw(voluntary=4, involuntary=444)]
>>> [ psutil.Process( p ).num_ctx_switches() for p in ( 18259, 18260, 18261 ) ] [pctxsw(voluntary=4, involuntary=273), pctxsw(voluntary=4, involuntary=1915), pctxsw(voluntary=4, involuntary=445)]
>>> [ psutil.Process( p ).num_ctx_switches() for p in ( 18259, 18260, 18261 ) ] [pctxsw(voluntary=4, involuntary=275), pctxsw(voluntary=4, involuntary=1917), pctxsw(voluntary=4, involuntary=445)]

Quick Union Functional Style [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am trying to mix study with pleasure by implementing the exercises from Sedgewick and Wayne's "Algorithm's 4th Edition" in scala (and, to the best of my know-how, in a functional style).
At the exercises 1.5.7 I blocked and hope that someone could help me out. So the task is to write the QuickUnion implementation. You may find Java implementation here.
I've written my scala version and it seems to make sense, but the console output is outright discouraging. I am creating an array of 625 initial components but ... the number of components at the end is .. below zero
Without further ado this is my implementation:
package ca.vgorcinschi.algorithms1_5_7.quickUnionUF
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
class QuickUnionUF(size: Int) extends AbstractUF(size) {
override val array = (0 to size).toArray
override def find(p: Int): Int = {
validate(p)
Stream.iterate(p)(p => array(p)).dropWhile { _ != array(p) }.head
}
override def connected(p: Int, q: Int): Boolean = find(p) == find(q)
override def union(p: Int, q: Int) = {
/*
* need to declare Futures outisde
* for-comprehension loop to run in parallel
*/
val fRootP = Future { find(p) }
val fRootQ = Future { find(q) }
for {
rootP <- fRootP
rootQ <- fRootQ
if (rootP != rootQ)
} {
array(rootP) = rootQ
count -= 1
}
}
}
The parent abstract class and the underlying trait are both in my github repository. For ease of reading I am copying below the Main class:
import scala.io.Source
import ca.vgorcinschi.algorithms1_5_7.quickUnionUF.QuickUnionUF
import scala.util.matching.Regex
object Main extends App {
val allLines = Source.fromFile("src/main/resources/mediumUF.txt").getLines().toList
//get & print the initial number of components
val size = allLines.head.trim.toInt
println(s"Le nombre initial de composants est $size")
val uf = new QuickUnionUF(size)
val Integer = new Regex("(-)?(\\d+)")
for (line <- allLines.tail) {
val p = Integer findFirstIn line
assert(p.isDefined)
val intP = p.get toInt
val q = Integer findFirstIn line.substring(p.get.length).replace("\\s+", "")
assert(q.isDefined)
val intQ = q.get.toInt
if (!uf.connected(intP, intQ)) {
uf.union(intP, intQ)
println(s"L`union fait sur $intP et $intQ")
println(s"Le nombre des composants est maintenant - ${uf.counter()}")
}
}
}
In addition these are the first and the last lines of the run output:
> runMain Main
[info] Compiling 1 Scala source to /home/vgorcinschi/workspace-scala/Algorithms/Chapter 1 Fundamentals/algorithms1_5_7/target/scala-2.12/classes...
[info] Running Main
Le nombre initial de composants est 625
L`union fait sur 528 et 503
Le nombre des composants est maintenant - 624
L`union fait sur 548 et 523
Le nombre des composants est maintenant - 623
L`union fait sur 389 et 414
Le nombre des composants est maintenant - 622
L`union fait sur 446 et 421
Le nombre des composants est maintenant - 621
L`union fait sur 552 et 553
Le nombre des composants est maintenant - 620
L`union fait sur 154 et 155
...
Le nombre des composants est maintenant - -67
L`union fait sur 463 et 464
Le nombre des composants est maintenant - -67
L`union fait sur 10 et 35
Le nombre des composants est maintenant - -67
L`union fait sur 619 et 594
Le nombre des composants est maintenant - -67
L`union fait sur 403 et 402
Le nombre des composants est maintenant - -67
I do fear that the shoe pinches somewhere around my futures or the stream based find, but I can't seem to figure it out...
I think I got it. The solution was odd because it makes me wonder how does the original solution even worked. Basically I just rewrote the counter() in the parent class to return a array.distinct.length , i.e. the distinct integers or the roots:
/*
* takes the initial number of components
* as its argument
*/
abstract class AbstractUF(var count: Int) extends UF{
override def counter() = array.distinct.length
val array: Array[Int]
...
}
Output:
Le nombre initial de composants est 625
L`union fait sur 528 et 503
Le nombre des composants est maintenant - 625
L`union fait sur 548 et 523
Le nombre des composants est maintenant - 624
L`union fait sur 389 et 414
Le nombre des composants est maintenant - 623
L`union fait sur 446 et 421
Le nombre des composants est maintenant - 622
L`union fait sur 552 et 553
Le nombre des composants est maintenant - 621
L`union fait sur 154 et 155
Le nombre des composants est maintenant - 620
...
Le nombre des composants est maintenant - 266
L`union fait sur 295 et 320
Le nombre des composants est maintenant - 266
L`union fait sur 160 et 159
Le nombre des composants est maintenant - 266
L`union fait sur 463 et 464
Le nombre des composants est maintenant - 266
L`union fait sur 10 et 35
Le nombre des composants est maintenant - 266
L`union fait sur 619 et 594
Le nombre des composants est maintenant - 265
L`union fait sur 403 et 402
Le nombre des composants est maintenant - 265

Resources