I am trying to run cabal build, and I get the following error Posted: 17 Oct 2021 08:07 AM PDT Build profile: -w ghc-9.0.1 -O1 In order, the following will be built (use -v for more details): - csound-expression-dynamic-0.3.8 (lib) (requires build)
- csound-expression-typed-0.2.7 (lib) (requires build)
- csound-expression-opcodes-0.0.5.1 (lib) (requires build)
- csound-expression-5.3.4 (lib) (requires build)
- csound-sampler-0.0.10.0 (lib) (requires build)
- csound-catalog-0.7.4 (lib) (requires build)
- solve-0.2.0.0 (exe:solve) (first run) Starting csound-expression-dynamic-0.3.8 (lib) Building csound-expression-dynamic-0.3.8 (lib)
Failed to build csound-expression-dynamic-0.3.8. Build log ( C:\Users\Shiro\AppData\Roaming\cabal\logs\ghc-9.0.1\csound-expres_-0.3.8-3e9f98bb37e846ae1dd789bc6c80c4d50504a214.log ): Preprocessing library for csound-expression-dynamic-0.3.8.. Building library for csound-expression-dynamic-0.3.8.. [ 1 of 15] Compiling Csound.Dynamic.Tfm.DeduceTypes ( src\Csound\Dynamic\Tfm\DeduceTypes.hs, dist\build\Csound\Dynamic\Tfm\DeduceTypes.o ) [ 2 of 15] Compiling Csound.Dynamic.Tfm.UnfoldMultiOuts ( src\Csound\Dynamic\Tfm\UnfoldMultiOuts.hs, dist\build\Csound\Dynamic\Tfm\UnfoldMultiOuts.o ) [ 3 of 15] Compiling Csound.Dynamic.Types.Exp ( src\Csound\Dynamic\Types\Exp.hs, dist\build\Csound\Dynamic\Types\Exp.o ) src\Csound\Dynamic\Types\Exp.hs:202:66: error: * No instance for (Data.Functor.Classes.Eq1 RatedExp) arising from a use of ==' * In the second argument of (&&)', namely (ratedExpExp re == EmptyExp)' In the expression: isNothing (ratedExpDepends re) && (ratedExpExp re == EmptyExp) In an equation for isEmptyExp': isEmptyExp e = isNothing (ratedExpDepends re) && (ratedExpExp re == EmptyExp) where re = unFix e | 202 | isEmptyExp e = isNothing (ratedExpDepends re) && (ratedExpExp re == EmptyExp) | ^^ cabal.exe: Failed to build csound-expression-dynamic-0.3.8 (which is required by exe:solve from solve-0.2.0.0). See the build log above for details. |
Building not Extruded as per requirement using CGA Rules Posted: 17 Oct 2021 08:07 AM PDT City Engine uses CGA rules to describe building models. A CGA rule file consists of several rules that define how the actual building geometry is created. After a CGA rule file is assigned to a shape, the generation of the building model starting from this shape can begin. But in my case, when I apply extrusion rule, the extrusion just applied to the outer boundary of the polygon, and if there is polygon within polygon, city engine didn't consider the inside polygon and extrude as per the outer polygon. Any recommendations for this. |
my codes outputs a random number every time I run it Posted: 17 Oct 2021 08:07 AM PDT The purpose of my code is to tell the user what is the minimum amount of coins (quarter, dime, nickel, penny) needed for different values, the value comes from the user. My code first asks the user the cash(dollar) they want to solve for, then my program makes the cash(dollars) into cents by *100 after that my program is a loop subtracting the biggest coin possible while adding 1 each time to a counter I set up, but when I run all of this I get no error but I don't get the output I want I noticed that it takes the users value and adds a 5 to the end of. (the spacing messed up while copy and pasting) #include <cs50.h> #include <stdio.h> #include <math.h> int main(void) { //get the amount of change and make sure it is more than 0 float dollar; do { dollar = get_float("Enter change owed in dollars: "); } while (dollar < 0.001); // make the dollar value into cents int cent = round(dollar * 100); // make a loop so that I can subtract the largest coin possible int i = 0; while(cent <= 25) { (cent = cent - 25); i++; } while(cent <= 10 || cent > 25) { (cent = cent -10); i++; } while(cent <= 5 || cent >10) { (cent = cent - 5); i++; } while(cent <= 1 || cent > 5) { (cent = cent - 1); i++; } //print out how many coins were used printf("The minimum coins to be returned in %i \n", i); } |
How to create a multi-level xml file using Powershell Posted: 17 Oct 2021 08:06 AM PDT I planed to created config xml file for my small powershell application. To do this, I create an initialization procedure that polls the user and then generates a configuration file based on the data entered by him. The main program will take data from it, and not every time it starts. The procedure should create a file with something like this structure: <CamInfoSettings> <Application> <AppFolder>C:\Temp\01</AppFolder> <PictureFolder>images</PictureFolder> <LogFiles>CamInfo.log</LogFiles> </Application> <Sections> <Count>1</Count> <Section id="1"> <Name>FirstSection Name</Name> <Description>FirstSection Description</Description> <SectionNetworksCount>2</SectionNetworksCount> <FileName>C:\Temp\01\Section1.config</FileName> <SectionIpNetworks> <SectionIpNetwork id="1"> <Network>192.168.12.</Network> <StartIp>22</StartIp> <FinishIp>99<FinishIp> <SectionIpNetwork id="2"> <Network>192.168.13.</Network> <StartIp>1</StartIp> <FinishIp>254<FinishIp> </SectionIpNetworks> </Section> I learned how to create xml using examples from this site, or from the Internet, but I got stuck on the part where I need to create several child elements in the SectionIpNetworks section. Since there are many networks that can be used with the main program, I would like to create a file with exactly this structure. I settled on the fact that I can create one or more networks, but I cannot assign them the "id" attribute and create children within each network. I ask you to help with a small example. my procedure code asks the user for the number of networks, and then in a loop he must add items. Below is an example of code that creates branches, but further work stalled. Most likely I am making some kind of global mistake, which I have not been able to figure out for several days. My code: $SectionEnumber = [int]$Configfile.CamInfoSettings.Sections.Count + 1 $Configfile.SelectSingleNode("CamInfoSettings/Sections/Count").InnerText = $SectionEnumber $newSectionNode = $Configfile.CamInfoSettings.Sections.AppendChild($Configfile.CreateElement("Section")) $newSectionNode.SetAttribute("id",$SectionEnumber) $newSectionName = $newSectionNode.AppendChild($Configfile.CreateElement("Name")) $newSectionName.AppendChild($Configfile.CreateTextNode($SectionName)) | Out-Null $newDescription = $newSectionNode.AppendChild($Configfile.CreateElement("Description")) $newDescription.AppendChild($Configfile.CreateTextNode($SectionDescription)) | Out-Null $newSegmentsCount = $newSectionNode.AppendChild($Configfile.CreateElement("SectionNetworksCount")) $newSegmentsCount.AppendChild($Configfile.CreateTextNode($SectionNetworksCount)) | Out-Null $newFileName = $newSectionNode.AppendChild($Configfile.CreateElement("FileName")) $newFileName.AppendChild($Configfile.CreateTextNode($WritePath + "\" + "Section$SectionEnumber.config")) | Out-Null $newSectionNode.AppendChild($Configfile.CreateElement("SectionNetworks")) | Out-Null $newNetworksNode = $Configfile.SelectSingleNode("CamInfoSettings/Sections/Section[@id=$SectionEnumber]/SectionNetworks") $newNetworksNode.SetAttribute("count",$SectionNetworksCount) foreach ($item in 1..$SectionNetworksCount) { $newNetworksNode.AppendChild($Configfile.CreateElement("SectionNetwork")) |Out-Null Here i must create Elements for SectionIpNetwork and set attruibute id=$item } |
How to build a Power APP that shares Excel File Posted: 17 Oct 2021 08:06 AM PDT I am quite newbie in power app. Sorry for any inconvenience I could cause. I have been developing my first power app program and I connect it to an excel file (store in my one drive). I used One Drive connector, One Drive for Business connector and Excel connector ti connect program to the file. But any change I made in the excel file side doesn´t appear in the program side. It looks like there is an internal copy of the excel and the program works on it. This should be a problem if I need to add a record to my excel file from outside and watch it inside my program. For example, using the program by two users. Changes for one, must to appear in the second one as well. How can I connect to this excel file in the way any change I do in the excel (outside of the program) can be reflected inside the program? Thanks Best regards |
Unity Universal Render Pipeline isn't casting shadows Posted: 17 Oct 2021 08:06 AM PDT In my 2D Unity project I wanted to add lights, so I looked up a tutorial on Youtube made by Unity and followed it exactly (This is the tutorial: The tutorial I followed) but Unity's Universal Render Pipeline isn't doing anything. I've looked online and have found people with similar type problems but their solutions didn't fix my problem. Here is everything you might need: img1 img2 Let me know if you need anything else, thanks in advance! |
Deleting directory WPF Application C# Posted: 17 Oct 2021 08:06 AM PDT I'm trying to delete a directory in C# however nothing seems to happen. My code looks like this: private void CacheClear_Click(object sender, RoutedEventArgs e) { string path = @"%LOCALAPPDATA%\FiveM\FiveM Application Data\data\cache"; System.IO.DirectoryInfo di = new DirectoryInfo(@"%LOCALAPPDATA%\FiveM\FiveM Application Data\data\cache"); if(Directory.Exists(path)) di.Delete(true); } When I click my button nothing just happens, I don't get any errors. Thanks, Ossie |
How I can fetch the API correctly Posted: 17 Oct 2021 08:06 AM PDT I have created 10 , each display one id in API. I have used querySelectorAll to find all the and use for loop to make the content of each contains one id in API but when I try to code, as you can see, one will contain all ten id and I don't know how to make it possible function onResponse(response) { return response.json(); } function data(data) { //create a function to display the element var htmls = data.map(function(post) { return `<li> <h2> ${post.id}</h2> </li>` }); var html = htmls.join(''); const p = document.querySelectorAll('span'); for (let i = 0; i < p.length; i++) { p[i].innerHTML = html; } } fetch('https://jsonplaceholder.typicode.com/users').then(onResponse).then(data); <body> <form> <div> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> </div> </form> </body> </html> |
Sorting - Python Heap Characters Posted: 17 Oct 2021 08:06 AM PDT I am trying to sort characters in a descending manner using heap with the below code: def heap(arr, j, n): minimum = j leftSide = j * 2 + 1 rightSide = j * 2 + 2 if(leftSide < n and arr[minimum].lower() > arr[leftSide].lower()): minimum = leftSide if(rightSide < n and arr[minimum].lower() > arr[rightSide].lower()): minimum = rightSide if(minimum != j): arr[minimum], arr[j] = arr[j], arr[minimum] heap(arr, minimum, n) def heapSort(arr): n = len(arr) for k in range(n//2 - 1, -1, -1): heap(arr, k, n) for k in range(n-1, 0, -1): arr[k], arr[0] = arr[0], arr[k] heap(arr, 0, k) arr = ["A", "B", "C", "D", "a", "b", "c", "d"] heapSort(arr) print(arr) When I print the sorted array it returns as "d", "D", "c", "C", "b", "B", "a", "A". How can I have it provide me all the lower case sorted first and then all the upper case sorted second? |
React: Call a method from an imported component (onClick)? Posted: 17 Oct 2021 08:06 AM PDT Assuming I have the following two classes. Is it possible to call a method from the other class? Here I'd like to call the method "App.changeColor" from "ColorBox". But it does not seem to be working. When I click a color box, nothing will happen, even the alert is not outputted. When I use (), the compiling fails: App__WEBPACK_IMPORTED_MODULE_2_.default.changeColor is not a function Thank you! ColorBox.js import React from 'react' /* _____________________ Styles _____________________ */ import './App.css' /* __________________________________________________ */ /* ___________________ Components ___________________ */ import App from './App' /* __________________________________________________ */ class ColorBox extends React.Component { render() { return ( <div className="color-box" onClick={App.changeColor} style={{backgroundColor: this.props.bg}}></div> ) } } export default ColorBox App.js import React from 'react' /* _____________________ Styles _____________________ */ import './App.css' /* __________________________________________________ */ /* ___________________ Components ___________________ */ import ColorBox from './ColorBox'; /* __________________________________________________ */ class App extends React.Component { state = { color: ["blue", "red", "yellow", "green", "purple", "indigo", "grey", "pink"] } changeColor = () => { const random = Math.floor(Math.random() * this.state.color.length); this.props.bg = this.state.color[random]; alert("lol"); } randomizeColor() { const random = Math.floor(Math.random() * this.state.color.length); return (random, this.state.color[random]); } render() { return ( <div className="App"> <ColorBox bg={this.randomizeColor()} /> <ColorBox bg={this.randomizeColor()} /> <ColorBox bg={this.randomizeColor()} /> <ColorBox bg={this.randomizeColor()} /> <ColorBox bg={this.randomizeColor()} /> <ColorBox bg={this.randomizeColor()} /> <ColorBox bg={this.randomizeColor()} /> <ColorBox bg={this.randomizeColor()} /> <ColorBox bg={this.randomizeColor()} /> <ColorBox bg={this.randomizeColor()} /> <ColorBox bg={this.randomizeColor()} /> <ColorBox bg={this.randomizeColor()} /> <ColorBox bg={this.randomizeColor()} /> <ColorBox bg={this.randomizeColor()} /> <ColorBox bg={this.randomizeColor()} /> <ColorBox bg={this.randomizeColor()} /> </div> ) } } export default App |
Convert string to list of strings in python Posted: 17 Oct 2021 08:07 AM PDT I have a string extracted from a .csv which has this format: str = "[point, contextual, point]" What I wanna do is convert it to a list in the format: str = ["point", "contextual", "point"] How can I do it? I tried with json.loads(str) but I got the error: json.decoder.JSONDecodeError: Expecting value: line 1 column 2 (char 1) |
Pandas drop rows appearing above/below string match Posted: 17 Oct 2021 08:05 AM PDT I have a dataframe from a .txt file, and I am only interested in the data that appears between the <Header> tags. 0 1 0 webmaster @.com 1 <Header> 121112 2 ReportID 5353 3 Date 20210630 4 Type DMV13 5 </Header> None 6 ZIP 90279 7 State WV I therefore want to drop all other rows, but can't do it on position because the <Header> tags appear in different rows depending on the file. So is there a way to drop every row above/below a string match, so that the output looks like: 0 1 0 ReportID 5353 1 Date 20210630 2 Type DMV13 |
How can I make type assertions against an anonymous function? Posted: 17 Oct 2021 08:07 AM PDT I'm writing an HTTP service in Go using Gorilla. I'm newish to Go (<1yr experience), but ramping up fairly quickly. I have a function I use to register my handlers: func (s *Server) RegisterHandler(path string, handler http.HandlerFunc, methods ...string) { if len(methods) == 0 { s.Router.Handle(path, handler).Methods(http.MethodGet) } else { s.Router.Handle(path, handler).Methods(methods...) } } I have some code that registers named functions as handlers: func (s *Server) RegisterDefaultHandlers() { s.RegisterHandler("/ping", Ping) } func Ping(w http.ResponseWriter, request *http.Request) { responders.RespondOk(w) } I also have unit test code that registers anonymous functions as handlers: s.RegisterHandler("/testPath", func(w http.ResponseWriter, r *http.Request) { // whatever the test calls for }, http.MethodPost) This all works great -- just establishing my starting point. Today, I find myself banging my head against Go's type system. I am defining some custom handler types, for example: type UserAwareHandlerFunc func(http.ResponseWriter, *http.Request, models.User) And I'm also introducing a function to allow me to register such handlers, and to wrap all handlers in context.ClearHandler . If this works, I'll also wrap everything with another function that sets a few things on my logging context. What I have so far: func (s *Server) RegisterHandler(path string, handler interface{}, methods ...string) { wrappedHandler := wrappers.ApplyWrappers(handler) if len(methods) == 0 { s.Router.Handle(path, wrappedHandler).Methods(http.MethodGet) } else { s.Router.Handle(path, wrappedHandler).Methods(methods...) } } func ApplyWrappers(handler interface{}) http.Handler { var result http.Handler if userAwareHandler, ok := handler.(UserAwareHandlerFunc); ok { result = UserAware(userAwareHandler) } else if handlerFunc, ok := handler.(http.HandlerFunc); ok { result = handlerFunc } else if handlerObj, ok := handler.(http.Handler); ok { result = handlerObj } else { log.Fatalf("handler %+v (type %s) is not a recognized handler type.", handler, reflect.TypeOf(handler)) } // to avoid memory leaks, ensure that all request data is cleared by the end of the request lifetime // for all handlers -- see https://stackoverflow.com/a/48203334 result = context.ClearHandler(result) return result } func UserAware(handler UserAwareHandlerFunc) http.Handler { return func(w http.ResponseWriter, r *http.Request) { user := ... // get user from session handler(w, r, user) } } With these changes, I can no longer register named or anonymous functions; the type assertions in ApplyWrappers all fail. I have to declare and define a typed variable, then pass that in. Named functions have two feasible approaches: var Ping http.HandlerFunc = func(w http.ResponseWriter, request *http.Request) { responders.RespondOk(w) } func Ping2(w http.ResponseWriter, request *http.Request) { responders.RespondOk(w) } func (s *Server) RegisterDefaultHandlers() { s.RegisterHandler("/ping", Ping) var pingHandler2 http.HandlerFunc = Ping2 s.RegisterHandler("/ping2", pingHandler2) } For anonymous functions, I can do: var handler http.HandlerFunc = func(w http.ResponseWriter, r *http.Request) { ... } s.RegisterHandler("/testPath", handler, http.MethodPost) The whole point of what I've built here is to consolidate boilerplate into one place, keeping my many tests and handlers as streamlined as possible. The need to declare a typed variable is working against that goal. So my question is this: is there some special type magic I could use (preferably in RegisterHandler and/or ApplyWrappers ) that would restore the ability to pass named and/or anonymous functions to RegisterHandler? EDIT: thanks so much for the quick answers. Problem solved: func ApplyWrappers(handler interface{}) http.Handler { var result http.Handler if userAwareHandler, ok := handler.(UserAwareHandlerFunc); ok { result = UserAware(userAwareHandler) } else if anonymousFunc, ok := handler.(func(http.ResponseWriter,*http.Request)); ok { result = http.HandlerFunc(anonymousFunc) } else if handlerObj, ok := handler.(http.Handler); ok { result = handlerObj } else { log.Fatalf("handler %+v (type %s) is not a recognized handler type.", handler, reflect.TypeOf(handler)) } // to avoid memory leaks, ensure that all request data is cleared by the end of the request lifetime // for all handlers -- see https://stackoverflow.com/a/48203334 result = context.ClearHandler(result) return result } It's working now, but I still have questions: - If I understand correctly, the "duck typing" behavior that I was looking for here would have been fine if I were dealing with interfaces rather than functions. What drives the distinction? Is duck-typing of functions something I could reasonably hope to see in a future version of the language?
- I can cast the anonymous function to a HandlerFunc. It's weird to me that casting and type assertions don't share semantics. Can someone explain?
|
No qualifying bean available: expected single matching bean but found 2 Posted: 17 Oct 2021 08:06 AM PDT I am trying to get bean from one class using Autowired. I have class Person @Component("personBean") public class Person { @Autowired @Qualifier("dog") private Pet pet; private String surname; private int age; public Person(Pet pet) { this.pet = pet; } public void setSurname(String surname) { this.surname = surname; } public void setAge(int age) { this.age = age; } public void setPet(Pet pet) { this.pet = pet; } public void callYourPet(){ System.out.println("Hello my pet"); pet.say(); } } also class Dog @Component public class Dog implements Pet{ public void init(){ System.out.println("Class dog: init method"); } public void destroy(){ System.out.println("Class Dog:delete method"); } @Override public void say(){ System.out.println("Bow-Wow"); } @Override public String toString() { return "Dog{Sobaka}"; } } Cat class: @Component public class Cat implements Pet{ @Override public void say() { System.out.println("Meow-Meow"); } } When i am trying to get "personBean" Bean from context i get this exception Exception in thread "main" org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'personBean'. Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'spring_introduction.Pet' available: expected single matching bean but found 2: cat,dog //////////////////////////////////////////////////////////////////////////////////////// |
How to use roman numerals in ggplot's scale_x_date? Posted: 17 Oct 2021 08:07 AM PDT I need to change format string "2016-06-29" to: 29.V.2016 I've try: scale_x_date(date_labels = paste("%d", as.roman("%m"), "%Y", sep = ".")) but the only result I get is: Error: Invalid input: date_trans works with objects of class Date only In addition: Warning message: In .roman2numeric(x) : invalid roman numeral: %m |
grouping data according to "if" condition Posted: 17 Oct 2021 08:07 AM PDT can anyone help me revise the following table coding: The output I want is column cluster 1 containing "merk" and "jenis" data that has a value of c1 = 1, column cluster 2 contains data on "merk" and "jenis" that have a value of c2 = 1, and column cluster 3 contains data on "merk" and "jenis" that have a value of c3 = 1 . after that the bottom row contains the number of data in each cluster the following is the code view: <!DOCTYPE html> <html> <head> <?php $this->load->view("_partials/head.php") ?> </head> <body> <!-- Navigation Bar--> <header id="topnav"> <?php $this->load->view("_partials/topbar.php") ?> <?php $this->load->view("_partials/navbar.php") ?> </header> <div class="wrapper"> <div class="container"> <!-- Page-Title --> <div class="row"> <div class="col-sm-12"> <div class="page-title-box"> <!-- FLASH MESSAGE --> <div class=""> <?= $this->session->flashdata('message'); ?> </div> <?php if ($this->session->userdata('username')) { ?> <div class="btn-group pull-right"> <ol class="breadcrumb hide-phone p-0 m-0"> <li> <a href=""><?= $this->uri->segment(1); ?></a> </li> <li class="active"> kmeans </li> </ol> </div> <h4 class="page-title">Perhitungan K-Means</h4> <?php } ?> </div> </div> <div class="col-sm-12"> <div class="panel panel-color panel-inverse"> <div class="panel-heading"> <?php $i = $this->db->query('SELECT * FROM centroid_temp ORDER BY iterasi DESC')->row(); ?> <h3 class="panel-title">Iterasi ke - <?php echo (($i->iterasi)+1); ?></h3> </div> <div class="panel-body card-box table-responsive"> <?php $uri = $this->uri->segment(3); ?> <a class="btn btn-primary" href="<?php echo base_url(); ?>kmeans">Iterasi Awal</a> <a id="tombol-iterasi" class="btn btn-primary" href="<?php echo base_url(); ?>kmeanslanjut">Iterasi Selanjutnya</a> <br><br> <!-- <hr> --> <table id="datatable" class="table table-striped table-bordered"> <thead> <tr align="center"> <th>Nama Merk</th> <th>Nama jenis</th> <th>Harga</th> <th>Stock</th> <th>Terjual</th> <th>Rata-Rata</th> <th>Centroid 1</th> <th>Centroid 2</th> <th>Centroid 3</th> <th>C1</th> <th>C2</th> <th>C3</th> </tr> <?php $m = $this->db->query('SELECT * FROM centroid_temp ORDER BY iterasi DESC')->row(); $c1a = $this->m_kmeanslanjut->set_number($m->c1a); $c1b = $this->m_kmeanslanjut->set_number($m->c1b); $c1c = $this->m_kmeanslanjut->set_number($m->c1c); $c1d = $this->m_kmeanslanjut->set_number($m->c1d); $c2a = $this->m_kmeanslanjut->set_number($m->c2a); $c2b = $this->m_kmeanslanjut->set_number($m->c2b); $c2c = $this->m_kmeanslanjut->set_number($m->c2c); $c2d = $this->m_kmeanslanjut->set_number($m->c2d); $c3a = $this->m_kmeanslanjut->set_number($m->c3a); $c3b = $this->m_kmeanslanjut->set_number($m->c3b); $c3c = $this->m_kmeanslanjut->set_number($m->c3c); $c3d = $this->m_kmeanslanjut->set_number($m->c3d); $hc1=0; $hc2=0; $hc3=0; $no=0; $arr_c1 = array(); $arr_c2 = array(); $arr_c3 = array(); $arr_c1_temp = array(); $arr_c2_temp = array(); $arr_c3_temp = array(); ?> </thead> <tbody> <tr> <?php foreach ($harian as $hr) : $rata_rata = $this->m_kmeanslanjut->set_number(($hr->terjual)/12); $this->m_kmeanslanjut->update_data(array('id' => $hr->id_hr), array('rata' => $rata_rata), 'harian'); ?> <td><?php echo $hr->nama_merk ?></td> <td><?php echo $hr->nama_jenis ?></td> <td align="right"><?php echo "Rp. " . $this->m_kmeanslanjut->set_money($hr->harga) ?></td> <td align="center"><?php echo $hr->stok ?></td> <td align="center"><?php echo $hr->terjual ?></td> <td align="center"><?php echo $rata_rata ?></td> <td align="center"><?php $hc1 = sqrt(pow((($hr->harga)-($m->c1a)),2)+pow((($hr->stok)-($m->c1b)),2)+pow((($hr->terjual)-($m->c1c)),2)+pow(($rata_rata-($m->c1d)),2)); echo $this->m_kmeanslanjut->set_number($hc1); ?></td> <td align="center"><?php $hc2 = sqrt(pow((($hr->harga)-($m->c2a)),2)+pow((($hr->stok)-($m->c2b)),2)+pow((($hr->terjual)-($m->c2c)),2)+pow(($rata_rata-($m->c2d)),2)); echo $this->m_kmeanslanjut->set_number($hc2); ?></td> <td align="center"><?php $hc3 = sqrt(pow((($hr->harga)-($m->c3a)),2)+pow((($hr->stok)-($m->c3b)),2)+pow((($hr->terjual)-($m->c3c)),2)+pow(($rata_rata-($m->c3d)),2)); echo $this->m_kmeanslanjut->set_number($hc3); ?></td> <?php if($hc1<=$hc2) { if($hc1<=$hc3) { $arr_c1[$no] = 1; }else { $arr_c1[$no] = '0'; } }else { $arr_c1[$no] = '0'; } if($hc2<=$hc1) { if($hc2<=$hc3) { $arr_c2[$no] = 1; }else { $arr_c2[$no] = '0'; } }else { $arr_c2[$no] = '0'; } if($hc3<=$hc1){ if($hc3<=$hc2){ $arr_c3[$no] = 1; }else { $arr_c3[$no] = '0'; } } else { $arr_c3[$no] = '0'; } $arr_c1_temp[$no] = $hr->harga; $arr_c2_temp[$no] = $hr->stok; $arr_c3_temp[$no] = $hr->terjual; $arr_c4_temp[$no] = $rata_rata; $warna1=""; $warna2=""; $warna3=""; ?> <?php if($arr_c1[$no]==1) { $this->m_kmeanslanjut->update_data(array('id' => $hr->id_hr), array('cluster'=> 1), 'harian'); $warna1='#FFFF00';} else { $warna1='#ccc';} ?><td bgcolor="<?php echo $warna1; ?>"> <?php echo $arr_c1[$no] ;?></td> <?php if($arr_c2[$no]==1) { $this->m_kmeanslanjut->update_data(array('id' => $hr->id_hr), array('cluster'=> 2), 'harian'); $warna2='#FFFF00';} else { $warna2='#ccc';} ?><td bgcolor="<?php echo $warna2; ?>"> <?php echo $arr_c2[$no] ;?></td> <?php if($arr_c3[$no]==1) { $this->m_kmeanslanjut->update_data(array('id' => $hr->id_hr), array('cluster'=> 3), 'harian'); $warna3='#FFFF00';} else { $warna3='#ccc';} ?><td bgcolor="<?php echo $warna3; ?>"> <?php echo $arr_c3[$no] ;?></td> </tr> <?php endforeach; ?> <?php $q = "INSERT INTO centroid_temp(c1a,c1b,c1c,c1d,c2a,c2b,c2c,c2d,c3a,c3b,c3c,c3d) SELECT (SELECT AVG(harga) FROM harian WHERE cluster = 1) as c1a, (SELECT AVG(stok) FROM harian WHERE cluster = 1) as c1b, (SELECT AVG(terjual) FROM harian WHERE cluster = 1) as c1c, (SELECT AVG(rata) FROM harian WHERE cluster = 1) as c1d, (SELECT AVG(harga) FROM harian WHERE cluster = 2) as c2a, (SELECT AVG(stok) FROM harian WHERE cluster = 2) as c2b, (SELECT AVG(terjual) FROM harian WHERE cluster = 2) as c2c, (SELECT AVG(rata) FROM harian WHERE cluster = 2) as c2d, (SELECT AVG(harga) FROM harian WHERE cluster = 3) as c3a, (SELECT AVG(stok) FROM harian WHERE cluster = 3) as c3b, (SELECT AVG(terjual) FROM harian WHERE cluster = 3) as c3c, (SELECT AVG(rata) FROM harian WHERE cluster = 3) as c3d"; $this->db->query($q); $m = $this->db->query('SELECT * FROM centroid_temp ORDER BY iterasi DESC')->row(); $n = $this->db->query('SELECT * FROM centroid_temp ORDER BY iterasi DESC LIMIT 1,1')->row(); if($m->c1a == $n->c1a || $m->c1b == $n->c1b || $m->c1c == $n->c1c || $m->c1d == $n->c1d || $m->c2a == $n->c2a || $m->c2b == $n->c2b || $m->c2c == $n->c2c || $m->c2d == $n->c2d || $m->c3a == $n->c3a || $m->c3b == $n->c3b || $m->c3c == $n->c3c || $m->c3d == $n->c3d) { ?> <script> document.getElementById("tombol-iterasi").style.display = "none"; alert("Proses berhenti"); </script> <?php } ?> </tbody> </table> <div class="panel-body"> <table id="datatable" class="table table-striped table-bordered"> <thead> <strong> <td><b>Nama Centroid</b></td> <td><b>Harga</b></td> <td><b>Stock</b></td> <td><b>Terjual</b></td> <td><b>Rata-Rata</b></td> </strong> </thead> <tbody> <tr align="center"> <td>Centroid 1</td><td><?php echo $c1a ?></td><td><?php echo $c1b ?></td><td><?php echo $c1c ?></td><td><?php echo $c1d ?></td> </tr> <tr align="center"> <td>Centroid 2</td><td><?php echo $c2a ?></td><td><?php echo $c2b ?></td><td><?php echo $c2c ?></td><td><?php echo $c2d ?></td> </tr> <tr align="center"> <td>Centroid 3</td><td><?php echo $c3a ?></td><td><?php echo $c3b ?></td><td><?php echo $c3c ?></td><td><?php echo $c3d ?></td> </tr> </tbody> </table> </div> <div class="panel-body"> <table id="datatable" class="table table-striped table-bordered"> <thead> <strong> <tr> <td colspan=2><b>Cluster 1</b></td> <td colspan=2><b>Cluster 2</b></td> <td colspan=2><b>Cluster 3</b></td> </tr> <tr> <td><b>Merk</b></td> <td><b>Jenis</b></td> <td><b>Merk</b></td> <td><b>Jenis</b></td> <td><b>Merk</b></td> <td><b>Jenis</b></td> </tr> </strong> </thead> <tbody> <?php foreach ($harian as $hr) : ?> <tr align="center"> <?php if($arr_c1[$no]==1) { ?> <td><?php echo $hr->nama_merk ?></td> <td><?php echo $hr->nama_jenis ?></td> <?php } ?> </tr> <tr align="center"> <?php if($arr_c2[$no]==1) { ?> <td><?php echo $hr->nama_merk ?></td> <td><?php echo $hr->nama_jenis ?></td> <?php } ?> </tr> <tr align="center"> <?php if($arr_c3[$no]==1) { ?> <td><?php echo $hr->nama_merk ?></td> <td><?php echo $hr->nama_jenis ?></td> <?php } ?> </tr> <?php endforeach ?> </tbody> </table> </div> </div> </div> </div> </div> </div> </div> <!-- Footer --> <footer class="footer text-right"> <?php $this->load->view("_partials/footer.php") ?> </footer> <script type="text/javascript"> function check() { var mrk = $("#mrk").val(); var jns = $("#jns").val(); var start = $("#start").val(); var end = $("
|
No comments:
Post a Comment